Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom Class Attributes in Metro Style App

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

like image 379
marc-dworkin Avatar asked Apr 29 '12 15:04

marc-dworkin


1 Answers

Or, too leverage extensions as they were meant:

var attr = typeof(Bar).GetTypeInfo().GetCustomAttribute<FooAttribute>();
like image 165
Andreas Hassmann Avatar answered Oct 15 '22 19:10

Andreas Hassmann