【发布时间】:2011-09-01 13:14:14
【问题描述】:
我有以下问题:
public class MyType
{
public void method(int a, params object[] p){}
public void MyType()
{
method(5);
}
}
当我使用构造函数时一切都很好,但是当我尝试使用 Activator.CreateInstance(MyType);
void Factory()
{
string componentPath = "MyType.dll";
Assembly component = Assembly.LoadFrom(componentPath);
Type myType= component.GetType("MyType");
Activator.CreateInstance(myType);
}
它失败,异常 MyType.method(int32) is not found。
重要的是要注意,在我将 params object[] p 添加到方法之前,一切正常。
谢谢。
【问题讨论】:
-
缺少代码?也请重新格式化您的帖子。
-
我认为如果您将参数传递给该方法,您可以避免您的问题。只需将您的方法称为 method(5, new object[0]);
-
你的代码不会为初学者编译
标签: c# reflection activation