c# - 我可以在 .NET Core 中获取私有构造函数吗?
问题描述
在 .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 中以某种方式访问和获取私有构造函数。
解决方案
使用TypeInfo.DeclaredConstructors
.
根据文档,它适用于 .NET Core 1.1(和其他)。
您应该使用GetTypeInfo().DeclaredConstructors
LINQ 过滤器来找到所需的构造函数。
推荐阅读
- ruby - 将函数存储在哈希中键的值中
- ssh - 从 circleci SSH 到 digitalocean 服务器
- python - 规范化熊猫数据框中的列
- mongodb - 在 mongodb 中为每个用户应用 FIFO 文档
- asp.net-mvc - 未调用 Azure 应用服务预热 ping 路径
- python - Python中有没有办法确保我的函数的一个参数是另一个函数?
- performance - GTmetrix 瀑布图中的大缺口,有没有办法摆脱它们?
- python - 如何在 tweepy 中使用多个“过滤器”?
- oracle - Oracle计算各部分的总和
- javascript - 为什么数组函数像标记的模板文字一样工作,我能用它做什么?