UWP应用程序中是否可以替换Attribute.IsDefined?

Tho*_*der 5 c# uwp

看来,UWP应用程序缺少静态方法Attribute.IsDefined,我可以导航到Attribute类的元数据,并且该方法在那里,但是项目不会编译,说明“ Attribute”不包含针对'IsDefined'-很奇怪(事实上,根据IntelliSense,该类型上根本没有静态方法)。

我要查询具有特定属性的类型,例如

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

并且想知道是否有解决方法。

Jef*_*eff 3

这应该有效:

var types = this.GetType().GetTypeInfo().Assembly.GetTypes()
        .Where(t => t.GetTypeInfo().GetCustomAttribute<MyAttribute>() != null);
Run Code Online (Sandbox Code Playgroud)