-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Description
Many of the diagnostics issued by the JSON source generator are also applicable to the reflection-based serializer. For example, a type cannot contain multiple [JsonConstructor]
applications. When the source generator is used, it logs a compile error when a type violates this expectation. A runtime exception is thrown in the reflection-based serializer instead.
Rather than having different behavior, we could package these diagnostic examinations into an analyzer that could be shared between the source generator and the reflection serializer, potentially giving the reflection serializer less validation work to do at runtime. We'd have to consider where this analyzer would live. There are a couple options
- it could ship in the same assembly as the source generator
(becoming the first analyzer to be shipped in the dotnet/runtime repo) - it could ship with the rest of the analyzers in https://github.com/dotnet/roslyn-analyzers
The source generator would be dependent on the analyzer, so we'd need to ship the analyzer in a manner that guarantees its visibility to the source generator.
cc @dotnet/area-system-text-json @jeffhandley