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); }
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); }