C# CoreCLR中的Type.GetCustomAttributes方法在哪里?
我试图从类中获取属性,但似乎没有GetCustomAttributes方法。如何在CoreCLR中获取属性C# CoreCLR中的Type.GetCustomAttributes方法在哪里?,c#,.net,reflection,asp.net-core,coreclr,C#,.net,Reflection,Asp.net Core,Coreclr,我试图从类中获取属性,但似乎没有GetCustomAttributes方法。如何在CoreCLR中获取属性 using System.Reflection; class FooBar { FooBar() { GetType().GetCustomAttributes(); // does not compile GetType().GetField("test").GetCustomAttributes(); // compiles } }
using System.Reflection;
class FooBar {
FooBar() {
GetType().GetCustomAttributes(); // does not compile
GetType().GetField("test").GetCustomAttributes(); // compiles
}
}
尝试
TypeInfo
,您可以通过Type.GetTypeInfo()
获得它,这是来自System.Reflection
命名空间的扩展方法
这是添加的,然后使用.GetTypeInfo().CustomAttributes