mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-20 16:15:43 +00:00
ZoneCodeGenerator: Add renderer for DataType to be able to safely display typenames without spaces
This commit is contained in:
parent
377dc5c99b
commit
032eb997ca
@ -1,5 +1,6 @@
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using Antlr4.StringTemplate;
|
using Antlr4.StringTemplate;
|
||||||
|
using ZoneCodeGenerator.Domain;
|
||||||
|
|
||||||
namespace ZoneCodeGenerator.Generating
|
namespace ZoneCodeGenerator.Generating
|
||||||
{
|
{
|
||||||
@ -17,6 +18,7 @@ namespace ZoneCodeGenerator.Generating
|
|||||||
{
|
{
|
||||||
this.templateGroup = templateGroup;
|
this.templateGroup = templateGroup;
|
||||||
templateGroup.RegisterRenderer(typeof(string), new StringRenderer());
|
templateGroup.RegisterRenderer(typeof(string), new StringRenderer());
|
||||||
|
templateGroup.RegisterRenderer(typeof(DataType), new DataTypeAttributeRenderer());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CodeTemplate FromResources(string fileName)
|
public static CodeTemplate FromResources(string fileName)
|
||||||
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user