c# – Metro风格应用程序中的自定义类属性

我试图在Metro Style 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));
    }
}

这在普通的4.5工作,但在一个便携式图书馆,针对地铁风格的应用程序,它告诉我

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

谢谢

解决方法

根据OP:

You need to do var attrs = CustomAttributeExtensions.GetCustomAttribute(typeof(Bar).GetTypeIn‌​fo());

这似乎与the documentation一致

相关文章

在要实现单例模式的类当中添加如下代码:实例化的时候:frmC...
1、如果制作圆角窗体,窗体先继承DOTNETBAR的:public parti...
根据网上资料,自己很粗略的实现了一个winform搜索提示,但是...
近期在做DSOFramer这个控件,打算自己弄一个自定义控件来封装...
今天玩了一把WMI,查询了一下电脑的硬件信息,感觉很多代码都...
最近在研究WinWordControl这个控件,因为上级要求在系统里,...