Skip to content

Commit 042203b

Browse files
TheSmallPixelclaude
andcommitted
refactor: migrate Newtonsoft.Json to System.Text.Json and bump Roslyn
- Removed Newtonsoft.Json dependency entirely - Serialization now uses System.Text.Json with a custom LowercaseNamingPolicy (same output format as before) - Microsoft.CodeAnalysis.CSharp bumped 4.5.0 → 4.12.0 - Microsoft.CodeAnalysis.Analyzers bumped 3.3.3 → 3.11.0 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 7a3e2e3 commit 042203b

2 files changed

Lines changed: 12 additions & 25 deletions

File tree

tools/CodeAnalysisTool/CodeAnalysisTool.csproj

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,7 @@
55
</PropertyGroup>
66

77
<ItemGroup>
8-
<!-- Roslyn compiler APIs for code analysis -->
9-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.5.0" />
10-
<!-- Analyzers for Roslyn (optional but often recommended).
11-
Set PrivateAssets to 'all' so they don't flow to consumers of your tool. -->
12-
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.3" PrivateAssets="all" />
13-
<!-- Newtonsoft.Json to serialize your final D3 graph, if you're using that -->
14-
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
8+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.12.0" />
9+
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0" PrivateAssets="all" />
1510
</ItemGroup>
1611
</Project>

tools/CodeAnalysisTool/Program.cs

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
using System.Reflection;
77
using Microsoft.CodeAnalysis;
88
using Microsoft.CodeAnalysis.CSharp;
9-
using Newtonsoft.Json;
10-
using Newtonsoft.Json.Serialization;
9+
using System.Text.Json;
10+
using System.Text.Json.Serialization;
1111

1212
namespace CodeAnalysisTool
1313
{
@@ -129,19 +129,14 @@ static void Main(string[] args)
129129
{
130130
Directory.CreateDirectory(docsPath);
131131
var outputFile = Path.Combine(docsPath, "graph.json");
132-
133-
// Create settings specifying our custom naming strategy
134-
var settings = new JsonSerializerSettings
132+
133+
var options = new JsonSerializerOptions
135134
{
136-
// Use a DefaultContractResolver with our LowercaseNamingStrategy
137-
ContractResolver = new DefaultContractResolver
138-
{
139-
NamingStrategy = new LowercaseNamingStrategy()
140-
},
141-
Formatting = Formatting.Indented // for pretty printing
135+
PropertyNamingPolicy = new LowercaseNamingPolicy(),
136+
WriteIndented = true
142137
};
143-
144-
File.WriteAllText(outputFile, JsonConvert.SerializeObject(graph, settings));
138+
139+
File.WriteAllText(outputFile, JsonSerializer.Serialize(graph, options));
145140
Console.WriteLine($"Generated: {outputFile}");
146141

147142
// Print some statistics
@@ -243,11 +238,8 @@ private static List<MetadataReference> GetMetadataReferences()
243238
}
244239
}
245240

246-
public class LowercaseNamingStrategy : NamingStrategy
241+
public class LowercaseNamingPolicy : JsonNamingPolicy
247242
{
248-
protected override string ResolvePropertyName(string name)
249-
{
250-
return name.ToLowerInvariant();
251-
}
243+
public override string ConvertName(string name) => name.ToLowerInvariant();
252244
}
253245
}

0 commit comments

Comments
 (0)