【发布时间】:2017-03-26 19:57:25
【问题描述】:
我正在尝试将我的 .NET 4 项目升级到 .NETStandard 和 Core,但找不到对应的:-
var ctors = typeof(T).GetConstructors();
GetConstructors 是反射的一部分,因此似乎有意缺少或移动了支持...
谢谢。 西蒙。
【问题讨论】:
标签: c# .net-core .net-standard
我正在尝试将我的 .NET 4 项目升级到 .NETStandard 和 Core,但找不到对应的:-
var ctors = typeof(T).GetConstructors();
GetConstructors 是反射的一部分,因此似乎有意缺少或移动了支持...
谢谢。 西蒙。
【问题讨论】:
标签: c# .net-core .net-standard
在 .NET 标准 /Core 中,许多反射 api 被移动到特定的包 (system.reflection)。该包提供了Type类的扩展方法GetTypeInfo。
typeof(T).GetTypeInfo().DeclaredConstructors;
【讨论】:
很简单 - 只需添加 GetTypeInfo():
var ctors = typeof(T).GetTypeInfo().DeclaredConstructors();
【讨论】: