Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

uwp

It seems that the static method Attribute.IsDefined is missing for UWP apps, I can navigate to the metadata for the Attribute class alright and the method is there, but the project won't compile stating that 'Attribute' does not contain a definition for 'IsDefined' - weird (matter of fact, there are no static methods on that type at all according to IntelliSense).

I was going to query for types with a certain attribute like

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

and am wondering if there is a workaround.

like image 243
Thorsten Westheider Avatar asked Oct 19 '22 03:10

Thorsten Westheider


1 Answers

This should work:

var types = this.GetType().GetTypeInfo().Assembly.GetTypes()
        .Where(t => t.GetTypeInfo().GetCustomAttribute<MyAttribute>() != null);
like image 124
Jeff Avatar answered Oct 21 '22 21:10

Jeff