-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Refresh union language reference for .NET 11 preview 5 #54198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
69cbaf4
1d6f235
12af319
3788e65
f3ba9c3
6541a84
1aa0a5e
8c15c91
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,36 +1,34 @@ | ||
| // Uncomment when union member providers are available in the compiler: | ||
|
|
||
| // <MemberProvider> | ||
| // [System.Runtime.CompilerServices.Union] | ||
| // public record class Outcome<T> : Outcome<T>.IUnionMembers | ||
| // { | ||
| // private readonly object? _value; | ||
| // | ||
| // private Outcome(object? value) => _value = value; | ||
| // | ||
| // public interface IUnionMembers | ||
| // { | ||
| // static Outcome<T> Create(T? value) => new(value); | ||
| // static Outcome<T> Create(Exception? value) => new(value); | ||
| // object? Value { get; } | ||
| // } | ||
| // | ||
| // object? IUnionMembers.Value => _value; | ||
| // } | ||
| [System.Runtime.CompilerServices.Union] | ||
| public record class Outcome<T> : Outcome<T>.IUnionMembers | ||
| { | ||
| private readonly object? _value; | ||
|
|
||
| private Outcome(object? value) => _value = value; | ||
|
|
||
| public interface IUnionMembers | ||
| { | ||
| static Outcome<T> Create(T? value) => new(value); | ||
| static Outcome<T> Create(Exception? value) => new(value); | ||
| object? Value { get; } | ||
| } | ||
|
|
||
| object? IUnionMembers.Value => _value; | ||
| } | ||
| // </MemberProvider> | ||
|
|
||
| // <MemberProviderExample> | ||
| // public static class MemberProviderScenario | ||
| // { | ||
| // public static void Run() | ||
| // { | ||
| // Outcome<string> ok = "success"; | ||
| // var msg = ok switch | ||
| // { | ||
| // string s => $"OK: {s}", | ||
| // Exception e => $"Error: {e.Message}", | ||
| // }; | ||
| // Console.WriteLine(msg); | ||
| // } | ||
| // } | ||
| public static class MemberProviderScenario | ||
| { | ||
| public static void Run() | ||
| { | ||
| Outcome<string> ok = "success"; | ||
|
Check failure on line 25 in docs/csharp/language-reference/builtin-types/snippets/unions/MemberProvider.cs
|
||
| var msg = ok switch | ||
| { | ||
| string s => $"OK: {s}", | ||
|
Check failure on line 28 in docs/csharp/language-reference/builtin-types/snippets/unions/MemberProvider.cs
|
||
| Exception e => $"Error: {e.Message}", | ||
|
Check failure on line 29 in docs/csharp/language-reference/builtin-types/snippets/unions/MemberProvider.cs
|
||
| }; | ||
| Console.WriteLine(msg); | ||
| } | ||
| } | ||
| // </MemberProviderExample> | ||
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.