Add polyfills for C# 15 union types (UnionAttribute and IUnion)#140
Open
AndiJingzhiTse wants to merge 1 commit into
Open
Add polyfills for C# 15 union types (UnionAttribute and IUnion)#140AndiJingzhiTse wants to merge 1 commit into
AndiJingzhiTse wants to merge 1 commit into
Conversation
Adds source-only polyfills for the UnionAttribute and IUnion interface from System.Runtime.CompilerServices, enabling C# 15 union type features on downlevel targets before .NET 11 ships these types in the BCL. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
73fd312 to
d27001b
Compare
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
Closes #139
This PR adds source-only polyfills for the two types required by the C# 15 union types feature, enabling their use on downlevel targets before .NET 11 ships these types in the BCL:
[Union](System.Runtime.CompilerServices.UnionAttribute) — attribute recognized by the C# 15 compiler to identify a type as a union typeIUnion(System.Runtime.CompilerServices.IUnion) — interface that union types implement, providing access to the underlying value viaobject? Value { get; }Both are placed in the main
EmbeddedResources/folder (language support polyfills, enabled by default) and follow the existing conventions:// <auto-generated/>header,internalaccessibility (switchable topublicviaPolySharpUsePublicAccessibilityForGeneratedTypes), and[ExcludeFromCodeCoverage]on the attribute class.References
Test plan
TestUnionclass intests/PolySharp.Tests/LanguageFeatures.csthat applies[Union]and implementsIUnion, exercising both new polyfillsdotnet build— 0 warnings, 0 errorsnet472,net48,net481,netstandard2.0,netstandard2.1,net8.0,net9.0)🤖 Generated with Claude Code