Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is Type.GetCustomAttributes method in CoreCLR?

I am trying to get attributes from a class, and it seems that there is no GetCustomAttributes method. How to obtain attributes in CoreCLR?

using System.Reflection;

class FooBar {
    FooBar() {
        GetType().GetCustomAttributes(); // does not compile
        GetType().GetField("test").GetCustomAttributes(); // compiles
    }
}
like image 413
x2bool Avatar asked Mar 20 '16 12:03

x2bool


2 Answers

Try TypeInfo, you get it by Type.GetTypeInfo() which is a extension method from the System.Reflection namespace.

This has been changed with .NET 4.5.

like image 179
Felix K. Avatar answered Sep 28 '22 10:09

Felix K.


Add the the System.Reflection Nuget package, then use .GetTypeInfo().CustomAttributes

like image 35
Scott Hannen Avatar answered Sep 28 '22 11:09

Scott Hannen