Can I get private constructor in .NET Core?

Viewed 378

In .NET Framework such method exists:

public ConstructorInfo GetConstructor(
    BindingFlags bindingAttr,
    Binder binder,
    CallingConventions callConvention,
    Type[] types,
    ParameterModifier[] modifiers
)

But in .NET Core (1.1) I found only extension, which doesn't give me private constructor:

public static ConstructorInfo GetConstructor(this Type type, Type[] types)

So I'm wondering if I can somehow access and get private constructor in .NET Core.

1 Answers

Use TypeInfo.DeclaredConstructors.

According to documentation it applies to .NET Core 1.1 (and else).

You are expected to use GetTypeInfo().DeclaredConstructors and LINQ filter to find the desired constructor.

Related