资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

编写自定义特性

===========================Document.cs

成都做网站、网站建设介绍好的网站是理念、设计和技术的结合。创新互联拥有的网站设计理念、多方位的设计风格、经验丰富的设计团队。提供PC端+手机端网站建设,用营销思维进行网站设计、采用先进技术开源代码、注重用户体验与SEO基础,将技术与创意整合到网站之中,以契合客户的方式做到创意性的视觉化效果。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication2
{
    [AttributeUsage(AttributeTargets.Property,//该特性能够应用的范围(只能用于属性)
        AllowMultiple = true,//是否支持多个应用到同一个项上
        Inherited = true)//如果特性应用到类或接口上,就会自动应用到所有派生的类或接口上,
        ]              //如果特性应用在属性或方法上,就会自动应用到该方法或属性的重写版本上
    public class DocumentAttribute : Attribute
    {
        private string m_strName;
        private bool m_blnIsYes;
        public bool IsYes { get { return m_blnIsYes; } set { m_blnIsYes = value; } }
        public DocumentAttribute(string p_name)
        {
            this.m_strName = p_name;
        }
    }
}

===========================主程序

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication2
{
    class Program
    {
        //指定特性
        [Document("文档一",//构造函数需要传入的值
            IsYes = true)]//可选参数(Document类的属性)
        public string Name { get; set; }
        static void Main(string[] args)
        {
        }
    }
}

网页标题:编写自定义特性
URL链接:http://cdkjz.cn/article/gsshjs.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220