private EntityMeta GenerateEntityMeta() { if (Type is EnumType) { var entityType = Type as EnumType; var entityMeta = new EnumMeta(); entityMeta.ProjectName = Model.Project.Name; entityMeta.ModelName = Model.Name; entityMeta.EntityType = Enum.GetName(typeof(EntityType), entityType.EntityType); entityMeta.Access = Enum.GetName(typeof(AccessModifier), entityType.Access); entityMeta.Name = entityType.Name; entityMeta.ValuesCount = entityType.ValueCount; foreach (var value in entityType.Values) { entityMeta.Values.Add(Enum.GetName(typeof(EnumValue), value)); } return entityMeta; } else { var entityType = Type as CompositeType; var entityMeta = new CompositeMeta(); entityMeta.ProjectName = Model.Project.Name; entityMeta.ModelName = Model.Name; entityMeta.EntityType = Enum.GetName(typeof(EntityType), entityType.EntityType); entityMeta.Access = Enum.GetName(typeof(AccessModifier), entityType.Access); entityMeta.Name = entityType.Name; entityMeta.NHMTableName = entityType.NHMTableName; entityMeta.IdentityGenerator = EnumExtensions.GetDescription((IdentityGeneratorType)Enum.Parse(typeof(IdentityGeneratorType), entityType.IdGenerator)); if (entityType.SupportsFields) { entityMeta.FieldsCount = entityType.FieldCount; foreach (var field in entityType.Fields) { var fieldMeta = new FieldMeta(); fieldMeta.MemberType = Enum.GetName(typeof(MemberType), field.MemberType); fieldMeta.Access = Enum.GetName(typeof(AccessModifier), field.Access); fieldMeta.Name = field.Name; fieldMeta.Type = field.Type; entityMeta.Fields.Add(fieldMeta); } } if (entityType.SupportsOperations) { entityMeta.OperationsCount = entityType.OperationCount; foreach (var operation in entityType.Operations) { var operationMeta = new OperationMeta(); operationMeta.MemberType = Enum.GetName(typeof(MemberType), operation.MemberType); operationMeta.Access = Enum.GetName(typeof(AccessModifier), operation.Access); operationMeta.Name = operation.Name; operationMeta.Type = operation.Type; operationMeta.NHMColumnName = operation.NHMColumnName; operationMeta.Identity = operation.IsIdentity; operationMeta.ManyToOne = operation.ManyToOne; operationMeta.Unique = operation.IsUnique; operationMeta.NotNull = operation.IsNotNull; entityMeta.Operations.Add(operationMeta); } } return entityMeta; } }
private EntityMeta GenerateEntityMeta() { if (Type is EnumType) { var entityType = Type as EnumType; var entityMeta = new EnumMeta(); entityMeta.ProjectName = Model.Project.Name; entityMeta.ModelName = Model.Name; entityMeta.EntitiesNames = Model.Entities.Select(x => x.Name).ToList(); entityMeta.EntityType = Enum.GetName(typeof(EntityType), Type.EntityType); entityMeta.Access = Enum.GetName(typeof(AccessModifier), entityType.Access); entityMeta.Name = entityType.Name; entityMeta.ValuesCount = entityType.ValueCount; foreach (var value in entityType.Values) { entityMeta.Values.Add(Enum.GetName(typeof(EnumValue), value)); } foreach (var relationship in Model.Relationships) { var relationshipMeta = new RelationshipMeta(); relationshipMeta.RelationshipType = Enum.GetName(typeof(RelationshipType), relationship.RelationshipType); relationshipMeta.SupportsLabel = relationship.SupportsLabel; relationshipMeta.Label = relationship.Label; relationshipMeta.FirstEntity.EntityType = Enum.GetName(typeof(EntityType), relationship.First.EntityType); relationshipMeta.FirstEntity.Name = relationship.First.Name; relationshipMeta.SecondEntity.EntityType = Enum.GetName(typeof(EntityType), relationship.Second.EntityType); relationshipMeta.SecondEntity.Name = relationship.Second.Name; entityMeta.Relationships.Add(relationshipMeta); } return(entityMeta); } else { var entityType = Type as CompositeType; var entityMeta = new CompositeMeta(); entityMeta.ProjectName = Model.Project.Name; entityMeta.ModelName = Model.Name; entityMeta.EntitiesNames = Model.Entities.Select(x => x.Name).ToList(); entityMeta.EntityType = Enum.GetName(typeof(EntityType), Type.EntityType); entityMeta.Access = Enum.GetName(typeof(AccessModifier), entityType.Access); entityMeta.Name = entityType.Name; if (entityType.SupportsFields) { entityMeta.FieldsCount = entityType.FieldCount; foreach (var field in entityType.Fields) { var fieldMeta = new FieldMeta(); fieldMeta.MemberType = Enum.GetName(typeof(MemberType), field.MemberType); fieldMeta.Access = Enum.GetName(typeof(AccessModifier), field.Access); fieldMeta.Name = field.Name; fieldMeta.Type = field.Type; entityMeta.Fields.Add(fieldMeta); } } if (entityType.SupportsOperations) { entityMeta.OperationsCount = entityType.OperationCount; foreach (var operation in entityType.Operations) { var operationMeta = new OperationMeta(); operationMeta.MemberType = Enum.GetName(typeof(MemberType), operation.MemberType); operationMeta.Access = Enum.GetName(typeof(AccessModifier), operation.Access); operationMeta.Name = operation.Name; operationMeta.Type = operation.Type; entityMeta.Operations.Add(operationMeta); } } foreach (var relationship in Model.Relationships) { var relationshipMeta = new RelationshipMeta(); relationshipMeta.RelationshipType = Enum.GetName(typeof(RelationshipType), relationship.RelationshipType); relationshipMeta.SupportsLabel = relationship.SupportsLabel; relationshipMeta.Label = relationship.Label; relationshipMeta.FirstEntity.EntityType = Enum.GetName(typeof(EntityType), relationship.First.EntityType); relationshipMeta.FirstEntity.Name = relationship.First.Name; relationshipMeta.SecondEntity.EntityType = Enum.GetName(typeof(EntityType), relationship.Second.EntityType); relationshipMeta.SecondEntity.Name = relationship.Second.Name; entityMeta.Relationships.Add(relationshipMeta); } return(entityMeta); } }