string name = Properties.Settings.Default.ClassName.ToString();
//"myproject.myclass, myassembly" format.
//name = "ABC.MyClass, Assem" ;
Type t = Type.GetType(name);
Object obj = Activator.CreateInstance(t);
string result = t.InvokeMember("methodName",
System.Reflection.BindingFlags.InvokeMethod, null, obj, new object[] {
strA,
strB });
cheers
"Andrew" wrote:
Hi,
I've looked at the Activator classes and I've come out with these samples of
code. However there is an error:
e.g. codes:
=======
string name = "ClassABC";
Type theMathType = Type.GetType("System.Math");
Type testType = Type.GetType(name);
Type testType2 = Type.GetType("name");
--both testType and testType2 gives "null".
Object theObj2 = Activator.CreateInstance(theMathType); --Error: Cannot
create an abstract class.
Object theObj3 = Activator.CreateInstance(testType); --Error: Value
cannot be
null. Parameter name: type.
Object theObj4 = Activator.CreateInstance(testType2); --Error: Value
cannot be
null. Parameter name: type.
I'm not very familiar with CreateInstance method etc ...
I just want to create an instance of "name" which is the name of the class
that I want to instantiate.
Thanks
regards,
Andrew