Is there a replacement for Attribute.IsDefined in UWP apps?

It seems that there is no static Attribute.IsDefined method for UWP applications, I can go to the metadata for the Attribute class in order and there is a method, but the project will not compile, stating that "Attribute" does not contain the definition of "IsDefined" - strange (actually, there are no static methods in this type according to IntelliSense).

I was going to request types with a specific attribute, e.g.

var types = this.GetType().GetTypeInfo().Assembly.GetTypes()
            .Where(t => Attribute.IsDefined(t, typeof (MyAttribute)));

and I wonder if there is a workaround.

+4
source share
1 answer

This should work:

var types = this.GetType().GetTypeInfo().Assembly.GetTypes()
        .Where(t => t.GetTypeInfo().GetCustomAttribute<MyAttribute>() != null);
+2
source

Source: https://habr.com/ru/post/1606072/


All Articles