Esempio n. 1
0
        public static CollectionInfo GetInfo(FieldInfo fieldInfo)
        {
            CollectionInfo      info      = null;
            CollectionAttribute attribute = fieldInfo.GetCustomAttribute <CollectionAttribute>(false);

            if (attribute != null)
            {
                info = new CollectionInfo();
                info.CollectionType = attribute.CollectionType;
                info.Name           = string.IsNullOrEmpty(attribute.Name)
                                        ? Char.ToUpper(fieldInfo.Name[0]) + fieldInfo.Name.Substring(1)
                                        : attribute.Name;;
                info.MapSourceKey = string.IsNullOrEmpty(attribute.MapSourceKey)
                                        ? fieldInfo.DeclaringType.Name + "_Id"
                                        : attribute.MapSourceKey;
                info.TargetType = attribute.TargetType == null
                                        ? fieldInfo.FieldType.GetGenericArguments()[0]
                                        : attribute.TargetType;

                info.MapTargetKey = string.IsNullOrEmpty(attribute.MapTargetKey)
                                        ? info.TargetType.Name + "_Id"
                                        : attribute.MapTargetKey;
                info.IntermediateTableName = attribute.IntermediateTableName;
                info.FieldInfo             = fieldInfo;
            }
            return(info);
        }
Esempio n. 2
0
        protected virtual void SetInfo(Type type)
        {
            BaseInfo = GetInfo(type.BaseType);
            if (BaseInfo != null)
            {
                foreach (ColumnInfo col in BaseInfo.AllColumns.Values)
                {
                    allColumns[col.Name] = col;
                }
            }
            PropertyInfo[] properties = type.GetProperties(BindingFlags.Instance | BindingFlags.Public);
            foreach (var property in properties)
            {
                ColumnInfo column = ColumnInfo.GetInfo(property);
                if (column != null)
                {
                    if (column.IsPrimaryKey)
                    {
                        primaryKeys[column.Name] = column;
                    }
                    else
                    {
                        columns[column.Name]    = column;
                        allColumns[column.Name] = column;
                    }
                }
            }

            FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic);
            foreach (var field in fields)
            {
                CollectionInfo collection = CollectionInfo.GetInfo(field);
                if (collection != null)
                {
                    collections[collection.Name] = collection;
                }
            }
        }
Esempio n. 3
0
		public static CollectionInfo GetInfo(FieldInfo fieldInfo)
		{
			CollectionInfo info = null;
			CollectionAttribute attribute = fieldInfo.GetCustomAttribute<CollectionAttribute>(false);
			if (attribute != null)
			{
				info = new CollectionInfo();
				info.CollectionType = attribute.CollectionType;
				info.Name = string.IsNullOrEmpty(attribute.Name)
					? Char.ToUpper(fieldInfo.Name[0]) + fieldInfo.Name.Substring(1)
					: attribute.Name; ;
				info.MapSourceKey = string.IsNullOrEmpty(attribute.MapSourceKey)
					? fieldInfo.DeclaringType.Name + "_Id"
					: attribute.MapSourceKey;
				info.TargetType = attribute.TargetType == null
					? fieldInfo.FieldType.GetGenericArguments()[0]
					: attribute.TargetType;
				info.MapTargetKey = string.IsNullOrEmpty(attribute.MapTargetKey)
					? info.TargetType.Name + "_Id"
					: attribute.MapTargetKey;
				info.IntermediateTableName = attribute.IntermediateTableName;
				info.FieldInfo = fieldInfo;
			}
			return info;
		}