110,535
社区成员
发帖
与我相关
我的任务
分享
CreateAndDo("CSDemo.ttt", "getData");
private void CreateAndDo(string classfullname, string methodname)
{
Type t = Type.GetType(classfullname);
if (t != null)
{
object val = Activator.CreateInstance(t);
MethodInfo method = t.GetMethod(methodname);
if (method != null)
{
method.Invoke(val, new object[] { });
}
}
}
public class ttt
{
public void getData()
{
Debug.WriteLine("getdate");
}
}
dynamic ss = Activator.CreateInstance("dll名称", "classname");
ss.getData();
如果实现了接口:
var ss = Activator.CreateInstance("dll名称", "classname") as IGetData;
ss.getData();
最后如果都不明白,就看http://blog.csdn.net/tonglian/article/details/2271066