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
Or, too leverage extensions as they were meant:
var attr = typeof(Bar).GetTypeInfo().GetCustomAttribute<FooAttribute>();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With