You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add prototype support for C# union types, closed enums, and closed hierarchies
This commit introduces experimental support for three upcoming C# language features:
1. **C# Union Types** - Maps to existing IUnionTypeShape abstraction via new
UnionKind enum (ClassHierarchy, FSharpUnion, CSharpUnion). Uses
DelegateMarshaler<TSource, TTarget> for marshal/unmarshal between
unrelated case types and union types. Detection via [Union] attribute +
IUnion interface by metadata name.
2. **Closed Enums** - Adds IsClosed property to IEnumTypeShape, detected via
[Closed] attribute by metadata name. Supported in both reflection and
source generator providers.
3. **Closed Hierarchies** - [ClosedSubtype] attributes are always honored for
union detection. Assembly scanning fallback requires InferDerivedTypes
opt-in via TypeShapeAttribute property.
Key design decisions:
- No breaking changes to public interfaces (InternalImplementationsOnly)
- Detection by metadata name avoids shipping BCL-conflicting types
- IUnionCaseShape has no TUnionCase:TUnion constraint at interface level,
enabling C# union support without new abstractions
- Source gen uses string UnionKindName to avoid accessibility issues
- Example JSON serializer extended with structural matching for C# unions
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
0 commit comments