diff --git a/.gitignore b/.gitignore
index 10e12b3..a9f796b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,6 +5,7 @@
# dotenv files
.env
+*.lscache
# User-specific files
*.rsuser
diff --git a/src/CarpaNet.SourceGen/CarpaNet.SourceGen.csproj b/src/CarpaNet.SourceGen/CarpaNet.SourceGen.csproj
index 857b26a..fb9a026 100644
--- a/src/CarpaNet.SourceGen/CarpaNet.SourceGen.csproj
+++ b/src/CarpaNet.SourceGen/CarpaNet.SourceGen.csproj
@@ -11,6 +11,10 @@
false
+
+
+
+
diff --git a/src/CarpaNet.SourceGen/Generation/JsonContextGenerator.cs b/src/CarpaNet.SourceGen/Generation/JsonContextGenerator.cs
index c3b4a98..d1509b3 100644
--- a/src/CarpaNet.SourceGen/Generation/JsonContextGenerator.cs
+++ b/src/CarpaNet.SourceGen/Generation/JsonContextGenerator.cs
@@ -799,7 +799,7 @@ private static void GenerateListTypeFactory(
dispatchLines.Add($"if (type == typeof({globalList})) return Create_BuiltIn_{safeName}_TypeInfo(options);");
}
- private static string ToBuiltInSuffix(string typeName)
+ internal static string ToBuiltInSuffix(string typeName)
{
return typeName switch
{
@@ -809,7 +809,7 @@ private static string ToBuiltInSuffix(string typeName)
"int" => "Int32",
"byte[]" => "ByteArray",
"object" => "Object",
- _ => typeName.Replace(".", "_").Replace("@", "")
+ _ => typeName.Replace(".", "_").Replace("@", "").Replace("<", "_").Replace(">", "_")
};
}
}
diff --git a/tests/CarpaNet.UnitTests/Generation/JsonContextGeneratorTests.cs b/tests/CarpaNet.UnitTests/Generation/JsonContextGeneratorTests.cs
new file mode 100644
index 0000000..5ebd401
--- /dev/null
+++ b/tests/CarpaNet.UnitTests/Generation/JsonContextGeneratorTests.cs
@@ -0,0 +1,33 @@
+using CarpaNet.Generation;
+
+using Xunit;
+
+namespace CarpaNet.UnitTests.Generation;
+
+public class JsonContextGeneratorTests
+{
+ [Theory]
+ [InlineData("string", "String")]
+ [InlineData("long", "Int64")]
+ [InlineData("bool", "Boolean")]
+ [InlineData("int", "Int32")]
+ [InlineData("byte[]", "ByteArray")]
+ [InlineData("object", "Object")]
+ [InlineData("System.DateTimeOffset", "System_DateTimeOffset")]
+ [InlineData("System.Collections.Generic.List", "System_Collections_Generic_List_string_")]
+ public void ToBuiltInSuffix_ProducesValidIdentifier(string typeName, string expected)
+ {
+ var result = JsonContextGenerator.ToBuiltInSuffix(typeName);
+ Assert.Equal(expected, result);
+ }
+
+ [Fact]
+ public void ToBuiltInSuffix_NestedGenericType_SanitizesAngleBrackets()
+ {
+ var result = JsonContextGenerator.ToBuiltInSuffix("System.Collections.Generic.List");
+
+ Assert.DoesNotContain("<", result);
+ Assert.DoesNotContain(">", result);
+ Assert.Equal("System_Collections_Generic_List_string_", result);
+ }
+}