.net core 关于.NET Core中.NET反射支持的查询

.net core 关于.NET Core中.NET反射支持的查询,.net-core,.net Core,我们正在将.NET 4.0类库移植到.NET Core 1.1,并在.NET Core CLR中遇到了一个对.NET反射支持有限的问题 是否有人可以帮助我们了解与.net核心等价物相关的任何详细信息,以便在程序集对象上调用Type.GetProperties和Type.GetCustomAttributes方法 Using System.Type; Type myType; var prop = myType.GetProperties(); var attrib =

我们正在将.NET 4.0类库移植到.NET Core 1.1,并在.NET Core CLR中遇到了一个对.NET反射支持有限的问题

是否有人可以帮助我们了解与.net核心等价物相关的任何详细信息,以便在程序集对象上调用
Type.GetProperties
Type.GetCustomAttributes
方法

 Using System.Type;
 Type myType;   
    var prop = myType.GetProperties();
    var attrib = myType.GetCustomAttributes(true);

我们可以看到有
CustomAttributes
属性,但它不返回自定义属性的实例,而是返回有关属性的元数据。

您需要像这样使用
GetTypeInfo

using System;
using System.Reflection;

Type myType = ...;   
TypeInfo myTypeInfo = myType.GetTypeInfo();

var prop = myTypeInfo.GetProperties();
var attrib = myTypeInfo.GetCustomAttributes(true);

当.NET Standard 2.0和.NET Core 2.0面世时,我的理解是,您不需要进行此更改,可以使用原始API。

首先调用
Type.GetTypeInfo
。作为附录,此名为“移植到.NET Core”的文档明确说明了对
System.Type
的更改,并说明了您建议的操作: