首页 > 其他 > 详细

定制特性

时间:2017-06-18 14:48:38      阅读:258      评论:0      收藏:0      [点我收藏+]

1,定制特性

①C#允许用一个前缀明确指定特性要应用的目标元素

[assembly: AssemblyVersion("1.0.0.0")]

②AttributeUsage. Inherited(特性应用于基类时,是否同时应用于派生类和重写的方法)

    [AttributeUsage(AttributeTargets.Class|AttributeTargets.Method,Inherited = true)]
    internal class TastyAttribute : Attribute
    {
    }

    [Tasty,Serializable]
    internal class BaseType
    {
        [Tasty]
        protected virtual void DoSomething(){}
    }
    //继承父类Tasty的特性
    internal class DerivedType : BaseType
    {
        //继承Tasty的特性
        protected override void DoSomething(){}
    }
    //如果特性类没有显示的引用AttributeUsage,则默认AttributeUsage如下
    [AttributeUsage(AttributeTargets.All,AllowMultiple = false, Inherited = true)]

 

定制特性

原文:http://www.cnblogs.com/zd1994/p/7044203.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!