Conversation
…ucts) Resolve SerializationKind per parameter at classification time by checking IUtf8SpanFormattable on the type symbol. Bool emits zero-alloc UTF-8 literals, other non-formattable types fall back to WriteString(ToString()). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
All Models/ types and SerializationKind are generator-internal and should not be part of the public API surface. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
bool,enum, or custom struct parameters in[LogMessage]methods. The generator now resolvesSerializationKindper parameter at classification time by checkingIUtf8SpanFormattableon the type symbol, emitting the correct write path for each type.Reason for Change
The source generator unconditionally emitted
writer.WriteFormatted(value)for all non-string parameters, which has a generic constraint ofIUtf8SpanFormattable. Types likebool, enums, and custom structs do not implement this interface, causing CS0315 in generated code.Impact
boolparameters now emit zero-allocation UTF-8 literals:writer.Write(value ? "true"u8 : "false"u8)enumand custom struct parameters fall back towriter.WriteString(value.ToString())IUtf8SpanFormattable(int,double,decimal, etc.) are unchanged.ToString("spec")instead of failingParameterInfo,LogMethodInfo,TemplatePart, etc.) madeinternal— they were incorrectlypublicMigration Steps
None required. This is a bug fix — previously broken code will now compile.
Performance Considerations
bool: improved — zero allocation via UTF-8 literals instead ofToString()enum/custom structs:ToString()allocation is unavoidable withoutIUtf8SpanFormattableIUtf8SpanFormattabletypes: no changeSecurity Considerations
None.
Breaking Changes
publicbut not usable outside the analyzer — making theminternalmatches their intended usage.ParameterInfogained aSerializationKindproperty (additive).