public void NavigationCreator(INavigation navigation, string filePath, string entityClassName) { string file = null; using (var sr = new StreamReader("./CodeTemplates/NavigationTemplate.txt")) { file = sr.ReadToEnd(); } var className = $"{navigation.Name}Navigation"; var fileText = Smart.Format(file, new { Namespace = namespaceString, ClassName = className, EntityClassName = entityClassName, Name = navigation.Name, ClrType = navigation.ClrType.FullName, PropertyInfo = navigation.PropertyInfo.Name, FieldInfo = navigation.FieldInfo.Name, DeclaringEntityType = $"{EntityListFormatter.GetNameOfIEntityType(navigation.DeclaringEntityType)}.GetInstance()", IsShadowProperty = navigation.IsShadowProperty?"true":"false", IsEagerLoaded = navigation.IsEagerLoaded?"true":"false", DeclaringType = $"{EntityListFormatter.GetNameOfIEntityType(navigation.DeclaringType)}.GetInstance()", ForeignKey = navigation.ForeignKey != null? string.Format("{0}.GetInstance()", ForeignKeyListFormatter.GetNameOfForeignKey(navigation.ForeignKey)):"null", ForeignKeyObject = navigation.ForeignKey, }); File.WriteAllText($"{filePath}/{className}.cs", fileText); }
private void CreateIndex(IIndex index, string filePath, string entityClassName) { string file = null; using (var sr = new StreamReader("./CodeTemplates/IndexTemplate.txt")) { file = sr.ReadToEnd(); } var className = $"{index.ToString().Split(".").Last().Split(" ").First()}Index"; var fileText = Smart.Format(file, new { Namespace = namespaceString, EntityClassName = entityClassName, Annotations = index.GetAnnotations(), ClassName = IndexListFormatter.GetNameOfIndex(index), IsUnique = index.IsUnique?"true":"false", DeclaringEntityType = EntityListFormatter.GetNameOfIEntityType(index.DeclaringEntityType), Properties = index.Properties }); File.WriteAllText($"{filePath}/{className}.cs", fileText); }
private void KeyCreator(IKey key, string filePath, string entityClassName) { string file = null; using (var sr = new StreamReader("./CodeTemplates/KeyTemplate.txt")) { file = sr.ReadToEnd(); } var className = KeyListFormatter.GetNameOfKey(key); var fileText = Smart.Format(file, new { Namespace = namespaceString, EntityClassName = entityClassName, ClassName = className, Annotations = key.GetAnnotations(), DeclaringEntityType = EntityListFormatter.GetNameOfIEntityType(key.DeclaringEntityType), Properties = key.Properties }); File.WriteAllText($"{filePath}/{className}.cs", fileText); }
private void EntityTypeCreator(IEntityType entityType) { string file = null; using (StreamReader sr = new StreamReader("./CodeTemplates/EntityTypeTemplate.txt")) { file = sr.ReadToEnd(); } var entityClassName = EntityListFormatter.GetNakedNameOfIEntityType(entityType); var filePath = $"{filePathRoot}/{entityClassName}"; var className = EntityListFormatter.GetNameOfIEntityType(entityType); var classNameNameSpace = entityType.ClrType.Namespace; var primaryKey = entityType.FindPrimaryKey(); Directory.CreateDirectory(filePath); foreach (var property in entityType.GetProperties()) { PropertyCreator(property, filePath, className, classNameNameSpace, entityClassName); } foreach (var key in entityType.GetKeys()) { KeyCreator(key, filePath, entityClassName); } foreach (var index in entityType.GetIndexes()) { CreateIndex(index, filePath, entityClassName); } foreach (var serviceProperty in entityType.GetServiceProperties()) { ServicePropertyCreator(serviceProperty, filePath, entityClassName); } foreach (var foreignKey in entityType.GetForeignKeys()) { ForeignKeyCreator(foreignKey, filePath, entityClassName); } foreach (var navigation in entityType.GetNavigations()) { NavigationCreator(navigation, filePath, entityClassName); } var fileText = Smart.Format(file, new { Namespace = namespaceString, ClassName = className, ClassNamespace = classNameNameSpace, EntityName = entityType.Name, Annotations = entityType.GetAnnotations(), Keys = entityType.GetKeys(), ServiceProperties = entityType.GetServiceProperties(), ForeignKeys = entityType.GetForeignKeys(), Properties = entityType.GetProperties(), Indexes = entityType.GetIndexes(), ConfigurationSource = ((Key)primaryKey).GetConfigurationSource(), PrimaryKeyProperties = primaryKey.Properties, EntityClassName = entityClassName, QueryFilter = entityType.QueryFilter, DefiningQuery = entityType.DefiningQuery, DefiningNavigationName = entityType.DefiningNavigationName ?? "null", DefiningEntityType = entityType.DefiningEntityType == null ?"null":string.Format("{0}.GetInstance()", EntityListFormatter.GetNameOfIEntityType(entityType.DefiningEntityType)), IsQueryType = entityType.IsQueryType?"true":"false", BaseType = entityType.BaseType != null? string.Format("{0}.GetInstance()", EntityListFormatter.GetNameOfIEntityType(entityType.BaseType)):"null" } ); File.WriteAllText($"{filePath}/{className}.cs", fileText); }
private void ForeignKeyCreator(IForeignKey foreignKey, string filePath, string entityClassName) { string file = null; using (var sr = new StreamReader("./CodeTemplates/ForeignKeyTemplate.txt")) { file = sr.ReadToEnd(); } var className = ForeignKeyListFormatter.GetNameOfForeignKey(foreignKey); var fileText = Smart.Format(file, new { Namespace = namespaceString, EntityClassName = entityClassName, ClassName = className, IsUnique = foreignKey.IsUnique?"true":"false", IsRequired = foreignKey.IsRequired?"true":"false", IsOwnership = foreignKey.IsOwnership?"true":"false", DeleteBehavior = foreignKey.DeleteBehavior, Properties = foreignKey.Properties, DependentToPrincipal = foreignKey.DependentToPrincipal != null ?string.Format("{0}.GetInstance()", NavigationFormatter.GetNameOfNavigation(foreignKey.DependentToPrincipal)):"null", PrincipalToDependent = foreignKey.PrincipalToDependent != null ?string.Format("{0}.GetInstance()", NavigationFormatter.GetNameOfNavigation(foreignKey.PrincipalToDependent)):"null", PrincipalKey = foreignKey.PrincipalKey != null? string.Format("{0}.GetInstance()", KeyListFormatter.GetNameOfKey(foreignKey.PrincipalKey)):"null", PrincipalEntityType = foreignKey.PrincipalEntityType != null? string.Format("{0}.GetInstance()", EntityListFormatter.GetNameOfIEntityType(foreignKey.PrincipalEntityType)):"null", Annotations = foreignKey.GetAnnotations(), DeclaringEntityType = foreignKey.DeclaringEntityType != null? string.Format("{0}.GetInstance()", EntityListFormatter.GetNameOfIEntityType(foreignKey.DeclaringEntityType)):"null" }); File.WriteAllText($"{filePath}/{className}.cs", fileText); }