Browse Source

Generate valid C# when a field with an anon type starts with '$'

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/1224/head
Dimitar Dobrev 7 years ago
parent
commit
fce2841a21
  1. 4
      src/Generator/Generators/CSharp/CSharpSources.cs
  2. 2
      src/Generator/Passes/RenamePass.cs
  3. 3
      tests/CSharp/AnonTypes.h

4
src/Generator/Generators/CSharp/CSharpSources.cs

@ -64,7 +64,9 @@ namespace CppSharp.Generators.CSharp @@ -64,7 +64,9 @@ namespace CppSharp.Generators.CSharp
if (id.All(char.IsLetterOrDigit))
return ReservedKeywords.Contains(id) ? "@" + id : id;
return new string(id.Select(c => char.IsLetterOrDigit(c) ? c : '_').ToArray());
return new string((from c in id
where c != '$'
select char.IsLetterOrDigit(c) ? c : '_').ToArray());
}
#endregion

2
src/Generator/Passes/RenamePass.cs

@ -363,7 +363,7 @@ namespace CppSharp.Passes @@ -363,7 +363,7 @@ namespace CppSharp.Passes
var sb = new StringBuilder(decl.Name);
// check if it's been renamed to avoid a keyword
if (sb[0] == '@')
if (sb[0] == '@' || sb[0] == '$')
sb.Remove(0, 1);
RemoveUnderscores(sb);

3
tests/CSharp/AnonTypes.h

@ -147,6 +147,9 @@ extern "C" { @@ -147,6 +147,9 @@ extern "C" {
example_lib_kref_com_plangrid_example_Request_Response_ErrorResponse(*ErrorResponse)(example_lib_kref_kotlin_Error error);
example_lib_kref_kotlin_Error(*get_error)(example_lib_kref_com_plangrid_example_Request_Response_ErrorResponse thiz);
} ErrorResponse;
struct {
int i;
} $serializer;
} Response;
} Request;
} example;

Loading…
Cancel
Save