/// <summary> /// 初始化 <see cref="EntityMetadata"/> 类的新实例。 /// </summary> /// <param name="entityType">一个实体的类型。</param> internal EntityMetadata(Type entityType) { EntityType = entityType; //获取描述表名称映射的 EntityMappingAttribute var mapper = entityType.GetCustomAttributes <EntityMappingAttribute>(true).FirstOrDefault(); if (mapper != null) { TableName = mapper.TableName; Description = mapper.Description; } else { TableName = entityType.Name; } //获取描述树结构映射的 EntityTreeMappingAttribute var treeMapper = entityType.GetCustomAttributes <EntityTreeMappingAttribute>().FirstOrDefault(); if (treeMapper != null) { EntityTree = new EntityTreeMetadata(treeMapper); } //获取表名称变量映射的 EntityVariableAttribute var varMapper = entityType.GetCustomAttributes <EntityVariableAttribute>().FirstOrDefault(); if (varMapper != null) { TableName = varMapper.Expression.Replace("$", TableName); } }
/// <summary> /// 使用实体类型和 <see cref="EntityTreeMappingAttribute"/> 对象创建一个 <see cref="EntityTreeMetadata"/> 对象。 /// </summary> /// <param name="attribute"></param> /// <param name="entityType"></param> /// <returns></returns> public static EntityTreeMetadata CreateMetadata(Type entityType, EntityTreeMappingAttribute attribute) { var metadata = new EntityTreeMetadata(attribute); IProperty property; if (!string.IsNullOrEmpty(attribute.InnerSign) && (property = PropertyUnity.GetProperty(entityType, attribute.InnerSign)) != null) { metadata.InnerSign = property; } if (!string.IsNullOrEmpty(attribute.Level) && (property = PropertyUnity.GetProperty(entityType, attribute.Level)) != null) { metadata.Level = property; } if (!string.IsNullOrEmpty(attribute.Order) && (property = PropertyUnity.GetProperty(entityType, attribute.Order)) != null) { metadata.Order = property; } if (!string.IsNullOrEmpty(attribute.Name) && (property = PropertyUnity.GetProperty(entityType, attribute.Name)) != null) { metadata.Name = property; } if (!string.IsNullOrEmpty(attribute.FullName) && (property = PropertyUnity.GetProperty(entityType, attribute.FullName)) != null) { metadata.FullName = property; } return(metadata); }