我试图找到具有特定签名的构造函数。此构造函数在当前类型中不存在,但它在其父类中存在。为了说明:C#GetConstructor()不返回父构造函数
public class Base
{
public Base()
{
}
public Base(string a1, string a2, string a3)
{
...
}
}
public class Child : Base
{
}
的问题是,我似乎无法找到.ctor
与字符串参数与.GetConstructor
,甚至还试图如:
typeof(Child).GetConstructor(BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Instance, null, new Type[] { typeof(string), typeof(string), typeof(string) }, null);
代typeof(Child)
与typeof(Base)
,自然,作品。
有没有什么我找不到关于寻找父构造函数?
从“Base”中删除默认构造函数不会给Child提供三个参数构造函数。起初我以为这是一件非常整洁的东西,我从来不知道,但我在.NET 4中试过,并且不,仍然得到“'Child'不包含带3个参数的构造函数” –