Пример #1
0
        /// <summary>
        /// Gets the type discription.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <returns></returns>
        public static TypeDescription GetTypeDiscription(Type type)
        {
            TypeDescription description = s_typeInfoDict[type.FullName] as TypeDescription;

            if (description == null)
            {
                PropertyInfo[] properties = type.GetProperties(s_flag);
                int            length     = properties.Length;
                Dictionary <string, DbMapInfo> dictionary = new Dictionary <string, DbMapInfo>(length, StringComparer.OrdinalIgnoreCase);
                foreach (PropertyInfo info in properties)
                {
                    DbMapInfo             info2       = null;
                    DataColumnAttribute   myAttribute = info.GetMyAttribute <DataColumnAttribute>();
                    IgnoreColumnAttribute attrIgnore  = info.GetMyAttribute <IgnoreColumnAttribute>();
                    if (myAttribute != null)
                    {
                        info2 = new DbMapInfo(string.IsNullOrEmpty(myAttribute.Alias) ? info.Name : myAttribute.Alias, info.Name, myAttribute, attrIgnore, info);
                    }
                    else
                    {
                        info2 = new DbMapInfo(info.Name, info.Name, null, attrIgnore, info);
                    }
                    dictionary[info2.DbName] = info2;
                }
                description = new TypeDescription
                {
                    MemberDict = dictionary
                };
                s_typeInfoDict[type.FullName] = description;
            }
            return(description);
        }
Пример #2
0
 public DbMapInfo(string dbName, string netName, DataColumnAttribute attrColumn, IgnoreColumnAttribute attrIgnore, PropertyInfo prop)
 {
     this.DbName       = dbName;
     this.NetName      = netName;
     this.AttrColumn   = attrColumn;
     this.PropertyInfo = prop;
     this.AttrIgnore   = AttrIgnore;
 }
Пример #3
0
        public static TypeDescription GetTypeDiscription(Type type)
        {
            TypeDescription description = s_typeInfoDict[type.FullName] as TypeDescription;

            if (description == null)
            {
                PropertyInfo[] properties           = type.GetProperties(s_flag);
                int            length               = properties.Length;
                Dictionary <string, DbMapInfo> dict = new Dictionary <string, DbMapInfo>(length, StringComparer.OrdinalIgnoreCase);

                foreach (PropertyInfo prop in properties)
                {
                    DbMapInfo info = null;

                    DataColumnAttribute   attrColumn = prop.GetMyAttribute <DataColumnAttribute>();
                    IgnoreColumnAttribute attrIgnore = prop.GetMyAttribute <IgnoreColumnAttribute>();

                    if (attrColumn != null)
                    {
                        info = new DbMapInfo(string.IsNullOrEmpty(attrColumn.Alias) ? prop.Name : attrColumn.Alias, prop.Name, attrColumn, attrIgnore, prop);
                    }
                    else
                    {
                        info = new DbMapInfo(prop.Name, prop.Name, null, attrIgnore, prop);
                    }

                    dict[info.DbName] = info;
                }

                description = new TypeDescription {
                    MemberDict = dict
                };

                // 添加到缓存字典
                s_typeInfoDict[type.FullName] = description;
            }

            return(description);
        }
Пример #4
0
        public CodeGenerator(Type entityType)
        {
            _entityType = entityType;
            _sb         = new StringBuilder(1024 * 20);

            DataEntityAttribute entityAttr = _entityType.GetMyAttribute <DataEntityAttribute>();
            string tableName;

            if (entityAttr == null)
            {
                tableName = _entityType.Name;
            }
            else
            {
                tableName = string.IsNullOrEmpty(entityAttr.Alias) ? _entityType.Name : entityAttr.Alias;
            }


            _tableInfo = new DbMapInfo(tableName, _entityType.Name, null, null, null);


            _allFields = new List <DbMapInfo>(20);
            _keyFields = new List <DbMapInfo>(3);

            DbMapInfo info = null;

            foreach (PropertyInfo property in _entityType.GetProperties(BindingFlags.Instance | BindingFlags.Public))
            {
                string fieldName = property.Name;

                IgnoreColumnAttribute attrIgnore = property.GetMyAttribute <IgnoreColumnAttribute>();
                if (attrIgnore != null)
                {
                    continue;
                }

                DataColumnAttribute attrColumn = property.GetMyAttribute <DataColumnAttribute>();

                if (attrColumn != null)
                {
                    if (string.IsNullOrEmpty(attrColumn.Alias) == false)
                    {
                        fieldName = attrColumn.Alias;
                    }

                    info = new DbMapInfo(fieldName, property.Name, attrColumn, attrIgnore, property);
                    _allFields.Add(new DbMapInfo(fieldName, property.Name, attrColumn, attrIgnore, property));

                    if (attrColumn.Identity)
                    {
                        _identityField = info;
                    }
                    if (attrColumn.TimeStamp)
                    {
                        _timeStampField = info;
                    }
                    if (attrColumn.SeqGuid)
                    {
                        _seqGuidField = info;
                    }

                    if (attrColumn.PrimaryKey)
                    {
                        _keyFields.Add(info);
                    }
                }
                else
                {
                    _allFields.Add(new DbMapInfo(fieldName, property.Name, null, attrIgnore, property));
                }
            }
        }