在.NET Framework中,这种方法存在:
public ConstructorInfo GetConstructor(
BindingFlags bindingAttr,
Binder binder,
CallingConventions callConvention,
Type[] types,
ParameterModifier[] modifiers
)
但是在.NET Core(1.1)中,我仅找到扩展名,但这并没有给我私有构造函数:
public static ConstructorInfo GetConstructor(this Type type, Type[] types)
所以我想知道我是否可以通过某种方式访问并获得.NET Core中的私有构造函数。
答案 0 :(得分:3)
使用TypeInfo.DeclaredConstructors
。
根据documentation,它适用于.NET Core 1.1(及其他)。
您应该使用GetTypeInfo().DeclaredConstructors
和LINQ过滤器来找到所需的构造函数。