Ejemplo n.º 1
0
        /// <summary>构造函数</summary>
        /// <param name="table"></param>
        /// <param name="property"></param>
        public FieldItem(TableItem table, PropertyInfo property)
        {
            if (property == null)
            {
                throw new ArgumentNullException("property");
            }

            _Table = table;

            _Property        = property;
            _Column          = BindColumnAttribute.GetCustomAttribute(_Property);
            _DataObjectField = DataObjectAttribute.GetCustomAttribute(_Property, typeof(DataObjectFieldAttribute)) as DataObjectFieldAttribute;
            _Description     = DescriptionAttribute.GetCustomAttribute(_Property, typeof(DescriptionAttribute)) as DescriptionAttribute;
        }
Ejemplo n.º 2
0
        /// <summary>构造函数</summary>
        /// <param name="table"></param>
        /// <param name="property">属性</param>
        public FieldItem(TableItem table, PropertyInfo property)
        {
            Table = table;

            if (property != null)
            {
                _Property = property;
                var dc = _Column = BindColumnAttribute.GetCustomAttribute(property);
                var df = _DataObjectField = property.GetCustomAttribute<DataObjectFieldAttribute>();
                var ds = _Description = property.GetCustomAttribute<DescriptionAttribute>();
                var di = _DisplayName = property.GetCustomAttribute<DisplayNameAttribute>();
                Map = property.GetCustomAttribute<MapAttribute>();
                Name = property.Name;
                Type = property.PropertyType;
                DeclaringType = property.DeclaringType;

                if (df != null)
                {
                    IsIdentity = df.IsIdentity;
                    PrimaryKey = df.PrimaryKey;
                    IsNullable = df.IsNullable;
                    Length = df.Length;

                    IsDataObjectField = true;
                }

                if (dc != null)
                {
                    Master = dc.Master;
                }

                if (dc != null && !dc.Name.IsNullOrWhiteSpace())
                    ColumnName = dc.Name;
                else
                    ColumnName = Name;

                if (ds != null && !String.IsNullOrEmpty(ds.Description))
                    Description = ds.Description;
                else if (dc != null && !String.IsNullOrEmpty(dc.Description))
                    Description = dc.Description;
                if (di != null && !di.DisplayName.IsNullOrEmpty())
                    DisplayName = di.DisplayName;

                var map = Map;
                if (map == null || map.Provider == null) ReadOnly = !property.CanWrite;
                var ra = property.GetCustomAttribute<ReadOnlyAttribute>();
                if (ra != null) ReadOnly = ra.IsReadOnly;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 获取实体类的描述名
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        static String GetDescription(Type type)
        {
            return(desCache.GetItem(type, delegate(Type key)
            {
                if (!typeof(IEntity).IsAssignableFrom(key))
                {
                    return null;
                }

                BindColumnAttribute att = AttributeX.GetCustomAttribute <BindColumnAttribute>(key, true);
                if (att != null && !String.IsNullOrEmpty(att.Description))
                {
                    return att.Description;
                }

                DescriptionAttribute att2 = AttributeX.GetCustomAttribute <DescriptionAttribute>(key, true);
                if (att2 != null && !String.IsNullOrEmpty(att2.Description))
                {
                    return att2.Description;
                }

                return null;
            }));
        }
Ejemplo n.º 4
0
        /// <summary>构造函数</summary>
        /// <param name="table"></param>
        /// <param name="property"></param>
        public FieldItem(TableItem table, PropertyInfo property)
        {
            if (property == null) throw new ArgumentNullException("property");

            _Table = table;

            _Property = property;
            _Column = BindColumnAttribute.GetCustomAttribute(_Property);
            _DataObjectField = DataObjectAttribute.GetCustomAttribute(_Property, typeof(DataObjectFieldAttribute)) as DataObjectFieldAttribute;
            _Description = DescriptionAttribute.GetCustomAttribute(_Property, typeof(DescriptionAttribute)) as DescriptionAttribute;
        }
Ejemplo n.º 5
0
        /// <summary>构造函数</summary>
        /// <param name="table"></param>
        /// <param name="property">属性</param>
        public FieldItem(TableItem table, PropertyInfo property)
        {
            //if (property == null) throw new ArgumentNullException("property");

            _Table = table;

            if (property != null)
            {
                _Property = property;
                var dc = _Column = BindColumnAttribute.GetCustomAttribute(property);
                var df = _DataObjectField = property.GetCustomAttribute <DataObjectFieldAttribute>();
                var ds = _Description = property.GetCustomAttribute <DescriptionAttribute>();
                var di = _DisplayName = property.GetCustomAttribute <DisplayNameAttribute>();
                Name          = property.Name;
                Type          = property.PropertyType;
                DeclaringType = property.DeclaringType;

                if (df != null)
                {
                    IsIdentity = df.IsIdentity;
                    PrimaryKey = df.PrimaryKey;
                    IsNullable = df.IsNullable;
                    Length     = df.Length;

                    IsDataObjectField = true;
                }

                if (dc != null)
                {
                    _ID    = dc.Order;
                    Master = dc.Master;
                }

                if (dc != null && !dc.Name.IsNullOrWhiteSpace())
                {
                    ColumnName = dc.Name;
                }
                else
                {
                    ColumnName = Name;
                }

                if (ds != null && !String.IsNullOrEmpty(ds.Description))
                {
                    Description = ds.Description;
                }
                else if (dc != null && !String.IsNullOrEmpty(dc.Description))
                {
                    Description = dc.Description;
                }
                if (di != null && !di.DisplayName.IsNullOrEmpty())
                {
                    DisplayName = di.DisplayName;
                }

                _ReadOnly = !property.CanWrite;
                var ra = property.GetCustomAttribute <ReadOnlyAttribute>();
                if (ra != null)
                {
                    _ReadOnly = ra.IsReadOnly;
                }
            }
        }