yes,agree to saucer! A simple demo here://class defined here public class LateBindingTest { public string GetSomewhat() { return "hello,fqq!"; } }//below is the test codeType t = Type.GetType("PerfDemo.LateBindingTest"); MethodInfo mi = t.GetMethod("GetSomewhat"); object s2 = mi.Invoke(lbt,null);
A simple demo here://class defined here
public class LateBindingTest
{
public string GetSomewhat()
{
return "hello,fqq!";
}
}//below is the test codeType t = Type.GetType("PerfDemo.LateBindingTest");
MethodInfo mi = t.GetMethod("GetSomewhat");
object s2 = mi.Invoke(lbt,null);
{
TestHandle handle = null;
if(b)
handle = new TestHandle(Test1);
else
handle = new TestHandle(Test2); handle();
}
那样的话就要用反射了,呵呵
{
Type t = Type.GetType(FormName);
//利用System.Type的实例成员函数GetConstructor获得你需要的窗体类型的构造函数。
System.Reflection.ConstructorInfo myConstructorInfo = t.GetConstructor(new Type[0]);
//根据构造函数的参数列表信息获得相应的目标窗体类型的实例。
object obj = myConstructorInfo.Invoke(new object[0]);
//将获得的实例转换为Form类型。
System.Windows.Forms.Form newfrm = ((Form)obj);
newfrm.Tag =newfrm.Name ;
newfrm.MdiParent = this.MdiParent ;
newfrm.Show();
}
catch(NullReferenceException)
{
MessageHandle.ErrorMsgBox ("表单名称设置错误,请与管理员联系!");
return;
}
if (a != null)
a.Invoke(objectinstance, null);