2015-09-05 17 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

相關問題