1.5 KiB
1.5 KiB
AyCode.Core.Serializers.SourceGenerator
Roslyn incremental source generator that produces optimized IGeneratedBinaryWriter and IGeneratedBinaryReader implementations for types marked with [AcBinarySerializable]. Eliminates runtime reflection on serialization hot paths.
Targets netstandard2.0 (required for Roslyn analyzers/generators).
Key Files
AcBinarySourceGenerator.cs— Single-fileIIncrementalGenerator(~2100 lines). Generates:{ClassName}_GeneratedWriter— Per-type writer withScanObject()+WriteProperties()methods. Handles primitives, strings (with interning), collections, dictionaries, complex nested types, and polymorphic objects.{ClassName}_GeneratedReader— Per-type reader withReadProperties()method.ModuleInitializer— Auto-registers all generated writers/readers at startup.- Circular reference detection with
ACBIN001diagnostic warning.
Feature Flags
The [AcBinarySerializable] attribute supports per-type feature control:
enableMetadata— Property hash metadata for cross-type deserializationenableIdTracking— IId-based reference trackingenableRefHandling— General reference trackingenableInternString— String interning/deduplication
Disabled features eliminate corresponding code blocks from generated output (zero dead code).
Dependencies
| Dependency | Purpose |
|---|---|
Microsoft.CodeAnalysis.CSharp |
Roslyn syntax/semantic APIs |
Microsoft.CodeAnalysis.Analyzers |
Analyzer best practices |