用属性来传值

来源:互联网 发布:软件维护收费标准 编辑:程序博客网 时间:2024/05/16 11:50

定义:   

[Serializable]
    [System.AttributeUsage(System.AttributeTargets.Property, AllowMultiple = true)]
    public class ParameterMappingAttribute : System.Attribute
    {
        private string mstrVariableName = "";

        public ParameterMappingAttribute()
        {
        }

        public ParameterMappingAttribute(string pstrVariableName)
        {
            mstrVariableName = pstrVariableName;
        }

        public string VariableName
        {
            get { return this.mstrVariableName; }
            set { this.mstrVariableName = value; }
        }
    }

使用:
private string mEv;

[ParameterMapping("xxxxxx")]
        public string Ev
        {
            set { this.mEv = value; }
            get { return this.mEv; }
        }

原创粉丝点击