I’m trying to find a constructor with a specific signature. This constructor does not exist in current type, but it does in its parent. To illustrate:
public class Base
{
public Base()
{
}
public Base(string a1, string a2, string a3)
{
...
}
}
public class Child : Base
{
}
The problem is, that I can’t seem to find the .ctor with the string arguments with .GetConstructor, even trying such as:
typeof(Child).GetConstructor(BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Instance, null, new Type[] { typeof(string), typeof(string), typeof(string) }, null);
substituting typeof(Child) with typeof(Base), naturally, works.
Is there something I’m missing in respect to finding parent constructors?
Constructors are not inherited, so you can’t find them through children, even with
FlattenHierarchy.You’ll have to loop through children to find it.