Hi Gurus,
Using C#.Net VS2005.
I am wondering if there is a was to instantiate an object at runtime when the class of the object is not known at designtime?
I have a list of classes that all inherit from BaseClass, and override BaseClass.someMethod();
But I don't know which descendant classes will be required at runtime, and I want to to call the overridden method someMethod().
Other than having a switch statement that compares the classname string with a string constant :-
//create a class called "classname"
switch (classname)
{
case "DescendentClass1":
return new DescedentClass1();
break;
etc...
}
The problem with this is that if I want to add new classes, I need to recompile the code with the new class name.
The descendent class implemetations are likely to be in a DLL.
In Delphi I could Register(classname:String) and call GetClass(classname:String)
Can this be done in C#, or am I on the wrong track architecturally ?
Many thanks in advance.
Using C#.Net VS2005.
I am wondering if there is a was to instantiate an object at runtime when the class of the object is not known at designtime?
I have a list of classes that all inherit from BaseClass, and override BaseClass.someMethod();
But I don't know which descendant classes will be required at runtime, and I want to to call the overridden method someMethod().
Other than having a switch statement that compares the classname string with a string constant :-
//create a class called "classname"
switch (classname)
{
case "DescendentClass1":
return new DescedentClass1();
break;
etc...
}
The problem with this is that if I want to add new classes, I need to recompile the code with the new class name.
The descendent class implemetations are likely to be in a DLL.
In Delphi I could Register(classname:String) and call GetClass(classname:String)
Can this be done in C#, or am I on the wrong track architecturally ?
Many thanks in advance.