x2bool
x2bool

Reputation: 2906

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

Upvotes: 5

Views: 2645

Answers (2)

Scott Hannen
Scott Hannen

Reputation: 29262

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

Upvotes: 2

Felix K.
Felix K.

Reputation: 6281

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.

Upvotes: 7

Related Questions