2015-09-05 16 views
4

似乎缺少UWP应用程序的静态方法Attribute.IsDefined,我可以导航到Attribute类的元数据,并且方法在那里,但是项目不会编译,指出'Attribute'不包含定义'IsDefined' - 奇怪(事实上,根据IntelliSense,根本没有这种类型的静态方法)。是否有替换UWP应用中的Attribute.IsDefined?

我打算有特定属性来查询类型,如

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

,我想知道如果有一种变通方法。

回答

2

这应该工作:

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

工程就像一个魅力,非常感谢! –

+0

嗯。 GetCustomAttribute接受类型'Type'的第一个参数也找不到。 – ickydime

+0

这似乎为我工作:http://stackoverflow.com/questions/30972197/system-type-has-no-definition-for-getcustomattribute-in-net35 – ickydime

相关问题