May 2006 Archives

AjaxViet.com

  • posted: 24 May 2006

Phạm Đức Hải seems to be testing out Vine Type at his home page ajaxviet.com -- completely in Vietnamese -- except for the occasional "download" or "email."

As a programmer, seeing someone use Vine Type and adjust the interface as you hoped someone would is just...cool.

Although he may eventually opt for another CMS, I'm hopeful that Vine Type will suit his needs. If you are aware of other Vine Type websites in other languages, I would love to hear from you.

more...

C# Reflection Part 6

  • posted: 23 May 2006

Passing "out" Parameters

Out parameters are parameters that are expected (and in fact for C# required) to be populated by the called method. That is, the value for the out parameter is not meaningful when passed in and receives a value after the method is called.

bool GetCustName(int iCust, out string strName);

We must first create the object as covered in depth in Part 2:

more...

C# Reflection Part 5

  • posted: 23 May 2006

Passing "ref" Parameters

So far we've made conventional reflection calls. Things get a bit sticky, however, when the method we want to invoke contains a ref parameter. For example, a method with the signature:

bool CheckCustName(int iCust, ref string strName);

Reference parameters are not copied into the receiving method, but referenced from the caller's memory area. Creating the object is not a problem if you've been reading this series: This part was covered in depth in Part 2:

more...

C# Reflection Part 4

  • posted: 09 May 2006

Set Properties on Reflected Object

Suppose that the method that we will eventually call requires that two properties within the object be set beforehand. Why would anyone design a class this way? I can't explain it but there is code out in the wild (ahem) that might require this. If you're one of the other unfortunate ones, here's how to set properties on an object created through reflection.

more...

C# Reflection Part 3

  • posted: 04 May 2006

Passing Parameters

Now with the basic form established, we can move to variations on the theme. First variation: pass parameters to the method we're calling.

Steps 1, 2 and 3 to load the DLL assembly and create a target object remain the same as the previous article:

// load the assembly
Assembly assem = Assembly.LoadFrom(@"c:\path\to\file.dll");
// create a Type object
Type typClsX = assem.GetType("Fully.Qual.ClsX",true);
// instantiate an object of that type
object oClsX = Activator.CreateInstance(typClsX);
more...

C# Reflection Part 2

  • posted: 01 May 2006

The first example with be the simplest and most straightforward. We'll invoke a method that takes no parameters and returns a string. What is as simple as string s = obj.Method(); takes quite a few extra steps when using reflection.

  1. Load an assembly from a known Data Link Libarary (DLL) in a known location
  2. Create a System.Type object of the class of the object you want to instantiate
  3. Create an instance of the class object
  4. Create a System.Reflection.MethodInfo object that represents the method we will invoke
  5. Invoke the method within the object we created
  6. Cast the generic object returned to its proper type
more...

C# Reflection Part 1

  • posted: 01 May 2006

For those who are unfamiliar with .NET reflection, it is a whole area of computing that allows runtime binding to public classes, methods, and properties within external DLLs. Some folks refer to this as late binding.

In .NET, the usual way we call a method in another project's Data Link Libarary (DLL) is by

  1. Adding a reference to the component DLL in Visual Studio
  2. Adding a #using declaration to the top of the C# file
  3. Calling the method just as you would call a local method
more...

Comments

SubSections

Recently

Archives

2010

2008

2007

2006

2005