Custom Class Attributes in Metro Style App

c#, custom-attributes, portable-class-library, system.reflection, windows-runtime

Solution

Or, too leverage extensions as they were meant:

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

Problem

I am trying to define and retrieve custom attributes on a class in a Metro Style App portable library. Something like ``` [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)); } } ``` This works in ordinary 4.5, but in a portable library targetting metro style apps it tells me ``` Cannot convert type 'System.Type' to 'System.Reflection.MemberInfo' ``` Thanks

Original source