楼上我是想实现这种效果,但不想这样实现
我感觉应该有更简单的方法
就像textbox label都有个backcolor属性
我想这里让telephone和id可能都有个共同的属性
我想是不是可以用特性+反射来实现?

解决方案 »

  1.   

    backcolor是通过共同的父类继承下来的
    要么你就telephone和id不用简单类型string和id
    自己定义类,继承要么,自己继承Attribute写自定义特性,但是,自定义特性和backcolor是完全不同的
      

  2.   

    backcolor是通过共同的父类继承下来的
    要么你就telephone和id不用简单类型string和id
    自己定义类,继承要么,自己继承Attribute写自定义特性,但是,自定义特性和backcolor是完全不同的
      

  3.   

    是不是像下面这种:
    class user
    {
       public CustomerAttribute Telephone
       {get;set;}
    }
    class CustomerAttribute
    {
      public String TelephoneNumber
      {get;set;}
      Public Color BackColor
      {get;set;}
      //..........
    }
      

  4.   

    [AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = false)]
        [Serializable]
        public class DBProperty : Attribute
        {
        
            int maxLength;
               .............
            /// <summary>
            /// 数据列最大长度
            /// </summary>
            public int MaxLength
            {
                get { return maxLength; }
                set { maxLength = value; }
            }
         }public class Contact
        {
            #region field
            int n_ID;
            string s_NAME;       
            #endregion
            #region property
            [DBProperty(Name="N_ID",IsAutoIncrease=true,IsPrimaryKey=true,OrmDBType= ORMEnum.DataType.INT)]
            public int N_ID
            {
                get { return n_ID; }
                set { n_ID = value; }
            }
            [DBProperty(Name = "S_NAME",OrmDBType = ORMEnum.DataType.STRING,MaxLength=10,NotRepeat=true,NotNull=true)]
            public string S_NAME
            {
                get { return s_NAME; }
                set { s_NAME = value; }
            }                
            #endregion    }绑定的时候再对这个东西进行解释,即可!
      

  5.   

    我觉得你的问题的是双向绑定的问题,就用你上面说的backcolor与Telephone来说,
    public class User
    {
      public Color ErrorColor//与Textbox的backcolor属性绑定
       {
          get;
          set;
       }
      public string Telephone
       {
          get;
          set
           {
             if(value判断格式是不是正确的)
               不正确的话改变this.ErrorColor = Color.Red;
           }
       }
    }将User类与TextBox控件的两个属性绑定,当text属性发生改变时,user类的telephone属性也会发生改变,这时你会在里面判断用户输入的格式是不是正确的,如果不正确就修改ErrorColor属性值,而ErrorColor属性又与TextBox控件的backcolor属性绑定,所以errorcolor的改变就会改变Textbox控件的颜色。
    具体实现不知道,但记得在那里看到过
      

  6.   

    Enterprise Library 3.1 - May 2007 可以满足你的要求,验证实体类。