diff --git a/src/ZoneCodeGenerator/Generating/CodeTemplate.cs b/src/ZoneCodeGenerator/Generating/CodeTemplate.cs index 2e5fd97f..eeed1884 100644 --- a/src/ZoneCodeGenerator/Generating/CodeTemplate.cs +++ b/src/ZoneCodeGenerator/Generating/CodeTemplate.cs @@ -1,5 +1,6 @@ using System.IO; using Antlr4.StringTemplate; +using ZoneCodeGenerator.Domain; namespace ZoneCodeGenerator.Generating { @@ -17,6 +18,7 @@ namespace ZoneCodeGenerator.Generating { this.templateGroup = templateGroup; templateGroup.RegisterRenderer(typeof(string), new StringRenderer()); + templateGroup.RegisterRenderer(typeof(DataType), new DataTypeAttributeRenderer()); } public static CodeTemplate FromResources(string fileName) diff --git a/src/ZoneCodeGenerator/Generating/DataTypeAttributeRenderer.cs b/src/ZoneCodeGenerator/Generating/DataTypeAttributeRenderer.cs new file mode 100644 index 00000000..3feb739e --- /dev/null +++ b/src/ZoneCodeGenerator/Generating/DataTypeAttributeRenderer.cs @@ -0,0 +1,29 @@ +using System.Globalization; +using Antlr4.StringTemplate; +using ZoneCodeGenerator.Domain; + +namespace ZoneCodeGenerator.Generating +{ + class DataTypeAttributeRenderer : IAttributeRenderer + { + public string ToString(object obj, string formatString, CultureInfo culture) + { + if (formatString == null) + return obj.ToString(); + + if (!(obj is DataType dataType)) + { + return obj.ToString(); + } + + switch (formatString) + { + case "safe_name": + return dataType.Name.Replace(" ", "_"); + + default: + return obj.ToString(); + } + } + } +} \ No newline at end of file