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

Nal*_*ial 5 c# reflection constructor

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

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),自然有效。

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

Sam*_*eff 4

构造函数不是继承的,因此您无法通过子级找到它们,即使使用FlattenHierarchy.

您必须遍历子项才能找到它。