Skip to content

Commit 7a0ecc8

Browse files
committed
Revert "Remove CodeDom"
1 parent 5d6c506 commit 7a0ecc8

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

src/Entitas.CodeGeneration.Plugins/src/CodeGeneratorExtensions.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Linq;
1+
using System.CodeDom.Compiler;
2+
using System.Linq;
23
using DesperateDevs.Extensions;
34
using Entitas.CodeGeneration.Attributes;
45

@@ -8,13 +9,17 @@ public static class CodeGeneratorExtensions
89
{
910
public const string LOOKUP = "ComponentsLookup";
1011

12+
const string KEYWORD_PREFIX = "@";
13+
1114
public static bool ignoreNamespaces;
1215

16+
static readonly CodeDomProvider provider = CodeDomProvider.CreateProvider("C#");
17+
1318
public static string ComponentName(this ComponentData data) =>
1419
data.GetTypeName().ToComponentName(ignoreNamespaces);
1520

1621
public static string ComponentNameValidLowerFirst(this ComponentData data) =>
17-
ComponentName(data).ToLowerFirst();
22+
ComponentName(data).ToLowerFirst().AddPrefixIfIsKeyword();
1823

1924
public static string ComponentNameWithContext(this ComponentData data, string contextName) =>
2025
contextName + data.ComponentName();
@@ -97,5 +102,13 @@ public static string GetMethodParameters(this MemberData[] memberData, bool newP
97102

98103
public static string GetMethodArgs(MemberData[] memberData, bool newPrefix) => string.Join(", ", memberData
99104
.Select(info => newPrefix ? $"new{info.name.ToUpperFirst()}" : info.name));
105+
106+
public static string AddPrefixIfIsKeyword(this string name)
107+
{
108+
if (!provider.IsValidIdentifier(name))
109+
name = KEYWORD_PREFIX + name;
110+
111+
return name;
112+
}
100113
}
101114
}

src/Entitas.CodeGeneration.Plugins/src/Entitas.CodeGeneration.Plugins.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<PackageReference Include="DesperateDevs.Serialization" Version="2.0.0" />
99
<PackageReference Include="Jenny" Version="1.0.0" />
1010
<PackageReference Include="Jenny.Generator" Version="1.0.0" />
11+
<PackageReference Include="System.CodeDom" Version="6.0.0" />
1112
</ItemGroup>
1213

1314
<ItemGroup>

src/Entitas.CodeGeneration.Plugins/src/EntityIndex/CodeGenerators/EntityIndexGenerator.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ string generateMethods(EntityIndexData data, string contextName) => ADD_INDEX_TE
134134
.Replace("${MemberName}", data.GetMemberName())
135135
.Replace("${componentName}", data.GetComponentType()
136136
.ToComponentName(_ignoreNamespacesConfig.ignoreNamespaces)
137-
.ToLowerFirst());
137+
.ToLowerFirst()
138+
.AddPrefixIfIsKeyword());
138139

139140
string generateGetMethods(EntityIndexData data) => string.Join("\n\n", data.GetContextNames()
140141
.Aggregate(new List<string>(), (getMethods, contextName) =>

0 commit comments

Comments
 (0)