我们正在将 .Net 4.0类库移植到 .Net Core 1.1 ,并且遇到了对.Net Reflection的有限支持问题在.Net Core CLR中。
任何人都可以帮助我们处理与.net核心等效相关的任何细节,以便在程序集对象上调用Type.GetProperties
和Type.GetCustomAttributes
方法吗?
Using System.Type;
Type myType;
var prop = myType.GetProperties();
var attrib = myType.GetCustomAttributes(true);
我们可以看到有CustomAttributes
属性,但这并不会返回自定义属性的实例,而是返回有关属性的元数据。
任何帮助都非常感谢。
答案 0 :(得分:2)
您需要像这样使用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。