Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# CoreCLR中的Type.GetCustomAttributes方法在哪里?_C#_.net_Reflection_Asp.net Core_Coreclr - Fatal编程技术网

C# CoreCLR中的Type.GetCustomAttributes方法在哪里?

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 } }

我试图从类中获取属性,但似乎没有GetCustomAttributes方法。如何在CoreCLR中获取属性

using System.Reflection;

class FooBar {
    FooBar() {
        GetType().GetCustomAttributes(); // does not compile
        GetType().GetField("test").GetCustomAttributes(); // compiles
    }
}

尝试
TypeInfo
,您可以通过
Type.GetTypeInfo()
获得它,这是来自
System.Reflection
命名空间的扩展方法

这是添加的,然后使用
.GetTypeInfo().CustomAttributes