Skip to content

Commit fce2841

Browse files
committed
Generate valid C# when a field with an anon type starts with '$'
Signed-off-by: Dimitar Dobrev <[email protected]>
1 parent ce3d5d5 commit fce2841

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

src/Generator/Generators/CSharp/CSharpSources.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ public static string SafeIdentifier(string id)
6464
if (id.All(char.IsLetterOrDigit))
6565
return ReservedKeywords.Contains(id) ? "@" + id : id;
6666

67-
return new string(id.Select(c => char.IsLetterOrDigit(c) ? c : '_').ToArray());
67+
return new string((from c in id
68+
where c != '$'
69+
select char.IsLetterOrDigit(c) ? c : '_').ToArray());
6870
}
6971

7072
#endregion

src/Generator/Passes/RenamePass.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ public static string ConvertCaseString(Declaration decl, RenameCasePattern patte
363363

364364
var sb = new StringBuilder(decl.Name);
365365
// check if it's been renamed to avoid a keyword
366-
if (sb[0] == '@')
366+
if (sb[0] == '@' || sb[0] == '$')
367367
sb.Remove(0, 1);
368368

369369
RemoveUnderscores(sb);

tests/CSharp/AnonTypes.h

+3
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ extern "C" {
147147
example_lib_kref_com_plangrid_example_Request_Response_ErrorResponse(*ErrorResponse)(example_lib_kref_kotlin_Error error);
148148
example_lib_kref_kotlin_Error(*get_error)(example_lib_kref_com_plangrid_example_Request_Response_ErrorResponse thiz);
149149
} ErrorResponse;
150+
struct {
151+
int i;
152+
} $serializer;
150153
} Response;
151154
} Request;
152155
} example;

0 commit comments

Comments
 (0)