uber1024's WebLog

It's not hot wings and beer, but it's still okay

December 2004 - Posts

Late binding

Okay, this isn't a big deal but I ran into a situation where it was convenient to be able to create a class without knowing it's type until runtime.  All the classes in this namespace derive from a base class so certain functionality it guaranteed in each one.  This is how we did it:

tType = Type.GetType("XmlRouter." + sCurrentNodeName);

if( tType != null )

{

object o = Activator.CreateInstance(tType);

}

// the function we want to use has XML parameters

XmlNode[] args = new XmlNode[2];

args[0] = oXmlHeaderNode;

args[1] = oNode;

// invoke method

object oOut = tType.InvokeMember("ProcessRequest", BindingFlags.Default | BindingFlags.InvokeMethod, null, o, args);

More Posts