public void Test(string name) { const string template = @"{{Name}}"; var data = new PocoModel { Name = name }; var result = Template.Transform(template, data); Assert.AreEqual(name, result); }
public override List <string> PocoUsings(PocoModel data) { var usings = new List <string> { "System", "System.Collections.Generic", "System.Threading", "System.Threading.Tasks", }; if (Settings.IncludeCodeGeneratedAttribute) { usings.Add("System.CodeDom.Compiler"); } return(usings); }
public CodeOutput GeneratePoco(Table table) { var filename = table.NameHumanCaseWithSuffix() + Settings.FileExtension; if (!CanWritePoco()) { FileManagementService.DeleteFile(filename); return(null); } var isEfCore3Plus = Settings.IsEfCore3Plus(); var data = new PocoModel { UseHasNoKey = isEfCore3Plus && table.IsView && !table.HasPrimaryKey, HasNoPrimaryKey = !table.HasPrimaryKey, Name = table.DbName, NameHumanCaseWithSuffix = table.NameHumanCaseWithSuffix(), ClassModifier = Settings.EntityClassesModifiers, ClassComment = table.WriteComments(), ExtendedComments = table.WriteExtendedComments(), ClassAttributes = table.WriteClassAttributes(), BaseClasses = table.BaseClasses, InsideClassBody = Settings.WriteInsideClassBody(table), Columns = table.Columns .Where(x => !x.Hidden && !x.ExistsInBaseClass) .OrderBy(x => x.Ordinal) .Select((col, index) => new PocoColumnModel { AddNewLineBefore = index > 0 && (((Settings.IncludeExtendedPropertyComments == CommentsStyle.InSummaryBlock || Settings.IncludeComments == CommentsStyle.InSummaryBlock) && !string.IsNullOrEmpty(col.SummaryComments)) || (col.Attributes != null && col.Attributes.Any())), HasSummaryComments = (Settings.IncludeExtendedPropertyComments == CommentsStyle.InSummaryBlock || Settings.IncludeComments == CommentsStyle.InSummaryBlock) && !string.IsNullOrEmpty(col.SummaryComments), SummaryComments = !string.IsNullOrEmpty(col.SummaryComments) ? SecurityElement.Escape(col.SummaryComments) : null, Attributes = col.Attributes, OverrideModifier = col.OverrideModifier, WrapIfNullable = col.WrapIfNullable(), NameHumanCase = col.NameHumanCase, PrivateSetterForComputedColumns = Settings.UsePrivateSetterForComputedColumns && col.IsComputed ? "private " : string.Empty, PropertyInitialisers = Settings.UsePropertyInitialisers ? (string.IsNullOrWhiteSpace(col.Default) ? string.Empty : string.Format(" = {0};", col.Default)) : string.Empty, InlineComments = col.InlineComments }) .ToList(), HasReverseNavigation = table.ReverseNavigationProperty.Count > 0, ReverseNavigationProperty = table.ReverseNavigationProperty .OrderBy(x => x.Definition) .Select(x => new PocoReverseNavigationPropertyModel { ReverseNavHasComment = Settings.IncludeComments != CommentsStyle.None && !string.IsNullOrEmpty(x.Comments), ReverseNavComment = Settings.IncludeComments != CommentsStyle.None ? x.Comments : string.Empty, AdditionalReverseNavigationsDataAnnotations = Settings.AdditionalReverseNavigationsDataAnnotations, AdditionalDataAnnotations = x.AdditionalDataAnnotations, Definition = x.Definition }) .ToList(), HasForeignKey = table.HasForeignKey, ForeignKeyTitleComment = Settings.IncludeComments != CommentsStyle.None && table.Columns.SelectMany(x => x.EntityFk).Any() ? " // Foreign keys" + Environment.NewLine : string.Empty, ForeignKeys = table.Columns .SelectMany(x => x.EntityFk) .OrderBy(o => o.Definition) .Select(x => new PocoForeignKeyModel { HasFkComment = Settings.IncludeComments != CommentsStyle.None && !string.IsNullOrEmpty(x.Comments), FkComment = x.Comments, AdditionalForeignKeysDataAnnotations = Settings.AdditionalForeignKeysDataAnnotations, AdditionalDataAnnotations = x.AdditionalDataAnnotations, Definition = x.Definition }) .ToList(), CreateConstructor = !Settings.UsePropertyInitialisers && ( table.Columns.Any(c => c.Default != string.Empty && !c.Hidden) || table.ReverseNavigationCtor.Any() || Settings.EntityClassesArePartial() ), ColumnsWithDefaults = table.Columns .Where(c => c.Default != string.Empty && !c.Hidden && Settings.IncludeColumnsWithDefaults) .OrderBy(x => x.Ordinal) .Select(x => new PocoColumnsWithDefaultsModel { NameHumanCase = x.NameHumanCase, Default = x.Default }) .ToList(), ReverseNavigationCtor = table.ReverseNavigationCtor, EntityClassesArePartial = Settings.EntityClassesArePartial() }; var co = new CodeOutput(table.DbName, filename, null, _globalUsings); co.AddUsings(_template.PocoUsings(data)); co.AddCode(Template.Transform(_template.Poco(), data)); return(co); }
public override List <string> PocoUsings(PocoModel data) { return(CacheList(TemplateFileBasedConstants.Text.PocoUsings)); }
public abstract List <string> PocoUsings(PocoModel data);
public override List <string> PocoUsings(PocoModel data) { var file = Path.Combine(Settings.TemplateFolder, "PocoUsings.txt"); return(File.ReadLines(file).ToList()); }
public override List <string> PocoUsings(PocoModel data) { return(CacheList("PocoUsings.txt")); }