Пример #1
0
        /// <summary>
        /// 取得指定类的所有数据属性。
        /// 静态缓存。
        /// </summary>
        /// <param name="t">实体类型</param>
        /// <returns>所有数据属性对象列表</returns>
        public static FieldItem[] AllFields(Type t)
        {
            if (_AllFields.ContainsKey(t))
            {
                return(_AllFields[t]);
            }
            lock (_AllFields)
            {
                if (_AllFields.ContainsKey(t))
                {
                    return(_AllFields[t]);
                }

                List <FieldItem> cFields = new List <FieldItem>();
                PropertyInfo[]   pis     = t.GetProperties();
                List <String>    names   = new List <String>();
                foreach (PropertyInfo item in pis)
                {
                    FieldItem field = new FieldItem();
                    field.Property        = item;
                    field.Column          = BindColumnAttribute.GetCustomAttribute(item);
                    field.DataObjectField = DataObjectAttribute.GetCustomAttribute(item, typeof(DataObjectFieldAttribute)) as DataObjectFieldAttribute;
                    cFields.Add(field);

                    if (names.Contains(item.Name))
                    {
                        throw new Exception(String.Format("{0}类中出现重复属性{1}", t.Name, item.Name));
                    }
                    names.Add(item.Name);
                }
                _AllFields.Add(t, cFields.ToArray());
                return(cFields.ToArray());
            }
        }
Пример #2
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="pi"></param>
 /// <param name="bc"></param>
 /// <param name="dof"></param>
 public FieldItem(PropertyInfo pi, BindColumnAttribute bc, DataObjectFieldAttribute dof)
 {
     Property        = pi;
     Column          = bc;
     DataObjectField = dof;
 }
Пример #3
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="pi"></param>
 /// <param name="bc"></param>
 public FieldItem(PropertyInfo pi, BindColumnAttribute bc)
 {
     Property = pi;
     Column   = bc;
 }