Skip to content

Instantly share code, notes, and snippets.

@genuinelucifer
Created May 14, 2015 03:34
Show Gist options
  • Save genuinelucifer/08891fb6931cd63288e0 to your computer and use it in GitHub Desktop.
Save genuinelucifer/08891fb6931cd63288e0 to your computer and use it in GitHub Desktop.
compilable code when nesting more than one anonymous type! :)
diff --git a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs b/src/Generat
index ef0a242..1baed7a 100644
--- a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs
+++ b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs
@@ -34,11 +34,27 @@ public static class Helpers
"void", "partial", "yield", "where"
};
+ private static int numSafeIden = 0;
public static string SafeIdentifier(string id)
{
if (id.All(char.IsLetterOrDigit))
return Keywords.Contains(id) ? "@" + id : id;
- return new string(id.Select(c => char.IsLetterOrDigit(c) ? c : '_')
+
+ id = new string(id.Select(c => char.IsLetterOrDigit(c) ? c : '_').T
+
+ if (id.Replace("_", "") == string.Empty)
+ {
+ id = string.Empty;
+ ++numSafeIden;
+ for (var i = 0; i < numSafeIden; ++i)
+ {
+ id += '_';
+ }
+ }
+
+ return id;
+
+ // return new string(id.Select(c => char.IsLetterOrDigit(c) ? c : '_
}
public const string InstanceField = "__instance";
diff --git a/tests/Basic/Basic.h b/tests/Basic/Basic.h
index 488dd2c..de99001 100644
--- a/tests/Basic/Basic.h
+++ b/tests/Basic/Basic.h
@@ -647,6 +647,24 @@ public:
{
};
};
+ struct
+ {
+ struct
+ {
+ };
+ };
+ struct
+ {
+ struct
+ {
+ };
+ };
+ struct
+ {
+ struct
+ {
+ };
+ };
union as_types
{
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment