小编Nal*_*ial的帖子

C# GetConstructor() 不返回父构造函数

我正在尝试找到具有特定签名的构造函数。此构造函数在当前类型中不存在,但在其父类型中存在。为了显示:

public class Base
{
    public Base()
    {

    }

    public Base(string a1, string a2, string a3)
    {
        ...
    }
}

public class Child : Base
{

}
Run Code Online (Sandbox Code Playgroud)

问题是,我似乎无法找到.ctor带有字符串参数的.GetConstructor,甚至尝试如下:

typeof(Child).GetConstructor(BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Instance, null, new Type[] { typeof(string), typeof(string), typeof(string) }, null);
Run Code Online (Sandbox Code Playgroud)

替换typeof(Child)typeof(Base),自然有效。

在寻找父构造函数方面我缺少什么吗?

c# reflection constructor

5
推荐指数
1
解决办法
2478
查看次数

标签 统计

c# ×1

constructor ×1

reflection ×1