加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-15 06:34:38 所属栏目:百科 来源:网络整理
导读:我试图在Metro Style App便携式库中定义和检索一个类的自定义属性. 就像是 [AttributeUsage(AttributeTargets.Class)]public class FooAttribute : Attribute{}[Foo]public class Bar{}class Program{ static void Main(string[] args) { var attrs = Custom
我试图在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一致

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读