10

Metro Style Appポータブルライブラリのクラスのカスタム属性を定義および取得しようとしています。メトロスタイルAppのカ​​スタムクラス属性

[AttributeUsage(AttributeTargets.Class)] 
public class FooAttribute : Attribute 
{ 
} 

[Foo] 
public class Bar 
{ 
} 


class Program 
{ 
    static void Main(string[] args) 
    { 
     var attrs = CustomAttributeExtensions.GetCustomAttribute<FooAttribute>(typeof(Bar)); 
    } 
} 

ような何かOPによると

Cannot convert type 'System.Type' to 'System.Reflection.MemberInfo' 

おかげ

+0

どうやら、あなたは( VAR attrsに= CustomAttributeExtensions.GetCustomAttribute を行う必要がありますtypeof(Bar).GetTypeInfo()); –

+1

http://msdn.microsoft.com/en-us/library/windows/apps/hh535795%28v=vs.110%29.aspx –

+1

@ user1364325上記のコメントのコードが問題を解決する場合は、答えとそれに答えてマークしてください。 – Adam

答えて

4

それとも、あまりにもレバレッジ拡張子と一致しているようだ:

var attr = typeof(Bar).GetTypeInfo().GetCustomAttribute<FooAttribute>(); 
2

をこれが通常の4.5で動作しますが、Metroスタイルアプリをターゲットポータブルなライブラリで、それは私に語った:

You n var attrs = CustomAttributeExtensions.GetCustomAttribute(typeof(Bar).GetTypeIn fo());を実行します。

これは、彼らが意味していたとしてthe documentation