Where is Type.GetCustomAttributes method in CoreCLR?
Asked Answered
W

2

5

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
    }
}
Winn answered 20/3, 2016 at 12:24 Comment(0)
C
7

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.

Cyndicyndia answered 20/3, 2016 at 12:30 Comment(0)
A
2

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

Amygdala answered 20/3, 2016 at 23:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.