From 23339e53058d8b4f2f2374a770cea502986bb74a Mon Sep 17 00:00:00 2001 From: Andrew McClement Date: Thu, 13 Mar 2025 13:45:44 +0000 Subject: [PATCH 1/3] Update the codegen to enable nullability analysis for OneOf and OneOfBase. --- Generator/Program.cs | 42 +++++++++++++++++++++++------------------- OneOf/Functions.cs | 3 +++ OneOf/IOneOf.cs | 2 +- OneOf/OneOf.csproj | 2 +- 4 files changed, 28 insertions(+), 21 deletions(-) diff --git a/Generator/Program.cs b/Generator/Program.cs index 4f04e2b..e90101f 100644 --- a/Generator/Program.cs +++ b/Generator/Program.cs @@ -36,8 +36,11 @@ string GetContent(bool isStruct, int i) { var genericArgs = Range(0, i).Select(e => $"T{e}").ToList(); var genericArg = genericArgs.Joined(", "); var sb = new StringBuilder(); + const string invalidIndexException = "throw InvalidIndexException(_index)"; - sb.Append(@$"using System; + sb.Append(@$"#nullable enable +using System; +using System.Diagnostics.CodeAnalysis; using static OneOf.Functions; namespace OneOf @@ -45,11 +48,11 @@ namespace OneOf public {IfStruct("readonly struct", "class")} {className}<{genericArg}> : IOneOf {{ {RangeJoined(@" - ", j => $"readonly T{j} _value{j};")} + ", j => $"readonly T{j} _value{j}{IfStruct("", " = default!")};")} readonly int _index; {IfStruct( // constructor - $@"OneOf(int index, {RangeJoined(", ", j => $"T{j} value{j} = default")}) + $@"OneOf(int index, {RangeJoined(", ", j => $"T{j} value{j} = default!")}) {{ _index = index; {RangeJoined(@" @@ -62,17 +65,17 @@ namespace OneOf {{ {RangeJoined($@" ", j => $"case {j}: _value{j} = input.AsT{j}; break;")} - default: throw new InvalidOperationException(); + default: {invalidIndexException}; }} }}" )} - public object Value => + public object? Value => _index switch {{ {RangeJoined(@" ", j => $"{j} => _value{j},")} - _ => throw new InvalidOperationException() + _ => {invalidIndexException} }}; public int Index => _index; @@ -97,7 +100,7 @@ public void Switch({RangeJoined(", ", e => $"Action f{e}")}) f{j}(_value{j}); return; }}")} - throw new InvalidOperationException(); + {invalidIndexException}; }} public TResult Match({RangeJoined(", ", e => $"Func f{e}")}) @@ -107,7 +110,7 @@ public TResult Match({RangeJoined(", ", e => $"Func f{e} {{ return f{j}(_value{j}); }}")} - throw new InvalidOperationException(); + {invalidIndexException}; }} {IfStruct(genericArgs.Joined(@" @@ -132,7 +135,7 @@ public TResult Match({RangeJoined(", ", e => $"Func f{e} x == bindToType ? $"{k} => mapFunc(As{x})," : $"{k} => As{x},")} - _ => throw new InvalidOperationException() + _ => {invalidIndexException} }}; }}"; }))} @@ -145,17 +148,21 @@ public TResult Match({RangeJoined(", ", e => $"Func f{e} var genericArgWithSkip = Range(0, i).ExceptSingle(j).Joined(", ", e => $"T{e}"); var remainderType = i == 2 ? genericArgWithSkip : $"OneOf<{genericArgWithSkip}>"; return $@" - public bool TryPickT{j}(out T{j} value, out {remainderType} remainder) +#if NET + public bool TryPickT{j}([NotNullWhen(true)] out T{j}? value, {(i == 2 ? "[NotNullWhen(false)] " : "")}out {remainderType}{(i == 2 ? "?" : "")} remainder) +#else + public bool TryPickT{j}(out T{j}? value, out {remainderType}{(i == 2 ? "?" : "")} remainder) +#endif {{ value = IsT{j} ? AsT{j} : default; remainder = _index switch {{ {RangeJoined(@" ", k => - k == j ? - $"{k} => default," : - $"{k} => AsT{k},")} - _ => throw new InvalidOperationException() + k == j ? + $"{k} => default," : + $"{k} => AsT{k},")} + _ => {invalidIndexException} }}; return this.IsT{j}; }}"; @@ -173,7 +180,7 @@ bool Equals({className}<{genericArg}> other) => _ => false }}; - public override bool Equals(object obj) + public override bool Equals(object? obj) {{ if (ReferenceEquals(null, obj)) {{ @@ -216,16 +223,13 @@ public override int GetHashCode() return sb.ToString(); } -public static class Extensions { +internal static class Extensions { public static string Joined(this IEnumerable source, string delimiter, Func? selector = null) { - if (source == null) { return ""; } if (selector == null) { return string.Join(delimiter, source); } return string.Join(delimiter, source.Select(selector)); } public static string Joined(this IEnumerable source, string delimiter, Func selector) { - if (source == null) { return ""; } return string.Join(delimiter, source.Select(selector)); } public static IEnumerable ExceptSingle(this IEnumerable source, T single) => source.Except(Repeat(single, 1)); - public static void AppendLineTo(this string? s, StringBuilder sb) => sb.AppendLine(s); } \ No newline at end of file diff --git a/OneOf/Functions.cs b/OneOf/Functions.cs index 89cfa67..f57248c 100644 --- a/OneOf/Functions.cs +++ b/OneOf/Functions.cs @@ -7,5 +7,8 @@ internal static string FormatValue(object @this, object @base, T value) => ReferenceEquals(@this, value) ? @base.ToString() : $"{typeof(T).FullName}: {value?.ToString()}"; + + internal static InvalidOperationException InvalidIndexException(int index) + => new InvalidOperationException($"Unexpected index {index}, which indicates a problem in the OneOf codegen."); } } diff --git a/OneOf/IOneOf.cs b/OneOf/IOneOf.cs index f026e1a..117d7b6 100644 --- a/OneOf/IOneOf.cs +++ b/OneOf/IOneOf.cs @@ -2,7 +2,7 @@ namespace OneOf { public interface IOneOf { - object Value { get ; } + object? Value { get ; } int Index { get; } } } \ No newline at end of file diff --git a/OneOf/OneOf.csproj b/OneOf/OneOf.csproj index 4bd8b36..d8c3fd5 100644 --- a/OneOf/OneOf.csproj +++ b/OneOf/OneOf.csproj @@ -1,7 +1,7 @@  - net35;net45;netstandard1.3;netstandard2.0 + net35;net45;netstandard1.3;netstandard2.0;net8.0 Harry McIntyre OneOf - Easy Discriminated Unions for c# Harry McIntyre From 13a4e85ccd33a47c1e4f0285308d5a65243069e1 Mon Sep 17 00:00:00 2001 From: Andrew McClement Date: Thu, 13 Mar 2025 13:46:10 +0000 Subject: [PATCH 2/3] Regen code. --- OneOf.Extended/Functions.cs | 11 - OneOf.Extended/OneOf.Extended.csproj | 6 + OneOf.Extended/OneOfBaseT10.generated.cs | 124 ++++++--- OneOf.Extended/OneOfBaseT11.generated.cs | 134 ++++++--- OneOf.Extended/OneOfBaseT12.generated.cs | 144 +++++++--- OneOf.Extended/OneOfBaseT13.generated.cs | 154 +++++++---- OneOf.Extended/OneOfBaseT14.generated.cs | 164 +++++++---- OneOf.Extended/OneOfBaseT15.generated.cs | 174 ++++++++---- OneOf.Extended/OneOfBaseT16.generated.cs | 184 +++++++++---- OneOf.Extended/OneOfBaseT17.generated.cs | 194 +++++++++---- OneOf.Extended/OneOfBaseT18.generated.cs | 204 +++++++++----- OneOf.Extended/OneOfBaseT19.generated.cs | 214 ++++++++++----- OneOf.Extended/OneOfBaseT20.generated.cs | 224 ++++++++++----- OneOf.Extended/OneOfBaseT21.generated.cs | 234 +++++++++++----- OneOf.Extended/OneOfBaseT22.generated.cs | 244 ++++++++++++----- OneOf.Extended/OneOfBaseT23.generated.cs | 254 +++++++++++------ OneOf.Extended/OneOfBaseT24.generated.cs | 264 ++++++++++++------ OneOf.Extended/OneOfBaseT25.generated.cs | 274 +++++++++++++------ OneOf.Extended/OneOfBaseT26.generated.cs | 284 +++++++++++++------ OneOf.Extended/OneOfBaseT27.generated.cs | 294 ++++++++++++++------ OneOf.Extended/OneOfBaseT28.generated.cs | 304 ++++++++++++++------- OneOf.Extended/OneOfBaseT29.generated.cs | 314 ++++++++++++++------- OneOf.Extended/OneOfBaseT30.generated.cs | 324 +++++++++++++++------- OneOf.Extended/OneOfBaseT31.generated.cs | 334 ++++++++++++++++------- OneOf.Extended/OneOfBaseT9.generated.cs | 114 +++++--- OneOf.Extended/OneOfT10.generated.cs | 124 ++++++--- OneOf.Extended/OneOfT11.generated.cs | 134 ++++++--- OneOf.Extended/OneOfT12.generated.cs | 144 +++++++--- OneOf.Extended/OneOfT13.generated.cs | 154 +++++++---- OneOf.Extended/OneOfT14.generated.cs | 164 +++++++---- OneOf.Extended/OneOfT15.generated.cs | 174 ++++++++---- OneOf.Extended/OneOfT16.generated.cs | 184 +++++++++---- OneOf.Extended/OneOfT17.generated.cs | 194 +++++++++---- OneOf.Extended/OneOfT18.generated.cs | 204 +++++++++----- OneOf.Extended/OneOfT19.generated.cs | 214 ++++++++++----- OneOf.Extended/OneOfT20.generated.cs | 224 ++++++++++----- OneOf.Extended/OneOfT21.generated.cs | 234 +++++++++++----- OneOf.Extended/OneOfT22.generated.cs | 244 ++++++++++++----- OneOf.Extended/OneOfT23.generated.cs | 254 +++++++++++------ OneOf.Extended/OneOfT24.generated.cs | 264 ++++++++++++------ OneOf.Extended/OneOfT25.generated.cs | 274 +++++++++++++------ OneOf.Extended/OneOfT26.generated.cs | 284 +++++++++++++------ OneOf.Extended/OneOfT27.generated.cs | 294 ++++++++++++++------ OneOf.Extended/OneOfT28.generated.cs | 304 ++++++++++++++------- OneOf.Extended/OneOfT29.generated.cs | 314 ++++++++++++++------- OneOf.Extended/OneOfT30.generated.cs | 324 +++++++++++++++------- OneOf.Extended/OneOfT31.generated.cs | 334 ++++++++++++++++------- OneOf.Extended/OneOfT9.generated.cs | 114 +++++--- OneOf/OneOfBaseT0.generated.cs | 16 +- OneOf/OneOfBaseT1.generated.cs | 34 ++- OneOf/OneOfBaseT2.generated.cs | 44 ++- OneOf/OneOfBaseT3.generated.cs | 54 ++-- OneOf/OneOfBaseT4.generated.cs | 64 +++-- OneOf/OneOfBaseT5.generated.cs | 74 +++-- OneOf/OneOfBaseT6.generated.cs | 84 ++++-- OneOf/OneOfBaseT7.generated.cs | 94 +++++-- OneOf/OneOfBaseT8.generated.cs | 104 ++++--- OneOf/OneOfT0.generated.cs | 16 +- OneOf/OneOfT1.generated.cs | 34 ++- OneOf/OneOfT2.generated.cs | 44 ++- OneOf/OneOfT3.generated.cs | 54 ++-- OneOf/OneOfT4.generated.cs | 64 +++-- OneOf/OneOfT5.generated.cs | 74 +++-- OneOf/OneOfT6.generated.cs | 84 ++++-- OneOf/OneOfT7.generated.cs | 94 +++++-- OneOf/OneOfT8.generated.cs | 104 ++++--- 66 files changed, 7898 insertions(+), 3559 deletions(-) delete mode 100644 OneOf.Extended/Functions.cs diff --git a/OneOf.Extended/Functions.cs b/OneOf.Extended/Functions.cs deleted file mode 100644 index d756b0b..0000000 --- a/OneOf.Extended/Functions.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; - -namespace OneOf { - internal static class Functions { - internal static string FormatValue(T value) => $"{typeof(T).FullName}: {value?.ToString()}"; - internal static string FormatValue(object @this, object @base, T value) => - ReferenceEquals(@this, value) ? - @base.ToString() : - $"{typeof(T).FullName}: {value?.ToString()}"; - } -} diff --git a/OneOf.Extended/OneOf.Extended.csproj b/OneOf.Extended/OneOf.Extended.csproj index 5dc1f77..af54536 100644 --- a/OneOf.Extended/OneOf.Extended.csproj +++ b/OneOf.Extended/OneOf.Extended.csproj @@ -32,4 +32,10 @@ + + + Functions.cs + + + \ No newline at end of file diff --git a/OneOf.Extended/OneOfBaseT10.generated.cs b/OneOf.Extended/OneOfBaseT10.generated.cs index 3c61780..c897af6 100644 --- a/OneOf.Extended/OneOfBaseT10.generated.cs +++ b/OneOf.Extended/OneOfBaseT10.generated.cs @@ -1,21 +1,23 @@ +#nullable enable using System; +using System.Diagnostics.CodeAnalysis; using static OneOf.Functions; namespace OneOf { public class OneOfBase : IOneOf { - readonly T0 _value0; - readonly T1 _value1; - readonly T2 _value2; - readonly T3 _value3; - readonly T4 _value4; - readonly T5 _value5; - readonly T6 _value6; - readonly T7 _value7; - readonly T8 _value8; - readonly T9 _value9; - readonly T10 _value10; + readonly T0 _value0 = default!; + readonly T1 _value1 = default!; + readonly T2 _value2 = default!; + readonly T3 _value3 = default!; + readonly T4 _value4 = default!; + readonly T5 _value5 = default!; + readonly T6 _value6 = default!; + readonly T7 _value7 = default!; + readonly T8 _value8 = default!; + readonly T9 _value9 = default!; + readonly T10 _value10 = default!; readonly int _index; protected OneOfBase(OneOf input) @@ -34,11 +36,11 @@ protected OneOfBase(OneOf input) case 8: _value8 = input.AsT8; break; case 9: _value9 = input.AsT9; break; case 10: _value10 = input.AsT10; break; - default: throw new InvalidOperationException(); + default: throw InvalidIndexException(_index); } } - public object Value => + public object? Value => _index switch { 0 => _value0, @@ -52,7 +54,7 @@ protected OneOfBase(OneOf input) 8 => _value8, 9 => _value9, 10 => _value10, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; public int Index => _index; @@ -173,7 +175,7 @@ public void Switch(Action f0, Action f1, Action f2, Action f3, A f10(_value10); return; } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } public TResult Match(Func f0, Func f1, Func f2, Func f3, Func f4, Func f5, Func f6, Func f7, Func f8, Func f9, Func f10) @@ -222,14 +224,18 @@ public TResult Match(Func f0, Func f1, Func remainder) +#if NET + public bool TryPickT0([NotNullWhen(true)] out T0? value, out OneOf remainder) +#else + public bool TryPickT0(out T0? value, out OneOf remainder) +#endif { value = IsT0 ? AsT0 : default; remainder = _index switch @@ -245,12 +251,16 @@ public bool TryPickT0(out T0 value, out OneOf AsT8, 9 => AsT9, 10 => AsT10, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT0; } - public bool TryPickT1(out T1 value, out OneOf remainder) +#if NET + public bool TryPickT1([NotNullWhen(true)] out T1? value, out OneOf remainder) +#else + public bool TryPickT1(out T1? value, out OneOf remainder) +#endif { value = IsT1 ? AsT1 : default; remainder = _index switch @@ -266,12 +276,16 @@ public bool TryPickT1(out T1 value, out OneOf AsT8, 9 => AsT9, 10 => AsT10, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT1; } - public bool TryPickT2(out T2 value, out OneOf remainder) +#if NET + public bool TryPickT2([NotNullWhen(true)] out T2? value, out OneOf remainder) +#else + public bool TryPickT2(out T2? value, out OneOf remainder) +#endif { value = IsT2 ? AsT2 : default; remainder = _index switch @@ -287,12 +301,16 @@ public bool TryPickT2(out T2 value, out OneOf AsT8, 9 => AsT9, 10 => AsT10, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT2; } - public bool TryPickT3(out T3 value, out OneOf remainder) +#if NET + public bool TryPickT3([NotNullWhen(true)] out T3? value, out OneOf remainder) +#else + public bool TryPickT3(out T3? value, out OneOf remainder) +#endif { value = IsT3 ? AsT3 : default; remainder = _index switch @@ -308,12 +326,16 @@ public bool TryPickT3(out T3 value, out OneOf AsT8, 9 => AsT9, 10 => AsT10, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT3; } - public bool TryPickT4(out T4 value, out OneOf remainder) +#if NET + public bool TryPickT4([NotNullWhen(true)] out T4? value, out OneOf remainder) +#else + public bool TryPickT4(out T4? value, out OneOf remainder) +#endif { value = IsT4 ? AsT4 : default; remainder = _index switch @@ -329,12 +351,16 @@ public bool TryPickT4(out T4 value, out OneOf AsT8, 9 => AsT9, 10 => AsT10, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT4; } - public bool TryPickT5(out T5 value, out OneOf remainder) +#if NET + public bool TryPickT5([NotNullWhen(true)] out T5? value, out OneOf remainder) +#else + public bool TryPickT5(out T5? value, out OneOf remainder) +#endif { value = IsT5 ? AsT5 : default; remainder = _index switch @@ -350,12 +376,16 @@ public bool TryPickT5(out T5 value, out OneOf AsT8, 9 => AsT9, 10 => AsT10, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT5; } - public bool TryPickT6(out T6 value, out OneOf remainder) +#if NET + public bool TryPickT6([NotNullWhen(true)] out T6? value, out OneOf remainder) +#else + public bool TryPickT6(out T6? value, out OneOf remainder) +#endif { value = IsT6 ? AsT6 : default; remainder = _index switch @@ -371,12 +401,16 @@ public bool TryPickT6(out T6 value, out OneOf AsT8, 9 => AsT9, 10 => AsT10, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT6; } - public bool TryPickT7(out T7 value, out OneOf remainder) +#if NET + public bool TryPickT7([NotNullWhen(true)] out T7? value, out OneOf remainder) +#else + public bool TryPickT7(out T7? value, out OneOf remainder) +#endif { value = IsT7 ? AsT7 : default; remainder = _index switch @@ -392,12 +426,16 @@ public bool TryPickT7(out T7 value, out OneOf AsT8, 9 => AsT9, 10 => AsT10, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT7; } - public bool TryPickT8(out T8 value, out OneOf remainder) +#if NET + public bool TryPickT8([NotNullWhen(true)] out T8? value, out OneOf remainder) +#else + public bool TryPickT8(out T8? value, out OneOf remainder) +#endif { value = IsT8 ? AsT8 : default; remainder = _index switch @@ -413,12 +451,16 @@ public bool TryPickT8(out T8 value, out OneOf default, 9 => AsT9, 10 => AsT10, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT8; } - public bool TryPickT9(out T9 value, out OneOf remainder) +#if NET + public bool TryPickT9([NotNullWhen(true)] out T9? value, out OneOf remainder) +#else + public bool TryPickT9(out T9? value, out OneOf remainder) +#endif { value = IsT9 ? AsT9 : default; remainder = _index switch @@ -434,12 +476,16 @@ public bool TryPickT9(out T9 value, out OneOf AsT8, 9 => default, 10 => AsT10, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT9; } - public bool TryPickT10(out T10 value, out OneOf remainder) +#if NET + public bool TryPickT10([NotNullWhen(true)] out T10? value, out OneOf remainder) +#else + public bool TryPickT10(out T10? value, out OneOf remainder) +#endif { value = IsT10 ? AsT10 : default; remainder = _index switch @@ -455,7 +501,7 @@ public bool TryPickT10(out T10 value, out OneOf AsT8, 9 => AsT9, 10 => default, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT10; } @@ -478,7 +524,7 @@ bool Equals(OneOfBase other) => _ => false }; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/OneOf.Extended/OneOfBaseT11.generated.cs b/OneOf.Extended/OneOfBaseT11.generated.cs index cc72a59..16b54e6 100644 --- a/OneOf.Extended/OneOfBaseT11.generated.cs +++ b/OneOf.Extended/OneOfBaseT11.generated.cs @@ -1,22 +1,24 @@ +#nullable enable using System; +using System.Diagnostics.CodeAnalysis; using static OneOf.Functions; namespace OneOf { public class OneOfBase : IOneOf { - readonly T0 _value0; - readonly T1 _value1; - readonly T2 _value2; - readonly T3 _value3; - readonly T4 _value4; - readonly T5 _value5; - readonly T6 _value6; - readonly T7 _value7; - readonly T8 _value8; - readonly T9 _value9; - readonly T10 _value10; - readonly T11 _value11; + readonly T0 _value0 = default!; + readonly T1 _value1 = default!; + readonly T2 _value2 = default!; + readonly T3 _value3 = default!; + readonly T4 _value4 = default!; + readonly T5 _value5 = default!; + readonly T6 _value6 = default!; + readonly T7 _value7 = default!; + readonly T8 _value8 = default!; + readonly T9 _value9 = default!; + readonly T10 _value10 = default!; + readonly T11 _value11 = default!; readonly int _index; protected OneOfBase(OneOf input) @@ -36,11 +38,11 @@ protected OneOfBase(OneOf inpu case 9: _value9 = input.AsT9; break; case 10: _value10 = input.AsT10; break; case 11: _value11 = input.AsT11; break; - default: throw new InvalidOperationException(); + default: throw InvalidIndexException(_index); } } - public object Value => + public object? Value => _index switch { 0 => _value0, @@ -55,7 +57,7 @@ protected OneOfBase(OneOf inpu 9 => _value9, 10 => _value10, 11 => _value11, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; public int Index => _index; @@ -186,7 +188,7 @@ public void Switch(Action f0, Action f1, Action f2, Action f3, A f11(_value11); return; } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } public TResult Match(Func f0, Func f1, Func f2, Func f3, Func f4, Func f5, Func f6, Func f7, Func f8, Func f9, Func f10, Func f11) @@ -239,14 +241,18 @@ public TResult Match(Func f0, Func f1, Func remainder) +#if NET + public bool TryPickT0([NotNullWhen(true)] out T0? value, out OneOf remainder) +#else + public bool TryPickT0(out T0? value, out OneOf remainder) +#endif { value = IsT0 ? AsT0 : default; remainder = _index switch @@ -263,12 +269,16 @@ public bool TryPickT0(out T0 value, out OneOf AsT9, 10 => AsT10, 11 => AsT11, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT0; } - public bool TryPickT1(out T1 value, out OneOf remainder) +#if NET + public bool TryPickT1([NotNullWhen(true)] out T1? value, out OneOf remainder) +#else + public bool TryPickT1(out T1? value, out OneOf remainder) +#endif { value = IsT1 ? AsT1 : default; remainder = _index switch @@ -285,12 +295,16 @@ public bool TryPickT1(out T1 value, out OneOf AsT9, 10 => AsT10, 11 => AsT11, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT1; } - public bool TryPickT2(out T2 value, out OneOf remainder) +#if NET + public bool TryPickT2([NotNullWhen(true)] out T2? value, out OneOf remainder) +#else + public bool TryPickT2(out T2? value, out OneOf remainder) +#endif { value = IsT2 ? AsT2 : default; remainder = _index switch @@ -307,12 +321,16 @@ public bool TryPickT2(out T2 value, out OneOf AsT9, 10 => AsT10, 11 => AsT11, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT2; } - public bool TryPickT3(out T3 value, out OneOf remainder) +#if NET + public bool TryPickT3([NotNullWhen(true)] out T3? value, out OneOf remainder) +#else + public bool TryPickT3(out T3? value, out OneOf remainder) +#endif { value = IsT3 ? AsT3 : default; remainder = _index switch @@ -329,12 +347,16 @@ public bool TryPickT3(out T3 value, out OneOf AsT9, 10 => AsT10, 11 => AsT11, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT3; } - public bool TryPickT4(out T4 value, out OneOf remainder) +#if NET + public bool TryPickT4([NotNullWhen(true)] out T4? value, out OneOf remainder) +#else + public bool TryPickT4(out T4? value, out OneOf remainder) +#endif { value = IsT4 ? AsT4 : default; remainder = _index switch @@ -351,12 +373,16 @@ public bool TryPickT4(out T4 value, out OneOf AsT9, 10 => AsT10, 11 => AsT11, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT4; } - public bool TryPickT5(out T5 value, out OneOf remainder) +#if NET + public bool TryPickT5([NotNullWhen(true)] out T5? value, out OneOf remainder) +#else + public bool TryPickT5(out T5? value, out OneOf remainder) +#endif { value = IsT5 ? AsT5 : default; remainder = _index switch @@ -373,12 +399,16 @@ public bool TryPickT5(out T5 value, out OneOf AsT9, 10 => AsT10, 11 => AsT11, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT5; } - public bool TryPickT6(out T6 value, out OneOf remainder) +#if NET + public bool TryPickT6([NotNullWhen(true)] out T6? value, out OneOf remainder) +#else + public bool TryPickT6(out T6? value, out OneOf remainder) +#endif { value = IsT6 ? AsT6 : default; remainder = _index switch @@ -395,12 +425,16 @@ public bool TryPickT6(out T6 value, out OneOf AsT9, 10 => AsT10, 11 => AsT11, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT6; } - public bool TryPickT7(out T7 value, out OneOf remainder) +#if NET + public bool TryPickT7([NotNullWhen(true)] out T7? value, out OneOf remainder) +#else + public bool TryPickT7(out T7? value, out OneOf remainder) +#endif { value = IsT7 ? AsT7 : default; remainder = _index switch @@ -417,12 +451,16 @@ public bool TryPickT7(out T7 value, out OneOf AsT9, 10 => AsT10, 11 => AsT11, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT7; } - public bool TryPickT8(out T8 value, out OneOf remainder) +#if NET + public bool TryPickT8([NotNullWhen(true)] out T8? value, out OneOf remainder) +#else + public bool TryPickT8(out T8? value, out OneOf remainder) +#endif { value = IsT8 ? AsT8 : default; remainder = _index switch @@ -439,12 +477,16 @@ public bool TryPickT8(out T8 value, out OneOf AsT9, 10 => AsT10, 11 => AsT11, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT8; } - public bool TryPickT9(out T9 value, out OneOf remainder) +#if NET + public bool TryPickT9([NotNullWhen(true)] out T9? value, out OneOf remainder) +#else + public bool TryPickT9(out T9? value, out OneOf remainder) +#endif { value = IsT9 ? AsT9 : default; remainder = _index switch @@ -461,12 +503,16 @@ public bool TryPickT9(out T9 value, out OneOf default, 10 => AsT10, 11 => AsT11, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT9; } - public bool TryPickT10(out T10 value, out OneOf remainder) +#if NET + public bool TryPickT10([NotNullWhen(true)] out T10? value, out OneOf remainder) +#else + public bool TryPickT10(out T10? value, out OneOf remainder) +#endif { value = IsT10 ? AsT10 : default; remainder = _index switch @@ -483,12 +529,16 @@ public bool TryPickT10(out T10 value, out OneOf AsT9, 10 => default, 11 => AsT11, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT10; } - public bool TryPickT11(out T11 value, out OneOf remainder) +#if NET + public bool TryPickT11([NotNullWhen(true)] out T11? value, out OneOf remainder) +#else + public bool TryPickT11(out T11? value, out OneOf remainder) +#endif { value = IsT11 ? AsT11 : default; remainder = _index switch @@ -505,7 +555,7 @@ public bool TryPickT11(out T11 value, out OneOf AsT9, 10 => AsT10, 11 => default, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT11; } @@ -529,7 +579,7 @@ bool Equals(OneOfBase other) = _ => false }; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/OneOf.Extended/OneOfBaseT12.generated.cs b/OneOf.Extended/OneOfBaseT12.generated.cs index 7b9c66d..41eaab1 100644 --- a/OneOf.Extended/OneOfBaseT12.generated.cs +++ b/OneOf.Extended/OneOfBaseT12.generated.cs @@ -1,23 +1,25 @@ +#nullable enable using System; +using System.Diagnostics.CodeAnalysis; using static OneOf.Functions; namespace OneOf { public class OneOfBase : IOneOf { - readonly T0 _value0; - readonly T1 _value1; - readonly T2 _value2; - readonly T3 _value3; - readonly T4 _value4; - readonly T5 _value5; - readonly T6 _value6; - readonly T7 _value7; - readonly T8 _value8; - readonly T9 _value9; - readonly T10 _value10; - readonly T11 _value11; - readonly T12 _value12; + readonly T0 _value0 = default!; + readonly T1 _value1 = default!; + readonly T2 _value2 = default!; + readonly T3 _value3 = default!; + readonly T4 _value4 = default!; + readonly T5 _value5 = default!; + readonly T6 _value6 = default!; + readonly T7 _value7 = default!; + readonly T8 _value8 = default!; + readonly T9 _value9 = default!; + readonly T10 _value10 = default!; + readonly T11 _value11 = default!; + readonly T12 _value12 = default!; readonly int _index; protected OneOfBase(OneOf input) @@ -38,11 +40,11 @@ protected OneOfBase(OneOf case 10: _value10 = input.AsT10; break; case 11: _value11 = input.AsT11; break; case 12: _value12 = input.AsT12; break; - default: throw new InvalidOperationException(); + default: throw InvalidIndexException(_index); } } - public object Value => + public object? Value => _index switch { 0 => _value0, @@ -58,7 +60,7 @@ protected OneOfBase(OneOf 10 => _value10, 11 => _value11, 12 => _value12, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; public int Index => _index; @@ -199,7 +201,7 @@ public void Switch(Action f0, Action f1, Action f2, Action f3, A f12(_value12); return; } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } public TResult Match(Func f0, Func f1, Func f2, Func f3, Func f4, Func f5, Func f6, Func f7, Func f8, Func f9, Func f10, Func f11, Func f12) @@ -256,14 +258,18 @@ public TResult Match(Func f0, Func f1, Func remainder) +#if NET + public bool TryPickT0([NotNullWhen(true)] out T0? value, out OneOf remainder) +#else + public bool TryPickT0(out T0? value, out OneOf remainder) +#endif { value = IsT0 ? AsT0 : default; remainder = _index switch @@ -281,12 +287,16 @@ public bool TryPickT0(out T0 value, out OneOf AsT10, 11 => AsT11, 12 => AsT12, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT0; } - public bool TryPickT1(out T1 value, out OneOf remainder) +#if NET + public bool TryPickT1([NotNullWhen(true)] out T1? value, out OneOf remainder) +#else + public bool TryPickT1(out T1? value, out OneOf remainder) +#endif { value = IsT1 ? AsT1 : default; remainder = _index switch @@ -304,12 +314,16 @@ public bool TryPickT1(out T1 value, out OneOf AsT10, 11 => AsT11, 12 => AsT12, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT1; } - public bool TryPickT2(out T2 value, out OneOf remainder) +#if NET + public bool TryPickT2([NotNullWhen(true)] out T2? value, out OneOf remainder) +#else + public bool TryPickT2(out T2? value, out OneOf remainder) +#endif { value = IsT2 ? AsT2 : default; remainder = _index switch @@ -327,12 +341,16 @@ public bool TryPickT2(out T2 value, out OneOf AsT10, 11 => AsT11, 12 => AsT12, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT2; } - public bool TryPickT3(out T3 value, out OneOf remainder) +#if NET + public bool TryPickT3([NotNullWhen(true)] out T3? value, out OneOf remainder) +#else + public bool TryPickT3(out T3? value, out OneOf remainder) +#endif { value = IsT3 ? AsT3 : default; remainder = _index switch @@ -350,12 +368,16 @@ public bool TryPickT3(out T3 value, out OneOf AsT10, 11 => AsT11, 12 => AsT12, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT3; } - public bool TryPickT4(out T4 value, out OneOf remainder) +#if NET + public bool TryPickT4([NotNullWhen(true)] out T4? value, out OneOf remainder) +#else + public bool TryPickT4(out T4? value, out OneOf remainder) +#endif { value = IsT4 ? AsT4 : default; remainder = _index switch @@ -373,12 +395,16 @@ public bool TryPickT4(out T4 value, out OneOf AsT10, 11 => AsT11, 12 => AsT12, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT4; } - public bool TryPickT5(out T5 value, out OneOf remainder) +#if NET + public bool TryPickT5([NotNullWhen(true)] out T5? value, out OneOf remainder) +#else + public bool TryPickT5(out T5? value, out OneOf remainder) +#endif { value = IsT5 ? AsT5 : default; remainder = _index switch @@ -396,12 +422,16 @@ public bool TryPickT5(out T5 value, out OneOf AsT10, 11 => AsT11, 12 => AsT12, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT5; } - public bool TryPickT6(out T6 value, out OneOf remainder) +#if NET + public bool TryPickT6([NotNullWhen(true)] out T6? value, out OneOf remainder) +#else + public bool TryPickT6(out T6? value, out OneOf remainder) +#endif { value = IsT6 ? AsT6 : default; remainder = _index switch @@ -419,12 +449,16 @@ public bool TryPickT6(out T6 value, out OneOf AsT10, 11 => AsT11, 12 => AsT12, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT6; } - public bool TryPickT7(out T7 value, out OneOf remainder) +#if NET + public bool TryPickT7([NotNullWhen(true)] out T7? value, out OneOf remainder) +#else + public bool TryPickT7(out T7? value, out OneOf remainder) +#endif { value = IsT7 ? AsT7 : default; remainder = _index switch @@ -442,12 +476,16 @@ public bool TryPickT7(out T7 value, out OneOf AsT10, 11 => AsT11, 12 => AsT12, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT7; } - public bool TryPickT8(out T8 value, out OneOf remainder) +#if NET + public bool TryPickT8([NotNullWhen(true)] out T8? value, out OneOf remainder) +#else + public bool TryPickT8(out T8? value, out OneOf remainder) +#endif { value = IsT8 ? AsT8 : default; remainder = _index switch @@ -465,12 +503,16 @@ public bool TryPickT8(out T8 value, out OneOf AsT10, 11 => AsT11, 12 => AsT12, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT8; } - public bool TryPickT9(out T9 value, out OneOf remainder) +#if NET + public bool TryPickT9([NotNullWhen(true)] out T9? value, out OneOf remainder) +#else + public bool TryPickT9(out T9? value, out OneOf remainder) +#endif { value = IsT9 ? AsT9 : default; remainder = _index switch @@ -488,12 +530,16 @@ public bool TryPickT9(out T9 value, out OneOf AsT10, 11 => AsT11, 12 => AsT12, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT9; } - public bool TryPickT10(out T10 value, out OneOf remainder) +#if NET + public bool TryPickT10([NotNullWhen(true)] out T10? value, out OneOf remainder) +#else + public bool TryPickT10(out T10? value, out OneOf remainder) +#endif { value = IsT10 ? AsT10 : default; remainder = _index switch @@ -511,12 +557,16 @@ public bool TryPickT10(out T10 value, out OneOf default, 11 => AsT11, 12 => AsT12, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT10; } - public bool TryPickT11(out T11 value, out OneOf remainder) +#if NET + public bool TryPickT11([NotNullWhen(true)] out T11? value, out OneOf remainder) +#else + public bool TryPickT11(out T11? value, out OneOf remainder) +#endif { value = IsT11 ? AsT11 : default; remainder = _index switch @@ -534,12 +584,16 @@ public bool TryPickT11(out T11 value, out OneOf AsT10, 11 => default, 12 => AsT12, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT11; } - public bool TryPickT12(out T12 value, out OneOf remainder) +#if NET + public bool TryPickT12([NotNullWhen(true)] out T12? value, out OneOf remainder) +#else + public bool TryPickT12(out T12? value, out OneOf remainder) +#endif { value = IsT12 ? AsT12 : default; remainder = _index switch @@ -557,7 +611,7 @@ public bool TryPickT12(out T12 value, out OneOf AsT10, 11 => AsT11, 12 => default, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT12; } @@ -582,7 +636,7 @@ bool Equals(OneOfBase oth _ => false }; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/OneOf.Extended/OneOfBaseT13.generated.cs b/OneOf.Extended/OneOfBaseT13.generated.cs index ccf0cd7..3907df8 100644 --- a/OneOf.Extended/OneOfBaseT13.generated.cs +++ b/OneOf.Extended/OneOfBaseT13.generated.cs @@ -1,24 +1,26 @@ +#nullable enable using System; +using System.Diagnostics.CodeAnalysis; using static OneOf.Functions; namespace OneOf { public class OneOfBase : IOneOf { - readonly T0 _value0; - readonly T1 _value1; - readonly T2 _value2; - readonly T3 _value3; - readonly T4 _value4; - readonly T5 _value5; - readonly T6 _value6; - readonly T7 _value7; - readonly T8 _value8; - readonly T9 _value9; - readonly T10 _value10; - readonly T11 _value11; - readonly T12 _value12; - readonly T13 _value13; + readonly T0 _value0 = default!; + readonly T1 _value1 = default!; + readonly T2 _value2 = default!; + readonly T3 _value3 = default!; + readonly T4 _value4 = default!; + readonly T5 _value5 = default!; + readonly T6 _value6 = default!; + readonly T7 _value7 = default!; + readonly T8 _value8 = default!; + readonly T9 _value9 = default!; + readonly T10 _value10 = default!; + readonly T11 _value11 = default!; + readonly T12 _value12 = default!; + readonly T13 _value13 = default!; readonly int _index; protected OneOfBase(OneOf input) @@ -40,11 +42,11 @@ protected OneOfBase(OneOf + public object? Value => _index switch { 0 => _value0, @@ -61,7 +63,7 @@ protected OneOfBase(OneOf _value11, 12 => _value12, 13 => _value13, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; public int Index => _index; @@ -212,7 +214,7 @@ public void Switch(Action f0, Action f1, Action f2, Action f3, A f13(_value13); return; } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } public TResult Match(Func f0, Func f1, Func f2, Func f3, Func f4, Func f5, Func f6, Func f7, Func f8, Func f9, Func f10, Func f11, Func f12, Func f13) @@ -273,14 +275,18 @@ public TResult Match(Func f0, Func f1, Func remainder) +#if NET + public bool TryPickT0([NotNullWhen(true)] out T0? value, out OneOf remainder) +#else + public bool TryPickT0(out T0? value, out OneOf remainder) +#endif { value = IsT0 ? AsT0 : default; remainder = _index switch @@ -299,12 +305,16 @@ public bool TryPickT0(out T0 value, out OneOf AsT11, 12 => AsT12, 13 => AsT13, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT0; } - public bool TryPickT1(out T1 value, out OneOf remainder) +#if NET + public bool TryPickT1([NotNullWhen(true)] out T1? value, out OneOf remainder) +#else + public bool TryPickT1(out T1? value, out OneOf remainder) +#endif { value = IsT1 ? AsT1 : default; remainder = _index switch @@ -323,12 +333,16 @@ public bool TryPickT1(out T1 value, out OneOf AsT11, 12 => AsT12, 13 => AsT13, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT1; } - public bool TryPickT2(out T2 value, out OneOf remainder) +#if NET + public bool TryPickT2([NotNullWhen(true)] out T2? value, out OneOf remainder) +#else + public bool TryPickT2(out T2? value, out OneOf remainder) +#endif { value = IsT2 ? AsT2 : default; remainder = _index switch @@ -347,12 +361,16 @@ public bool TryPickT2(out T2 value, out OneOf AsT11, 12 => AsT12, 13 => AsT13, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT2; } - public bool TryPickT3(out T3 value, out OneOf remainder) +#if NET + public bool TryPickT3([NotNullWhen(true)] out T3? value, out OneOf remainder) +#else + public bool TryPickT3(out T3? value, out OneOf remainder) +#endif { value = IsT3 ? AsT3 : default; remainder = _index switch @@ -371,12 +389,16 @@ public bool TryPickT3(out T3 value, out OneOf AsT11, 12 => AsT12, 13 => AsT13, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT3; } - public bool TryPickT4(out T4 value, out OneOf remainder) +#if NET + public bool TryPickT4([NotNullWhen(true)] out T4? value, out OneOf remainder) +#else + public bool TryPickT4(out T4? value, out OneOf remainder) +#endif { value = IsT4 ? AsT4 : default; remainder = _index switch @@ -395,12 +417,16 @@ public bool TryPickT4(out T4 value, out OneOf AsT11, 12 => AsT12, 13 => AsT13, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT4; } - public bool TryPickT5(out T5 value, out OneOf remainder) +#if NET + public bool TryPickT5([NotNullWhen(true)] out T5? value, out OneOf remainder) +#else + public bool TryPickT5(out T5? value, out OneOf remainder) +#endif { value = IsT5 ? AsT5 : default; remainder = _index switch @@ -419,12 +445,16 @@ public bool TryPickT5(out T5 value, out OneOf AsT11, 12 => AsT12, 13 => AsT13, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT5; } - public bool TryPickT6(out T6 value, out OneOf remainder) +#if NET + public bool TryPickT6([NotNullWhen(true)] out T6? value, out OneOf remainder) +#else + public bool TryPickT6(out T6? value, out OneOf remainder) +#endif { value = IsT6 ? AsT6 : default; remainder = _index switch @@ -443,12 +473,16 @@ public bool TryPickT6(out T6 value, out OneOf AsT11, 12 => AsT12, 13 => AsT13, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT6; } - public bool TryPickT7(out T7 value, out OneOf remainder) +#if NET + public bool TryPickT7([NotNullWhen(true)] out T7? value, out OneOf remainder) +#else + public bool TryPickT7(out T7? value, out OneOf remainder) +#endif { value = IsT7 ? AsT7 : default; remainder = _index switch @@ -467,12 +501,16 @@ public bool TryPickT7(out T7 value, out OneOf AsT11, 12 => AsT12, 13 => AsT13, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT7; } - public bool TryPickT8(out T8 value, out OneOf remainder) +#if NET + public bool TryPickT8([NotNullWhen(true)] out T8? value, out OneOf remainder) +#else + public bool TryPickT8(out T8? value, out OneOf remainder) +#endif { value = IsT8 ? AsT8 : default; remainder = _index switch @@ -491,12 +529,16 @@ public bool TryPickT8(out T8 value, out OneOf AsT11, 12 => AsT12, 13 => AsT13, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT8; } - public bool TryPickT9(out T9 value, out OneOf remainder) +#if NET + public bool TryPickT9([NotNullWhen(true)] out T9? value, out OneOf remainder) +#else + public bool TryPickT9(out T9? value, out OneOf remainder) +#endif { value = IsT9 ? AsT9 : default; remainder = _index switch @@ -515,12 +557,16 @@ public bool TryPickT9(out T9 value, out OneOf AsT11, 12 => AsT12, 13 => AsT13, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT9; } - public bool TryPickT10(out T10 value, out OneOf remainder) +#if NET + public bool TryPickT10([NotNullWhen(true)] out T10? value, out OneOf remainder) +#else + public bool TryPickT10(out T10? value, out OneOf remainder) +#endif { value = IsT10 ? AsT10 : default; remainder = _index switch @@ -539,12 +585,16 @@ public bool TryPickT10(out T10 value, out OneOf AsT11, 12 => AsT12, 13 => AsT13, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT10; } - public bool TryPickT11(out T11 value, out OneOf remainder) +#if NET + public bool TryPickT11([NotNullWhen(true)] out T11? value, out OneOf remainder) +#else + public bool TryPickT11(out T11? value, out OneOf remainder) +#endif { value = IsT11 ? AsT11 : default; remainder = _index switch @@ -563,12 +613,16 @@ public bool TryPickT11(out T11 value, out OneOf default, 12 => AsT12, 13 => AsT13, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT11; } - public bool TryPickT12(out T12 value, out OneOf remainder) +#if NET + public bool TryPickT12([NotNullWhen(true)] out T12? value, out OneOf remainder) +#else + public bool TryPickT12(out T12? value, out OneOf remainder) +#endif { value = IsT12 ? AsT12 : default; remainder = _index switch @@ -587,12 +641,16 @@ public bool TryPickT12(out T12 value, out OneOf AsT11, 12 => default, 13 => AsT13, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT12; } - public bool TryPickT13(out T13 value, out OneOf remainder) +#if NET + public bool TryPickT13([NotNullWhen(true)] out T13? value, out OneOf remainder) +#else + public bool TryPickT13(out T13? value, out OneOf remainder) +#endif { value = IsT13 ? AsT13 : default; remainder = _index switch @@ -611,7 +669,7 @@ public bool TryPickT13(out T13 value, out OneOf AsT11, 12 => AsT12, 13 => default, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT13; } @@ -637,7 +695,7 @@ bool Equals(OneOfBase false }; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/OneOf.Extended/OneOfBaseT14.generated.cs b/OneOf.Extended/OneOfBaseT14.generated.cs index cade467..b4278f8 100644 --- a/OneOf.Extended/OneOfBaseT14.generated.cs +++ b/OneOf.Extended/OneOfBaseT14.generated.cs @@ -1,25 +1,27 @@ +#nullable enable using System; +using System.Diagnostics.CodeAnalysis; using static OneOf.Functions; namespace OneOf { public class OneOfBase : IOneOf { - readonly T0 _value0; - readonly T1 _value1; - readonly T2 _value2; - readonly T3 _value3; - readonly T4 _value4; - readonly T5 _value5; - readonly T6 _value6; - readonly T7 _value7; - readonly T8 _value8; - readonly T9 _value9; - readonly T10 _value10; - readonly T11 _value11; - readonly T12 _value12; - readonly T13 _value13; - readonly T14 _value14; + readonly T0 _value0 = default!; + readonly T1 _value1 = default!; + readonly T2 _value2 = default!; + readonly T3 _value3 = default!; + readonly T4 _value4 = default!; + readonly T5 _value5 = default!; + readonly T6 _value6 = default!; + readonly T7 _value7 = default!; + readonly T8 _value8 = default!; + readonly T9 _value9 = default!; + readonly T10 _value10 = default!; + readonly T11 _value11 = default!; + readonly T12 _value12 = default!; + readonly T13 _value13 = default!; + readonly T14 _value14 = default!; readonly int _index; protected OneOfBase(OneOf input) @@ -42,11 +44,11 @@ protected OneOfBase(OneOf + public object? Value => _index switch { 0 => _value0, @@ -64,7 +66,7 @@ protected OneOfBase(OneOf _value12, 13 => _value13, 14 => _value14, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; public int Index => _index; @@ -225,7 +227,7 @@ public void Switch(Action f0, Action f1, Action f2, Action f3, A f14(_value14); return; } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } public TResult Match(Func f0, Func f1, Func f2, Func f3, Func f4, Func f5, Func f6, Func f7, Func f8, Func f9, Func f10, Func f11, Func f12, Func f13, Func f14) @@ -290,14 +292,18 @@ public TResult Match(Func f0, Func f1, Func remainder) +#if NET + public bool TryPickT0([NotNullWhen(true)] out T0? value, out OneOf remainder) +#else + public bool TryPickT0(out T0? value, out OneOf remainder) +#endif { value = IsT0 ? AsT0 : default; remainder = _index switch @@ -317,12 +323,16 @@ public bool TryPickT0(out T0 value, out OneOf AsT12, 13 => AsT13, 14 => AsT14, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT0; } - public bool TryPickT1(out T1 value, out OneOf remainder) +#if NET + public bool TryPickT1([NotNullWhen(true)] out T1? value, out OneOf remainder) +#else + public bool TryPickT1(out T1? value, out OneOf remainder) +#endif { value = IsT1 ? AsT1 : default; remainder = _index switch @@ -342,12 +352,16 @@ public bool TryPickT1(out T1 value, out OneOf AsT12, 13 => AsT13, 14 => AsT14, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT1; } - public bool TryPickT2(out T2 value, out OneOf remainder) +#if NET + public bool TryPickT2([NotNullWhen(true)] out T2? value, out OneOf remainder) +#else + public bool TryPickT2(out T2? value, out OneOf remainder) +#endif { value = IsT2 ? AsT2 : default; remainder = _index switch @@ -367,12 +381,16 @@ public bool TryPickT2(out T2 value, out OneOf AsT12, 13 => AsT13, 14 => AsT14, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT2; } - public bool TryPickT3(out T3 value, out OneOf remainder) +#if NET + public bool TryPickT3([NotNullWhen(true)] out T3? value, out OneOf remainder) +#else + public bool TryPickT3(out T3? value, out OneOf remainder) +#endif { value = IsT3 ? AsT3 : default; remainder = _index switch @@ -392,12 +410,16 @@ public bool TryPickT3(out T3 value, out OneOf AsT12, 13 => AsT13, 14 => AsT14, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT3; } - public bool TryPickT4(out T4 value, out OneOf remainder) +#if NET + public bool TryPickT4([NotNullWhen(true)] out T4? value, out OneOf remainder) +#else + public bool TryPickT4(out T4? value, out OneOf remainder) +#endif { value = IsT4 ? AsT4 : default; remainder = _index switch @@ -417,12 +439,16 @@ public bool TryPickT4(out T4 value, out OneOf AsT12, 13 => AsT13, 14 => AsT14, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT4; } - public bool TryPickT5(out T5 value, out OneOf remainder) +#if NET + public bool TryPickT5([NotNullWhen(true)] out T5? value, out OneOf remainder) +#else + public bool TryPickT5(out T5? value, out OneOf remainder) +#endif { value = IsT5 ? AsT5 : default; remainder = _index switch @@ -442,12 +468,16 @@ public bool TryPickT5(out T5 value, out OneOf AsT12, 13 => AsT13, 14 => AsT14, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT5; } - public bool TryPickT6(out T6 value, out OneOf remainder) +#if NET + public bool TryPickT6([NotNullWhen(true)] out T6? value, out OneOf remainder) +#else + public bool TryPickT6(out T6? value, out OneOf remainder) +#endif { value = IsT6 ? AsT6 : default; remainder = _index switch @@ -467,12 +497,16 @@ public bool TryPickT6(out T6 value, out OneOf AsT12, 13 => AsT13, 14 => AsT14, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT6; } - public bool TryPickT7(out T7 value, out OneOf remainder) +#if NET + public bool TryPickT7([NotNullWhen(true)] out T7? value, out OneOf remainder) +#else + public bool TryPickT7(out T7? value, out OneOf remainder) +#endif { value = IsT7 ? AsT7 : default; remainder = _index switch @@ -492,12 +526,16 @@ public bool TryPickT7(out T7 value, out OneOf AsT12, 13 => AsT13, 14 => AsT14, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT7; } - public bool TryPickT8(out T8 value, out OneOf remainder) +#if NET + public bool TryPickT8([NotNullWhen(true)] out T8? value, out OneOf remainder) +#else + public bool TryPickT8(out T8? value, out OneOf remainder) +#endif { value = IsT8 ? AsT8 : default; remainder = _index switch @@ -517,12 +555,16 @@ public bool TryPickT8(out T8 value, out OneOf AsT12, 13 => AsT13, 14 => AsT14, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT8; } - public bool TryPickT9(out T9 value, out OneOf remainder) +#if NET + public bool TryPickT9([NotNullWhen(true)] out T9? value, out OneOf remainder) +#else + public bool TryPickT9(out T9? value, out OneOf remainder) +#endif { value = IsT9 ? AsT9 : default; remainder = _index switch @@ -542,12 +584,16 @@ public bool TryPickT9(out T9 value, out OneOf AsT12, 13 => AsT13, 14 => AsT14, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT9; } - public bool TryPickT10(out T10 value, out OneOf remainder) +#if NET + public bool TryPickT10([NotNullWhen(true)] out T10? value, out OneOf remainder) +#else + public bool TryPickT10(out T10? value, out OneOf remainder) +#endif { value = IsT10 ? AsT10 : default; remainder = _index switch @@ -567,12 +613,16 @@ public bool TryPickT10(out T10 value, out OneOf AsT12, 13 => AsT13, 14 => AsT14, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT10; } - public bool TryPickT11(out T11 value, out OneOf remainder) +#if NET + public bool TryPickT11([NotNullWhen(true)] out T11? value, out OneOf remainder) +#else + public bool TryPickT11(out T11? value, out OneOf remainder) +#endif { value = IsT11 ? AsT11 : default; remainder = _index switch @@ -592,12 +642,16 @@ public bool TryPickT11(out T11 value, out OneOf AsT12, 13 => AsT13, 14 => AsT14, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT11; } - public bool TryPickT12(out T12 value, out OneOf remainder) +#if NET + public bool TryPickT12([NotNullWhen(true)] out T12? value, out OneOf remainder) +#else + public bool TryPickT12(out T12? value, out OneOf remainder) +#endif { value = IsT12 ? AsT12 : default; remainder = _index switch @@ -617,12 +671,16 @@ public bool TryPickT12(out T12 value, out OneOf default, 13 => AsT13, 14 => AsT14, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT12; } - public bool TryPickT13(out T13 value, out OneOf remainder) +#if NET + public bool TryPickT13([NotNullWhen(true)] out T13? value, out OneOf remainder) +#else + public bool TryPickT13(out T13? value, out OneOf remainder) +#endif { value = IsT13 ? AsT13 : default; remainder = _index switch @@ -642,12 +700,16 @@ public bool TryPickT13(out T13 value, out OneOf AsT12, 13 => default, 14 => AsT14, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT13; } - public bool TryPickT14(out T14 value, out OneOf remainder) +#if NET + public bool TryPickT14([NotNullWhen(true)] out T14? value, out OneOf remainder) +#else + public bool TryPickT14(out T14? value, out OneOf remainder) +#endif { value = IsT14 ? AsT14 : default; remainder = _index switch @@ -667,7 +729,7 @@ public bool TryPickT14(out T14 value, out OneOf AsT12, 13 => AsT13, 14 => default, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT14; } @@ -694,7 +756,7 @@ bool Equals(OneOfBase false }; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/OneOf.Extended/OneOfBaseT15.generated.cs b/OneOf.Extended/OneOfBaseT15.generated.cs index 05132d2..24b1280 100644 --- a/OneOf.Extended/OneOfBaseT15.generated.cs +++ b/OneOf.Extended/OneOfBaseT15.generated.cs @@ -1,26 +1,28 @@ +#nullable enable using System; +using System.Diagnostics.CodeAnalysis; using static OneOf.Functions; namespace OneOf { public class OneOfBase : IOneOf { - readonly T0 _value0; - readonly T1 _value1; - readonly T2 _value2; - readonly T3 _value3; - readonly T4 _value4; - readonly T5 _value5; - readonly T6 _value6; - readonly T7 _value7; - readonly T8 _value8; - readonly T9 _value9; - readonly T10 _value10; - readonly T11 _value11; - readonly T12 _value12; - readonly T13 _value13; - readonly T14 _value14; - readonly T15 _value15; + readonly T0 _value0 = default!; + readonly T1 _value1 = default!; + readonly T2 _value2 = default!; + readonly T3 _value3 = default!; + readonly T4 _value4 = default!; + readonly T5 _value5 = default!; + readonly T6 _value6 = default!; + readonly T7 _value7 = default!; + readonly T8 _value8 = default!; + readonly T9 _value9 = default!; + readonly T10 _value10 = default!; + readonly T11 _value11 = default!; + readonly T12 _value12 = default!; + readonly T13 _value13 = default!; + readonly T14 _value14 = default!; + readonly T15 _value15 = default!; readonly int _index; protected OneOfBase(OneOf input) @@ -44,11 +46,11 @@ protected OneOfBase(OneOf + public object? Value => _index switch { 0 => _value0, @@ -67,7 +69,7 @@ protected OneOfBase(OneOf _value13, 14 => _value14, 15 => _value15, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; public int Index => _index; @@ -238,7 +240,7 @@ public void Switch(Action f0, Action f1, Action f2, Action f3, A f15(_value15); return; } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } public TResult Match(Func f0, Func f1, Func f2, Func f3, Func f4, Func f5, Func f6, Func f7, Func f8, Func f9, Func f10, Func f11, Func f12, Func f13, Func f14, Func f15) @@ -307,14 +309,18 @@ public TResult Match(Func f0, Func f1, Func remainder) +#if NET + public bool TryPickT0([NotNullWhen(true)] out T0? value, out OneOf remainder) +#else + public bool TryPickT0(out T0? value, out OneOf remainder) +#endif { value = IsT0 ? AsT0 : default; remainder = _index switch @@ -335,12 +341,16 @@ public bool TryPickT0(out T0 value, out OneOf AsT13, 14 => AsT14, 15 => AsT15, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT0; } - public bool TryPickT1(out T1 value, out OneOf remainder) +#if NET + public bool TryPickT1([NotNullWhen(true)] out T1? value, out OneOf remainder) +#else + public bool TryPickT1(out T1? value, out OneOf remainder) +#endif { value = IsT1 ? AsT1 : default; remainder = _index switch @@ -361,12 +371,16 @@ public bool TryPickT1(out T1 value, out OneOf AsT13, 14 => AsT14, 15 => AsT15, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT1; } - public bool TryPickT2(out T2 value, out OneOf remainder) +#if NET + public bool TryPickT2([NotNullWhen(true)] out T2? value, out OneOf remainder) +#else + public bool TryPickT2(out T2? value, out OneOf remainder) +#endif { value = IsT2 ? AsT2 : default; remainder = _index switch @@ -387,12 +401,16 @@ public bool TryPickT2(out T2 value, out OneOf AsT13, 14 => AsT14, 15 => AsT15, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT2; } - public bool TryPickT3(out T3 value, out OneOf remainder) +#if NET + public bool TryPickT3([NotNullWhen(true)] out T3? value, out OneOf remainder) +#else + public bool TryPickT3(out T3? value, out OneOf remainder) +#endif { value = IsT3 ? AsT3 : default; remainder = _index switch @@ -413,12 +431,16 @@ public bool TryPickT3(out T3 value, out OneOf AsT13, 14 => AsT14, 15 => AsT15, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT3; } - public bool TryPickT4(out T4 value, out OneOf remainder) +#if NET + public bool TryPickT4([NotNullWhen(true)] out T4? value, out OneOf remainder) +#else + public bool TryPickT4(out T4? value, out OneOf remainder) +#endif { value = IsT4 ? AsT4 : default; remainder = _index switch @@ -439,12 +461,16 @@ public bool TryPickT4(out T4 value, out OneOf AsT13, 14 => AsT14, 15 => AsT15, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT4; } - public bool TryPickT5(out T5 value, out OneOf remainder) +#if NET + public bool TryPickT5([NotNullWhen(true)] out T5? value, out OneOf remainder) +#else + public bool TryPickT5(out T5? value, out OneOf remainder) +#endif { value = IsT5 ? AsT5 : default; remainder = _index switch @@ -465,12 +491,16 @@ public bool TryPickT5(out T5 value, out OneOf AsT13, 14 => AsT14, 15 => AsT15, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT5; } - public bool TryPickT6(out T6 value, out OneOf remainder) +#if NET + public bool TryPickT6([NotNullWhen(true)] out T6? value, out OneOf remainder) +#else + public bool TryPickT6(out T6? value, out OneOf remainder) +#endif { value = IsT6 ? AsT6 : default; remainder = _index switch @@ -491,12 +521,16 @@ public bool TryPickT6(out T6 value, out OneOf AsT13, 14 => AsT14, 15 => AsT15, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT6; } - public bool TryPickT7(out T7 value, out OneOf remainder) +#if NET + public bool TryPickT7([NotNullWhen(true)] out T7? value, out OneOf remainder) +#else + public bool TryPickT7(out T7? value, out OneOf remainder) +#endif { value = IsT7 ? AsT7 : default; remainder = _index switch @@ -517,12 +551,16 @@ public bool TryPickT7(out T7 value, out OneOf AsT13, 14 => AsT14, 15 => AsT15, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT7; } - public bool TryPickT8(out T8 value, out OneOf remainder) +#if NET + public bool TryPickT8([NotNullWhen(true)] out T8? value, out OneOf remainder) +#else + public bool TryPickT8(out T8? value, out OneOf remainder) +#endif { value = IsT8 ? AsT8 : default; remainder = _index switch @@ -543,12 +581,16 @@ public bool TryPickT8(out T8 value, out OneOf AsT13, 14 => AsT14, 15 => AsT15, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT8; } - public bool TryPickT9(out T9 value, out OneOf remainder) +#if NET + public bool TryPickT9([NotNullWhen(true)] out T9? value, out OneOf remainder) +#else + public bool TryPickT9(out T9? value, out OneOf remainder) +#endif { value = IsT9 ? AsT9 : default; remainder = _index switch @@ -569,12 +611,16 @@ public bool TryPickT9(out T9 value, out OneOf AsT13, 14 => AsT14, 15 => AsT15, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT9; } - public bool TryPickT10(out T10 value, out OneOf remainder) +#if NET + public bool TryPickT10([NotNullWhen(true)] out T10? value, out OneOf remainder) +#else + public bool TryPickT10(out T10? value, out OneOf remainder) +#endif { value = IsT10 ? AsT10 : default; remainder = _index switch @@ -595,12 +641,16 @@ public bool TryPickT10(out T10 value, out OneOf AsT13, 14 => AsT14, 15 => AsT15, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT10; } - public bool TryPickT11(out T11 value, out OneOf remainder) +#if NET + public bool TryPickT11([NotNullWhen(true)] out T11? value, out OneOf remainder) +#else + public bool TryPickT11(out T11? value, out OneOf remainder) +#endif { value = IsT11 ? AsT11 : default; remainder = _index switch @@ -621,12 +671,16 @@ public bool TryPickT11(out T11 value, out OneOf AsT13, 14 => AsT14, 15 => AsT15, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT11; } - public bool TryPickT12(out T12 value, out OneOf remainder) +#if NET + public bool TryPickT12([NotNullWhen(true)] out T12? value, out OneOf remainder) +#else + public bool TryPickT12(out T12? value, out OneOf remainder) +#endif { value = IsT12 ? AsT12 : default; remainder = _index switch @@ -647,12 +701,16 @@ public bool TryPickT12(out T12 value, out OneOf AsT13, 14 => AsT14, 15 => AsT15, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT12; } - public bool TryPickT13(out T13 value, out OneOf remainder) +#if NET + public bool TryPickT13([NotNullWhen(true)] out T13? value, out OneOf remainder) +#else + public bool TryPickT13(out T13? value, out OneOf remainder) +#endif { value = IsT13 ? AsT13 : default; remainder = _index switch @@ -673,12 +731,16 @@ public bool TryPickT13(out T13 value, out OneOf default, 14 => AsT14, 15 => AsT15, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT13; } - public bool TryPickT14(out T14 value, out OneOf remainder) +#if NET + public bool TryPickT14([NotNullWhen(true)] out T14? value, out OneOf remainder) +#else + public bool TryPickT14(out T14? value, out OneOf remainder) +#endif { value = IsT14 ? AsT14 : default; remainder = _index switch @@ -699,12 +761,16 @@ public bool TryPickT14(out T14 value, out OneOf AsT13, 14 => default, 15 => AsT15, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT14; } - public bool TryPickT15(out T15 value, out OneOf remainder) +#if NET + public bool TryPickT15([NotNullWhen(true)] out T15? value, out OneOf remainder) +#else + public bool TryPickT15(out T15? value, out OneOf remainder) +#endif { value = IsT15 ? AsT15 : default; remainder = _index switch @@ -725,7 +791,7 @@ public bool TryPickT15(out T15 value, out OneOf AsT13, 14 => AsT14, 15 => default, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT15; } @@ -753,7 +819,7 @@ bool Equals(OneOfBase false }; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/OneOf.Extended/OneOfBaseT16.generated.cs b/OneOf.Extended/OneOfBaseT16.generated.cs index d59e70a..d075f10 100644 --- a/OneOf.Extended/OneOfBaseT16.generated.cs +++ b/OneOf.Extended/OneOfBaseT16.generated.cs @@ -1,27 +1,29 @@ +#nullable enable using System; +using System.Diagnostics.CodeAnalysis; using static OneOf.Functions; namespace OneOf { public class OneOfBase : IOneOf { - readonly T0 _value0; - readonly T1 _value1; - readonly T2 _value2; - readonly T3 _value3; - readonly T4 _value4; - readonly T5 _value5; - readonly T6 _value6; - readonly T7 _value7; - readonly T8 _value8; - readonly T9 _value9; - readonly T10 _value10; - readonly T11 _value11; - readonly T12 _value12; - readonly T13 _value13; - readonly T14 _value14; - readonly T15 _value15; - readonly T16 _value16; + readonly T0 _value0 = default!; + readonly T1 _value1 = default!; + readonly T2 _value2 = default!; + readonly T3 _value3 = default!; + readonly T4 _value4 = default!; + readonly T5 _value5 = default!; + readonly T6 _value6 = default!; + readonly T7 _value7 = default!; + readonly T8 _value8 = default!; + readonly T9 _value9 = default!; + readonly T10 _value10 = default!; + readonly T11 _value11 = default!; + readonly T12 _value12 = default!; + readonly T13 _value13 = default!; + readonly T14 _value14 = default!; + readonly T15 _value15 = default!; + readonly T16 _value16 = default!; readonly int _index; protected OneOfBase(OneOf input) @@ -46,11 +48,11 @@ protected OneOfBase(OneOf + public object? Value => _index switch { 0 => _value0, @@ -70,7 +72,7 @@ protected OneOfBase(OneOf _value14, 15 => _value15, 16 => _value16, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; public int Index => _index; @@ -251,7 +253,7 @@ public void Switch(Action f0, Action f1, Action f2, Action f3, A f16(_value16); return; } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } public TResult Match(Func f0, Func f1, Func f2, Func f3, Func f4, Func f5, Func f6, Func f7, Func f8, Func f9, Func f10, Func f11, Func f12, Func f13, Func f14, Func f15, Func f16) @@ -324,14 +326,18 @@ public TResult Match(Func f0, Func f1, Func remainder) +#if NET + public bool TryPickT0([NotNullWhen(true)] out T0? value, out OneOf remainder) +#else + public bool TryPickT0(out T0? value, out OneOf remainder) +#endif { value = IsT0 ? AsT0 : default; remainder = _index switch @@ -353,12 +359,16 @@ public bool TryPickT0(out T0 value, out OneOf AsT14, 15 => AsT15, 16 => AsT16, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT0; } - public bool TryPickT1(out T1 value, out OneOf remainder) +#if NET + public bool TryPickT1([NotNullWhen(true)] out T1? value, out OneOf remainder) +#else + public bool TryPickT1(out T1? value, out OneOf remainder) +#endif { value = IsT1 ? AsT1 : default; remainder = _index switch @@ -380,12 +390,16 @@ public bool TryPickT1(out T1 value, out OneOf AsT14, 15 => AsT15, 16 => AsT16, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT1; } - public bool TryPickT2(out T2 value, out OneOf remainder) +#if NET + public bool TryPickT2([NotNullWhen(true)] out T2? value, out OneOf remainder) +#else + public bool TryPickT2(out T2? value, out OneOf remainder) +#endif { value = IsT2 ? AsT2 : default; remainder = _index switch @@ -407,12 +421,16 @@ public bool TryPickT2(out T2 value, out OneOf AsT14, 15 => AsT15, 16 => AsT16, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT2; } - public bool TryPickT3(out T3 value, out OneOf remainder) +#if NET + public bool TryPickT3([NotNullWhen(true)] out T3? value, out OneOf remainder) +#else + public bool TryPickT3(out T3? value, out OneOf remainder) +#endif { value = IsT3 ? AsT3 : default; remainder = _index switch @@ -434,12 +452,16 @@ public bool TryPickT3(out T3 value, out OneOf AsT14, 15 => AsT15, 16 => AsT16, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT3; } - public bool TryPickT4(out T4 value, out OneOf remainder) +#if NET + public bool TryPickT4([NotNullWhen(true)] out T4? value, out OneOf remainder) +#else + public bool TryPickT4(out T4? value, out OneOf remainder) +#endif { value = IsT4 ? AsT4 : default; remainder = _index switch @@ -461,12 +483,16 @@ public bool TryPickT4(out T4 value, out OneOf AsT14, 15 => AsT15, 16 => AsT16, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT4; } - public bool TryPickT5(out T5 value, out OneOf remainder) +#if NET + public bool TryPickT5([NotNullWhen(true)] out T5? value, out OneOf remainder) +#else + public bool TryPickT5(out T5? value, out OneOf remainder) +#endif { value = IsT5 ? AsT5 : default; remainder = _index switch @@ -488,12 +514,16 @@ public bool TryPickT5(out T5 value, out OneOf AsT14, 15 => AsT15, 16 => AsT16, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT5; } - public bool TryPickT6(out T6 value, out OneOf remainder) +#if NET + public bool TryPickT6([NotNullWhen(true)] out T6? value, out OneOf remainder) +#else + public bool TryPickT6(out T6? value, out OneOf remainder) +#endif { value = IsT6 ? AsT6 : default; remainder = _index switch @@ -515,12 +545,16 @@ public bool TryPickT6(out T6 value, out OneOf AsT14, 15 => AsT15, 16 => AsT16, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT6; } - public bool TryPickT7(out T7 value, out OneOf remainder) +#if NET + public bool TryPickT7([NotNullWhen(true)] out T7? value, out OneOf remainder) +#else + public bool TryPickT7(out T7? value, out OneOf remainder) +#endif { value = IsT7 ? AsT7 : default; remainder = _index switch @@ -542,12 +576,16 @@ public bool TryPickT7(out T7 value, out OneOf AsT14, 15 => AsT15, 16 => AsT16, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT7; } - public bool TryPickT8(out T8 value, out OneOf remainder) +#if NET + public bool TryPickT8([NotNullWhen(true)] out T8? value, out OneOf remainder) +#else + public bool TryPickT8(out T8? value, out OneOf remainder) +#endif { value = IsT8 ? AsT8 : default; remainder = _index switch @@ -569,12 +607,16 @@ public bool TryPickT8(out T8 value, out OneOf AsT14, 15 => AsT15, 16 => AsT16, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT8; } - public bool TryPickT9(out T9 value, out OneOf remainder) +#if NET + public bool TryPickT9([NotNullWhen(true)] out T9? value, out OneOf remainder) +#else + public bool TryPickT9(out T9? value, out OneOf remainder) +#endif { value = IsT9 ? AsT9 : default; remainder = _index switch @@ -596,12 +638,16 @@ public bool TryPickT9(out T9 value, out OneOf AsT14, 15 => AsT15, 16 => AsT16, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT9; } - public bool TryPickT10(out T10 value, out OneOf remainder) +#if NET + public bool TryPickT10([NotNullWhen(true)] out T10? value, out OneOf remainder) +#else + public bool TryPickT10(out T10? value, out OneOf remainder) +#endif { value = IsT10 ? AsT10 : default; remainder = _index switch @@ -623,12 +669,16 @@ public bool TryPickT10(out T10 value, out OneOf AsT14, 15 => AsT15, 16 => AsT16, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT10; } - public bool TryPickT11(out T11 value, out OneOf remainder) +#if NET + public bool TryPickT11([NotNullWhen(true)] out T11? value, out OneOf remainder) +#else + public bool TryPickT11(out T11? value, out OneOf remainder) +#endif { value = IsT11 ? AsT11 : default; remainder = _index switch @@ -650,12 +700,16 @@ public bool TryPickT11(out T11 value, out OneOf AsT14, 15 => AsT15, 16 => AsT16, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT11; } - public bool TryPickT12(out T12 value, out OneOf remainder) +#if NET + public bool TryPickT12([NotNullWhen(true)] out T12? value, out OneOf remainder) +#else + public bool TryPickT12(out T12? value, out OneOf remainder) +#endif { value = IsT12 ? AsT12 : default; remainder = _index switch @@ -677,12 +731,16 @@ public bool TryPickT12(out T12 value, out OneOf AsT14, 15 => AsT15, 16 => AsT16, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT12; } - public bool TryPickT13(out T13 value, out OneOf remainder) +#if NET + public bool TryPickT13([NotNullWhen(true)] out T13? value, out OneOf remainder) +#else + public bool TryPickT13(out T13? value, out OneOf remainder) +#endif { value = IsT13 ? AsT13 : default; remainder = _index switch @@ -704,12 +762,16 @@ public bool TryPickT13(out T13 value, out OneOf AsT14, 15 => AsT15, 16 => AsT16, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT13; } - public bool TryPickT14(out T14 value, out OneOf remainder) +#if NET + public bool TryPickT14([NotNullWhen(true)] out T14? value, out OneOf remainder) +#else + public bool TryPickT14(out T14? value, out OneOf remainder) +#endif { value = IsT14 ? AsT14 : default; remainder = _index switch @@ -731,12 +793,16 @@ public bool TryPickT14(out T14 value, out OneOf default, 15 => AsT15, 16 => AsT16, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT14; } - public bool TryPickT15(out T15 value, out OneOf remainder) +#if NET + public bool TryPickT15([NotNullWhen(true)] out T15? value, out OneOf remainder) +#else + public bool TryPickT15(out T15? value, out OneOf remainder) +#endif { value = IsT15 ? AsT15 : default; remainder = _index switch @@ -758,12 +824,16 @@ public bool TryPickT15(out T15 value, out OneOf AsT14, 15 => default, 16 => AsT16, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT15; } - public bool TryPickT16(out T16 value, out OneOf remainder) +#if NET + public bool TryPickT16([NotNullWhen(true)] out T16? value, out OneOf remainder) +#else + public bool TryPickT16(out T16? value, out OneOf remainder) +#endif { value = IsT16 ? AsT16 : default; remainder = _index switch @@ -785,7 +855,7 @@ public bool TryPickT16(out T16 value, out OneOf AsT14, 15 => AsT15, 16 => default, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT16; } @@ -814,7 +884,7 @@ bool Equals(OneOfBase false }; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/OneOf.Extended/OneOfBaseT17.generated.cs b/OneOf.Extended/OneOfBaseT17.generated.cs index b50d501..46fd309 100644 --- a/OneOf.Extended/OneOfBaseT17.generated.cs +++ b/OneOf.Extended/OneOfBaseT17.generated.cs @@ -1,28 +1,30 @@ +#nullable enable using System; +using System.Diagnostics.CodeAnalysis; using static OneOf.Functions; namespace OneOf { public class OneOfBase : IOneOf { - readonly T0 _value0; - readonly T1 _value1; - readonly T2 _value2; - readonly T3 _value3; - readonly T4 _value4; - readonly T5 _value5; - readonly T6 _value6; - readonly T7 _value7; - readonly T8 _value8; - readonly T9 _value9; - readonly T10 _value10; - readonly T11 _value11; - readonly T12 _value12; - readonly T13 _value13; - readonly T14 _value14; - readonly T15 _value15; - readonly T16 _value16; - readonly T17 _value17; + readonly T0 _value0 = default!; + readonly T1 _value1 = default!; + readonly T2 _value2 = default!; + readonly T3 _value3 = default!; + readonly T4 _value4 = default!; + readonly T5 _value5 = default!; + readonly T6 _value6 = default!; + readonly T7 _value7 = default!; + readonly T8 _value8 = default!; + readonly T9 _value9 = default!; + readonly T10 _value10 = default!; + readonly T11 _value11 = default!; + readonly T12 _value12 = default!; + readonly T13 _value13 = default!; + readonly T14 _value14 = default!; + readonly T15 _value15 = default!; + readonly T16 _value16 = default!; + readonly T17 _value17 = default!; readonly int _index; protected OneOfBase(OneOf input) @@ -48,11 +50,11 @@ protected OneOfBase(OneOf + public object? Value => _index switch { 0 => _value0, @@ -73,7 +75,7 @@ protected OneOfBase(OneOf _value15, 16 => _value16, 17 => _value17, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; public int Index => _index; @@ -264,7 +266,7 @@ public void Switch(Action f0, Action f1, Action f2, Action f3, A f17(_value17); return; } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } public TResult Match(Func f0, Func f1, Func f2, Func f3, Func f4, Func f5, Func f6, Func f7, Func f8, Func f9, Func f10, Func f11, Func f12, Func f13, Func f14, Func f15, Func f16, Func f17) @@ -341,14 +343,18 @@ public TResult Match(Func f0, Func f1, Func remainder) +#if NET + public bool TryPickT0([NotNullWhen(true)] out T0? value, out OneOf remainder) +#else + public bool TryPickT0(out T0? value, out OneOf remainder) +#endif { value = IsT0 ? AsT0 : default; remainder = _index switch @@ -371,12 +377,16 @@ public bool TryPickT0(out T0 value, out OneOf AsT15, 16 => AsT16, 17 => AsT17, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT0; } - public bool TryPickT1(out T1 value, out OneOf remainder) +#if NET + public bool TryPickT1([NotNullWhen(true)] out T1? value, out OneOf remainder) +#else + public bool TryPickT1(out T1? value, out OneOf remainder) +#endif { value = IsT1 ? AsT1 : default; remainder = _index switch @@ -399,12 +409,16 @@ public bool TryPickT1(out T1 value, out OneOf AsT15, 16 => AsT16, 17 => AsT17, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT1; } - public bool TryPickT2(out T2 value, out OneOf remainder) +#if NET + public bool TryPickT2([NotNullWhen(true)] out T2? value, out OneOf remainder) +#else + public bool TryPickT2(out T2? value, out OneOf remainder) +#endif { value = IsT2 ? AsT2 : default; remainder = _index switch @@ -427,12 +441,16 @@ public bool TryPickT2(out T2 value, out OneOf AsT15, 16 => AsT16, 17 => AsT17, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT2; } - public bool TryPickT3(out T3 value, out OneOf remainder) +#if NET + public bool TryPickT3([NotNullWhen(true)] out T3? value, out OneOf remainder) +#else + public bool TryPickT3(out T3? value, out OneOf remainder) +#endif { value = IsT3 ? AsT3 : default; remainder = _index switch @@ -455,12 +473,16 @@ public bool TryPickT3(out T3 value, out OneOf AsT15, 16 => AsT16, 17 => AsT17, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT3; } - public bool TryPickT4(out T4 value, out OneOf remainder) +#if NET + public bool TryPickT4([NotNullWhen(true)] out T4? value, out OneOf remainder) +#else + public bool TryPickT4(out T4? value, out OneOf remainder) +#endif { value = IsT4 ? AsT4 : default; remainder = _index switch @@ -483,12 +505,16 @@ public bool TryPickT4(out T4 value, out OneOf AsT15, 16 => AsT16, 17 => AsT17, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT4; } - public bool TryPickT5(out T5 value, out OneOf remainder) +#if NET + public bool TryPickT5([NotNullWhen(true)] out T5? value, out OneOf remainder) +#else + public bool TryPickT5(out T5? value, out OneOf remainder) +#endif { value = IsT5 ? AsT5 : default; remainder = _index switch @@ -511,12 +537,16 @@ public bool TryPickT5(out T5 value, out OneOf AsT15, 16 => AsT16, 17 => AsT17, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT5; } - public bool TryPickT6(out T6 value, out OneOf remainder) +#if NET + public bool TryPickT6([NotNullWhen(true)] out T6? value, out OneOf remainder) +#else + public bool TryPickT6(out T6? value, out OneOf remainder) +#endif { value = IsT6 ? AsT6 : default; remainder = _index switch @@ -539,12 +569,16 @@ public bool TryPickT6(out T6 value, out OneOf AsT15, 16 => AsT16, 17 => AsT17, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT6; } - public bool TryPickT7(out T7 value, out OneOf remainder) +#if NET + public bool TryPickT7([NotNullWhen(true)] out T7? value, out OneOf remainder) +#else + public bool TryPickT7(out T7? value, out OneOf remainder) +#endif { value = IsT7 ? AsT7 : default; remainder = _index switch @@ -567,12 +601,16 @@ public bool TryPickT7(out T7 value, out OneOf AsT15, 16 => AsT16, 17 => AsT17, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT7; } - public bool TryPickT8(out T8 value, out OneOf remainder) +#if NET + public bool TryPickT8([NotNullWhen(true)] out T8? value, out OneOf remainder) +#else + public bool TryPickT8(out T8? value, out OneOf remainder) +#endif { value = IsT8 ? AsT8 : default; remainder = _index switch @@ -595,12 +633,16 @@ public bool TryPickT8(out T8 value, out OneOf AsT15, 16 => AsT16, 17 => AsT17, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT8; } - public bool TryPickT9(out T9 value, out OneOf remainder) +#if NET + public bool TryPickT9([NotNullWhen(true)] out T9? value, out OneOf remainder) +#else + public bool TryPickT9(out T9? value, out OneOf remainder) +#endif { value = IsT9 ? AsT9 : default; remainder = _index switch @@ -623,12 +665,16 @@ public bool TryPickT9(out T9 value, out OneOf AsT15, 16 => AsT16, 17 => AsT17, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT9; } - public bool TryPickT10(out T10 value, out OneOf remainder) +#if NET + public bool TryPickT10([NotNullWhen(true)] out T10? value, out OneOf remainder) +#else + public bool TryPickT10(out T10? value, out OneOf remainder) +#endif { value = IsT10 ? AsT10 : default; remainder = _index switch @@ -651,12 +697,16 @@ public bool TryPickT10(out T10 value, out OneOf AsT15, 16 => AsT16, 17 => AsT17, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT10; } - public bool TryPickT11(out T11 value, out OneOf remainder) +#if NET + public bool TryPickT11([NotNullWhen(true)] out T11? value, out OneOf remainder) +#else + public bool TryPickT11(out T11? value, out OneOf remainder) +#endif { value = IsT11 ? AsT11 : default; remainder = _index switch @@ -679,12 +729,16 @@ public bool TryPickT11(out T11 value, out OneOf AsT15, 16 => AsT16, 17 => AsT17, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT11; } - public bool TryPickT12(out T12 value, out OneOf remainder) +#if NET + public bool TryPickT12([NotNullWhen(true)] out T12? value, out OneOf remainder) +#else + public bool TryPickT12(out T12? value, out OneOf remainder) +#endif { value = IsT12 ? AsT12 : default; remainder = _index switch @@ -707,12 +761,16 @@ public bool TryPickT12(out T12 value, out OneOf AsT15, 16 => AsT16, 17 => AsT17, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT12; } - public bool TryPickT13(out T13 value, out OneOf remainder) +#if NET + public bool TryPickT13([NotNullWhen(true)] out T13? value, out OneOf remainder) +#else + public bool TryPickT13(out T13? value, out OneOf remainder) +#endif { value = IsT13 ? AsT13 : default; remainder = _index switch @@ -735,12 +793,16 @@ public bool TryPickT13(out T13 value, out OneOf AsT15, 16 => AsT16, 17 => AsT17, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT13; } - public bool TryPickT14(out T14 value, out OneOf remainder) +#if NET + public bool TryPickT14([NotNullWhen(true)] out T14? value, out OneOf remainder) +#else + public bool TryPickT14(out T14? value, out OneOf remainder) +#endif { value = IsT14 ? AsT14 : default; remainder = _index switch @@ -763,12 +825,16 @@ public bool TryPickT14(out T14 value, out OneOf AsT15, 16 => AsT16, 17 => AsT17, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT14; } - public bool TryPickT15(out T15 value, out OneOf remainder) +#if NET + public bool TryPickT15([NotNullWhen(true)] out T15? value, out OneOf remainder) +#else + public bool TryPickT15(out T15? value, out OneOf remainder) +#endif { value = IsT15 ? AsT15 : default; remainder = _index switch @@ -791,12 +857,16 @@ public bool TryPickT15(out T15 value, out OneOf default, 16 => AsT16, 17 => AsT17, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT15; } - public bool TryPickT16(out T16 value, out OneOf remainder) +#if NET + public bool TryPickT16([NotNullWhen(true)] out T16? value, out OneOf remainder) +#else + public bool TryPickT16(out T16? value, out OneOf remainder) +#endif { value = IsT16 ? AsT16 : default; remainder = _index switch @@ -819,12 +889,16 @@ public bool TryPickT16(out T16 value, out OneOf AsT15, 16 => default, 17 => AsT17, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT16; } - public bool TryPickT17(out T17 value, out OneOf remainder) +#if NET + public bool TryPickT17([NotNullWhen(true)] out T17? value, out OneOf remainder) +#else + public bool TryPickT17(out T17? value, out OneOf remainder) +#endif { value = IsT17 ? AsT17 : default; remainder = _index switch @@ -847,7 +921,7 @@ public bool TryPickT17(out T17 value, out OneOf AsT15, 16 => AsT16, 17 => default, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT17; } @@ -877,7 +951,7 @@ bool Equals(OneOfBase false }; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/OneOf.Extended/OneOfBaseT18.generated.cs b/OneOf.Extended/OneOfBaseT18.generated.cs index 9749b93..d6421a1 100644 --- a/OneOf.Extended/OneOfBaseT18.generated.cs +++ b/OneOf.Extended/OneOfBaseT18.generated.cs @@ -1,29 +1,31 @@ +#nullable enable using System; +using System.Diagnostics.CodeAnalysis; using static OneOf.Functions; namespace OneOf { public class OneOfBase : IOneOf { - readonly T0 _value0; - readonly T1 _value1; - readonly T2 _value2; - readonly T3 _value3; - readonly T4 _value4; - readonly T5 _value5; - readonly T6 _value6; - readonly T7 _value7; - readonly T8 _value8; - readonly T9 _value9; - readonly T10 _value10; - readonly T11 _value11; - readonly T12 _value12; - readonly T13 _value13; - readonly T14 _value14; - readonly T15 _value15; - readonly T16 _value16; - readonly T17 _value17; - readonly T18 _value18; + readonly T0 _value0 = default!; + readonly T1 _value1 = default!; + readonly T2 _value2 = default!; + readonly T3 _value3 = default!; + readonly T4 _value4 = default!; + readonly T5 _value5 = default!; + readonly T6 _value6 = default!; + readonly T7 _value7 = default!; + readonly T8 _value8 = default!; + readonly T9 _value9 = default!; + readonly T10 _value10 = default!; + readonly T11 _value11 = default!; + readonly T12 _value12 = default!; + readonly T13 _value13 = default!; + readonly T14 _value14 = default!; + readonly T15 _value15 = default!; + readonly T16 _value16 = default!; + readonly T17 _value17 = default!; + readonly T18 _value18 = default!; readonly int _index; protected OneOfBase(OneOf input) @@ -50,11 +52,11 @@ protected OneOfBase(OneOf + public object? Value => _index switch { 0 => _value0, @@ -76,7 +78,7 @@ protected OneOfBase(OneOf _value16, 17 => _value17, 18 => _value18, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; public int Index => _index; @@ -277,7 +279,7 @@ public void Switch(Action f0, Action f1, Action f2, Action f3, A f18(_value18); return; } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } public TResult Match(Func f0, Func f1, Func f2, Func f3, Func f4, Func f5, Func f6, Func f7, Func f8, Func f9, Func f10, Func f11, Func f12, Func f13, Func f14, Func f15, Func f16, Func f17, Func f18) @@ -358,14 +360,18 @@ public TResult Match(Func f0, Func f1, Func remainder) +#if NET + public bool TryPickT0([NotNullWhen(true)] out T0? value, out OneOf remainder) +#else + public bool TryPickT0(out T0? value, out OneOf remainder) +#endif { value = IsT0 ? AsT0 : default; remainder = _index switch @@ -389,12 +395,16 @@ public bool TryPickT0(out T0 value, out OneOf AsT16, 17 => AsT17, 18 => AsT18, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT0; } - public bool TryPickT1(out T1 value, out OneOf remainder) +#if NET + public bool TryPickT1([NotNullWhen(true)] out T1? value, out OneOf remainder) +#else + public bool TryPickT1(out T1? value, out OneOf remainder) +#endif { value = IsT1 ? AsT1 : default; remainder = _index switch @@ -418,12 +428,16 @@ public bool TryPickT1(out T1 value, out OneOf AsT16, 17 => AsT17, 18 => AsT18, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT1; } - public bool TryPickT2(out T2 value, out OneOf remainder) +#if NET + public bool TryPickT2([NotNullWhen(true)] out T2? value, out OneOf remainder) +#else + public bool TryPickT2(out T2? value, out OneOf remainder) +#endif { value = IsT2 ? AsT2 : default; remainder = _index switch @@ -447,12 +461,16 @@ public bool TryPickT2(out T2 value, out OneOf AsT16, 17 => AsT17, 18 => AsT18, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT2; } - public bool TryPickT3(out T3 value, out OneOf remainder) +#if NET + public bool TryPickT3([NotNullWhen(true)] out T3? value, out OneOf remainder) +#else + public bool TryPickT3(out T3? value, out OneOf remainder) +#endif { value = IsT3 ? AsT3 : default; remainder = _index switch @@ -476,12 +494,16 @@ public bool TryPickT3(out T3 value, out OneOf AsT16, 17 => AsT17, 18 => AsT18, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT3; } - public bool TryPickT4(out T4 value, out OneOf remainder) +#if NET + public bool TryPickT4([NotNullWhen(true)] out T4? value, out OneOf remainder) +#else + public bool TryPickT4(out T4? value, out OneOf remainder) +#endif { value = IsT4 ? AsT4 : default; remainder = _index switch @@ -505,12 +527,16 @@ public bool TryPickT4(out T4 value, out OneOf AsT16, 17 => AsT17, 18 => AsT18, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT4; } - public bool TryPickT5(out T5 value, out OneOf remainder) +#if NET + public bool TryPickT5([NotNullWhen(true)] out T5? value, out OneOf remainder) +#else + public bool TryPickT5(out T5? value, out OneOf remainder) +#endif { value = IsT5 ? AsT5 : default; remainder = _index switch @@ -534,12 +560,16 @@ public bool TryPickT5(out T5 value, out OneOf AsT16, 17 => AsT17, 18 => AsT18, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT5; } - public bool TryPickT6(out T6 value, out OneOf remainder) +#if NET + public bool TryPickT6([NotNullWhen(true)] out T6? value, out OneOf remainder) +#else + public bool TryPickT6(out T6? value, out OneOf remainder) +#endif { value = IsT6 ? AsT6 : default; remainder = _index switch @@ -563,12 +593,16 @@ public bool TryPickT6(out T6 value, out OneOf AsT16, 17 => AsT17, 18 => AsT18, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT6; } - public bool TryPickT7(out T7 value, out OneOf remainder) +#if NET + public bool TryPickT7([NotNullWhen(true)] out T7? value, out OneOf remainder) +#else + public bool TryPickT7(out T7? value, out OneOf remainder) +#endif { value = IsT7 ? AsT7 : default; remainder = _index switch @@ -592,12 +626,16 @@ public bool TryPickT7(out T7 value, out OneOf AsT16, 17 => AsT17, 18 => AsT18, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT7; } - public bool TryPickT8(out T8 value, out OneOf remainder) +#if NET + public bool TryPickT8([NotNullWhen(true)] out T8? value, out OneOf remainder) +#else + public bool TryPickT8(out T8? value, out OneOf remainder) +#endif { value = IsT8 ? AsT8 : default; remainder = _index switch @@ -621,12 +659,16 @@ public bool TryPickT8(out T8 value, out OneOf AsT16, 17 => AsT17, 18 => AsT18, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT8; } - public bool TryPickT9(out T9 value, out OneOf remainder) +#if NET + public bool TryPickT9([NotNullWhen(true)] out T9? value, out OneOf remainder) +#else + public bool TryPickT9(out T9? value, out OneOf remainder) +#endif { value = IsT9 ? AsT9 : default; remainder = _index switch @@ -650,12 +692,16 @@ public bool TryPickT9(out T9 value, out OneOf AsT16, 17 => AsT17, 18 => AsT18, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT9; } - public bool TryPickT10(out T10 value, out OneOf remainder) +#if NET + public bool TryPickT10([NotNullWhen(true)] out T10? value, out OneOf remainder) +#else + public bool TryPickT10(out T10? value, out OneOf remainder) +#endif { value = IsT10 ? AsT10 : default; remainder = _index switch @@ -679,12 +725,16 @@ public bool TryPickT10(out T10 value, out OneOf AsT16, 17 => AsT17, 18 => AsT18, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT10; } - public bool TryPickT11(out T11 value, out OneOf remainder) +#if NET + public bool TryPickT11([NotNullWhen(true)] out T11? value, out OneOf remainder) +#else + public bool TryPickT11(out T11? value, out OneOf remainder) +#endif { value = IsT11 ? AsT11 : default; remainder = _index switch @@ -708,12 +758,16 @@ public bool TryPickT11(out T11 value, out OneOf AsT16, 17 => AsT17, 18 => AsT18, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT11; } - public bool TryPickT12(out T12 value, out OneOf remainder) +#if NET + public bool TryPickT12([NotNullWhen(true)] out T12? value, out OneOf remainder) +#else + public bool TryPickT12(out T12? value, out OneOf remainder) +#endif { value = IsT12 ? AsT12 : default; remainder = _index switch @@ -737,12 +791,16 @@ public bool TryPickT12(out T12 value, out OneOf AsT16, 17 => AsT17, 18 => AsT18, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT12; } - public bool TryPickT13(out T13 value, out OneOf remainder) +#if NET + public bool TryPickT13([NotNullWhen(true)] out T13? value, out OneOf remainder) +#else + public bool TryPickT13(out T13? value, out OneOf remainder) +#endif { value = IsT13 ? AsT13 : default; remainder = _index switch @@ -766,12 +824,16 @@ public bool TryPickT13(out T13 value, out OneOf AsT16, 17 => AsT17, 18 => AsT18, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT13; } - public bool TryPickT14(out T14 value, out OneOf remainder) +#if NET + public bool TryPickT14([NotNullWhen(true)] out T14? value, out OneOf remainder) +#else + public bool TryPickT14(out T14? value, out OneOf remainder) +#endif { value = IsT14 ? AsT14 : default; remainder = _index switch @@ -795,12 +857,16 @@ public bool TryPickT14(out T14 value, out OneOf AsT16, 17 => AsT17, 18 => AsT18, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT14; } - public bool TryPickT15(out T15 value, out OneOf remainder) +#if NET + public bool TryPickT15([NotNullWhen(true)] out T15? value, out OneOf remainder) +#else + public bool TryPickT15(out T15? value, out OneOf remainder) +#endif { value = IsT15 ? AsT15 : default; remainder = _index switch @@ -824,12 +890,16 @@ public bool TryPickT15(out T15 value, out OneOf AsT16, 17 => AsT17, 18 => AsT18, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT15; } - public bool TryPickT16(out T16 value, out OneOf remainder) +#if NET + public bool TryPickT16([NotNullWhen(true)] out T16? value, out OneOf remainder) +#else + public bool TryPickT16(out T16? value, out OneOf remainder) +#endif { value = IsT16 ? AsT16 : default; remainder = _index switch @@ -853,12 +923,16 @@ public bool TryPickT16(out T16 value, out OneOf default, 17 => AsT17, 18 => AsT18, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT16; } - public bool TryPickT17(out T17 value, out OneOf remainder) +#if NET + public bool TryPickT17([NotNullWhen(true)] out T17? value, out OneOf remainder) +#else + public bool TryPickT17(out T17? value, out OneOf remainder) +#endif { value = IsT17 ? AsT17 : default; remainder = _index switch @@ -882,12 +956,16 @@ public bool TryPickT17(out T17 value, out OneOf AsT16, 17 => default, 18 => AsT18, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT17; } - public bool TryPickT18(out T18 value, out OneOf remainder) +#if NET + public bool TryPickT18([NotNullWhen(true)] out T18? value, out OneOf remainder) +#else + public bool TryPickT18(out T18? value, out OneOf remainder) +#endif { value = IsT18 ? AsT18 : default; remainder = _index switch @@ -911,7 +989,7 @@ public bool TryPickT18(out T18 value, out OneOf AsT16, 17 => AsT17, 18 => default, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT18; } @@ -942,7 +1020,7 @@ bool Equals(OneOfBase false }; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/OneOf.Extended/OneOfBaseT19.generated.cs b/OneOf.Extended/OneOfBaseT19.generated.cs index 76a2c60..a0bb542 100644 --- a/OneOf.Extended/OneOfBaseT19.generated.cs +++ b/OneOf.Extended/OneOfBaseT19.generated.cs @@ -1,30 +1,32 @@ +#nullable enable using System; +using System.Diagnostics.CodeAnalysis; using static OneOf.Functions; namespace OneOf { public class OneOfBase : IOneOf { - readonly T0 _value0; - readonly T1 _value1; - readonly T2 _value2; - readonly T3 _value3; - readonly T4 _value4; - readonly T5 _value5; - readonly T6 _value6; - readonly T7 _value7; - readonly T8 _value8; - readonly T9 _value9; - readonly T10 _value10; - readonly T11 _value11; - readonly T12 _value12; - readonly T13 _value13; - readonly T14 _value14; - readonly T15 _value15; - readonly T16 _value16; - readonly T17 _value17; - readonly T18 _value18; - readonly T19 _value19; + readonly T0 _value0 = default!; + readonly T1 _value1 = default!; + readonly T2 _value2 = default!; + readonly T3 _value3 = default!; + readonly T4 _value4 = default!; + readonly T5 _value5 = default!; + readonly T6 _value6 = default!; + readonly T7 _value7 = default!; + readonly T8 _value8 = default!; + readonly T9 _value9 = default!; + readonly T10 _value10 = default!; + readonly T11 _value11 = default!; + readonly T12 _value12 = default!; + readonly T13 _value13 = default!; + readonly T14 _value14 = default!; + readonly T15 _value15 = default!; + readonly T16 _value16 = default!; + readonly T17 _value17 = default!; + readonly T18 _value18 = default!; + readonly T19 _value19 = default!; readonly int _index; protected OneOfBase(OneOf input) @@ -52,11 +54,11 @@ protected OneOfBase(OneOf + public object? Value => _index switch { 0 => _value0, @@ -79,7 +81,7 @@ protected OneOfBase(OneOf _value17, 18 => _value18, 19 => _value19, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; public int Index => _index; @@ -290,7 +292,7 @@ public void Switch(Action f0, Action f1, Action f2, Action f3, A f19(_value19); return; } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } public TResult Match(Func f0, Func f1, Func f2, Func f3, Func f4, Func f5, Func f6, Func f7, Func f8, Func f9, Func f10, Func f11, Func f12, Func f13, Func f14, Func f15, Func f16, Func f17, Func f18, Func f19) @@ -375,14 +377,18 @@ public TResult Match(Func f0, Func f1, Func remainder) +#if NET + public bool TryPickT0([NotNullWhen(true)] out T0? value, out OneOf remainder) +#else + public bool TryPickT0(out T0? value, out OneOf remainder) +#endif { value = IsT0 ? AsT0 : default; remainder = _index switch @@ -407,12 +413,16 @@ public bool TryPickT0(out T0 value, out OneOf AsT17, 18 => AsT18, 19 => AsT19, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT0; } - public bool TryPickT1(out T1 value, out OneOf remainder) +#if NET + public bool TryPickT1([NotNullWhen(true)] out T1? value, out OneOf remainder) +#else + public bool TryPickT1(out T1? value, out OneOf remainder) +#endif { value = IsT1 ? AsT1 : default; remainder = _index switch @@ -437,12 +447,16 @@ public bool TryPickT1(out T1 value, out OneOf AsT17, 18 => AsT18, 19 => AsT19, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT1; } - public bool TryPickT2(out T2 value, out OneOf remainder) +#if NET + public bool TryPickT2([NotNullWhen(true)] out T2? value, out OneOf remainder) +#else + public bool TryPickT2(out T2? value, out OneOf remainder) +#endif { value = IsT2 ? AsT2 : default; remainder = _index switch @@ -467,12 +481,16 @@ public bool TryPickT2(out T2 value, out OneOf AsT17, 18 => AsT18, 19 => AsT19, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT2; } - public bool TryPickT3(out T3 value, out OneOf remainder) +#if NET + public bool TryPickT3([NotNullWhen(true)] out T3? value, out OneOf remainder) +#else + public bool TryPickT3(out T3? value, out OneOf remainder) +#endif { value = IsT3 ? AsT3 : default; remainder = _index switch @@ -497,12 +515,16 @@ public bool TryPickT3(out T3 value, out OneOf AsT17, 18 => AsT18, 19 => AsT19, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT3; } - public bool TryPickT4(out T4 value, out OneOf remainder) +#if NET + public bool TryPickT4([NotNullWhen(true)] out T4? value, out OneOf remainder) +#else + public bool TryPickT4(out T4? value, out OneOf remainder) +#endif { value = IsT4 ? AsT4 : default; remainder = _index switch @@ -527,12 +549,16 @@ public bool TryPickT4(out T4 value, out OneOf AsT17, 18 => AsT18, 19 => AsT19, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT4; } - public bool TryPickT5(out T5 value, out OneOf remainder) +#if NET + public bool TryPickT5([NotNullWhen(true)] out T5? value, out OneOf remainder) +#else + public bool TryPickT5(out T5? value, out OneOf remainder) +#endif { value = IsT5 ? AsT5 : default; remainder = _index switch @@ -557,12 +583,16 @@ public bool TryPickT5(out T5 value, out OneOf AsT17, 18 => AsT18, 19 => AsT19, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT5; } - public bool TryPickT6(out T6 value, out OneOf remainder) +#if NET + public bool TryPickT6([NotNullWhen(true)] out T6? value, out OneOf remainder) +#else + public bool TryPickT6(out T6? value, out OneOf remainder) +#endif { value = IsT6 ? AsT6 : default; remainder = _index switch @@ -587,12 +617,16 @@ public bool TryPickT6(out T6 value, out OneOf AsT17, 18 => AsT18, 19 => AsT19, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT6; } - public bool TryPickT7(out T7 value, out OneOf remainder) +#if NET + public bool TryPickT7([NotNullWhen(true)] out T7? value, out OneOf remainder) +#else + public bool TryPickT7(out T7? value, out OneOf remainder) +#endif { value = IsT7 ? AsT7 : default; remainder = _index switch @@ -617,12 +651,16 @@ public bool TryPickT7(out T7 value, out OneOf AsT17, 18 => AsT18, 19 => AsT19, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT7; } - public bool TryPickT8(out T8 value, out OneOf remainder) +#if NET + public bool TryPickT8([NotNullWhen(true)] out T8? value, out OneOf remainder) +#else + public bool TryPickT8(out T8? value, out OneOf remainder) +#endif { value = IsT8 ? AsT8 : default; remainder = _index switch @@ -647,12 +685,16 @@ public bool TryPickT8(out T8 value, out OneOf AsT17, 18 => AsT18, 19 => AsT19, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT8; } - public bool TryPickT9(out T9 value, out OneOf remainder) +#if NET + public bool TryPickT9([NotNullWhen(true)] out T9? value, out OneOf remainder) +#else + public bool TryPickT9(out T9? value, out OneOf remainder) +#endif { value = IsT9 ? AsT9 : default; remainder = _index switch @@ -677,12 +719,16 @@ public bool TryPickT9(out T9 value, out OneOf AsT17, 18 => AsT18, 19 => AsT19, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT9; } - public bool TryPickT10(out T10 value, out OneOf remainder) +#if NET + public bool TryPickT10([NotNullWhen(true)] out T10? value, out OneOf remainder) +#else + public bool TryPickT10(out T10? value, out OneOf remainder) +#endif { value = IsT10 ? AsT10 : default; remainder = _index switch @@ -707,12 +753,16 @@ public bool TryPickT10(out T10 value, out OneOf AsT17, 18 => AsT18, 19 => AsT19, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT10; } - public bool TryPickT11(out T11 value, out OneOf remainder) +#if NET + public bool TryPickT11([NotNullWhen(true)] out T11? value, out OneOf remainder) +#else + public bool TryPickT11(out T11? value, out OneOf remainder) +#endif { value = IsT11 ? AsT11 : default; remainder = _index switch @@ -737,12 +787,16 @@ public bool TryPickT11(out T11 value, out OneOf AsT17, 18 => AsT18, 19 => AsT19, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT11; } - public bool TryPickT12(out T12 value, out OneOf remainder) +#if NET + public bool TryPickT12([NotNullWhen(true)] out T12? value, out OneOf remainder) +#else + public bool TryPickT12(out T12? value, out OneOf remainder) +#endif { value = IsT12 ? AsT12 : default; remainder = _index switch @@ -767,12 +821,16 @@ public bool TryPickT12(out T12 value, out OneOf AsT17, 18 => AsT18, 19 => AsT19, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT12; } - public bool TryPickT13(out T13 value, out OneOf remainder) +#if NET + public bool TryPickT13([NotNullWhen(true)] out T13? value, out OneOf remainder) +#else + public bool TryPickT13(out T13? value, out OneOf remainder) +#endif { value = IsT13 ? AsT13 : default; remainder = _index switch @@ -797,12 +855,16 @@ public bool TryPickT13(out T13 value, out OneOf AsT17, 18 => AsT18, 19 => AsT19, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT13; } - public bool TryPickT14(out T14 value, out OneOf remainder) +#if NET + public bool TryPickT14([NotNullWhen(true)] out T14? value, out OneOf remainder) +#else + public bool TryPickT14(out T14? value, out OneOf remainder) +#endif { value = IsT14 ? AsT14 : default; remainder = _index switch @@ -827,12 +889,16 @@ public bool TryPickT14(out T14 value, out OneOf AsT17, 18 => AsT18, 19 => AsT19, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT14; } - public bool TryPickT15(out T15 value, out OneOf remainder) +#if NET + public bool TryPickT15([NotNullWhen(true)] out T15? value, out OneOf remainder) +#else + public bool TryPickT15(out T15? value, out OneOf remainder) +#endif { value = IsT15 ? AsT15 : default; remainder = _index switch @@ -857,12 +923,16 @@ public bool TryPickT15(out T15 value, out OneOf AsT17, 18 => AsT18, 19 => AsT19, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT15; } - public bool TryPickT16(out T16 value, out OneOf remainder) +#if NET + public bool TryPickT16([NotNullWhen(true)] out T16? value, out OneOf remainder) +#else + public bool TryPickT16(out T16? value, out OneOf remainder) +#endif { value = IsT16 ? AsT16 : default; remainder = _index switch @@ -887,12 +957,16 @@ public bool TryPickT16(out T16 value, out OneOf AsT17, 18 => AsT18, 19 => AsT19, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT16; } - public bool TryPickT17(out T17 value, out OneOf remainder) +#if NET + public bool TryPickT17([NotNullWhen(true)] out T17? value, out OneOf remainder) +#else + public bool TryPickT17(out T17? value, out OneOf remainder) +#endif { value = IsT17 ? AsT17 : default; remainder = _index switch @@ -917,12 +991,16 @@ public bool TryPickT17(out T17 value, out OneOf default, 18 => AsT18, 19 => AsT19, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT17; } - public bool TryPickT18(out T18 value, out OneOf remainder) +#if NET + public bool TryPickT18([NotNullWhen(true)] out T18? value, out OneOf remainder) +#else + public bool TryPickT18(out T18? value, out OneOf remainder) +#endif { value = IsT18 ? AsT18 : default; remainder = _index switch @@ -947,12 +1025,16 @@ public bool TryPickT18(out T18 value, out OneOf AsT17, 18 => default, 19 => AsT19, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT18; } - public bool TryPickT19(out T19 value, out OneOf remainder) +#if NET + public bool TryPickT19([NotNullWhen(true)] out T19? value, out OneOf remainder) +#else + public bool TryPickT19(out T19? value, out OneOf remainder) +#endif { value = IsT19 ? AsT19 : default; remainder = _index switch @@ -977,7 +1059,7 @@ public bool TryPickT19(out T19 value, out OneOf AsT17, 18 => AsT18, 19 => default, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT19; } @@ -1009,7 +1091,7 @@ bool Equals(OneOfBase false }; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/OneOf.Extended/OneOfBaseT20.generated.cs b/OneOf.Extended/OneOfBaseT20.generated.cs index 7f69d8f..b70360b 100644 --- a/OneOf.Extended/OneOfBaseT20.generated.cs +++ b/OneOf.Extended/OneOfBaseT20.generated.cs @@ -1,31 +1,33 @@ +#nullable enable using System; +using System.Diagnostics.CodeAnalysis; using static OneOf.Functions; namespace OneOf { public class OneOfBase : IOneOf { - readonly T0 _value0; - readonly T1 _value1; - readonly T2 _value2; - readonly T3 _value3; - readonly T4 _value4; - readonly T5 _value5; - readonly T6 _value6; - readonly T7 _value7; - readonly T8 _value8; - readonly T9 _value9; - readonly T10 _value10; - readonly T11 _value11; - readonly T12 _value12; - readonly T13 _value13; - readonly T14 _value14; - readonly T15 _value15; - readonly T16 _value16; - readonly T17 _value17; - readonly T18 _value18; - readonly T19 _value19; - readonly T20 _value20; + readonly T0 _value0 = default!; + readonly T1 _value1 = default!; + readonly T2 _value2 = default!; + readonly T3 _value3 = default!; + readonly T4 _value4 = default!; + readonly T5 _value5 = default!; + readonly T6 _value6 = default!; + readonly T7 _value7 = default!; + readonly T8 _value8 = default!; + readonly T9 _value9 = default!; + readonly T10 _value10 = default!; + readonly T11 _value11 = default!; + readonly T12 _value12 = default!; + readonly T13 _value13 = default!; + readonly T14 _value14 = default!; + readonly T15 _value15 = default!; + readonly T16 _value16 = default!; + readonly T17 _value17 = default!; + readonly T18 _value18 = default!; + readonly T19 _value19 = default!; + readonly T20 _value20 = default!; readonly int _index; protected OneOfBase(OneOf input) @@ -54,11 +56,11 @@ protected OneOfBase(OneOf + public object? Value => _index switch { 0 => _value0, @@ -82,7 +84,7 @@ protected OneOfBase(OneOf _value18, 19 => _value19, 20 => _value20, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; public int Index => _index; @@ -303,7 +305,7 @@ public void Switch(Action f0, Action f1, Action f2, Action f3, A f20(_value20); return; } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } public TResult Match(Func f0, Func f1, Func f2, Func f3, Func f4, Func f5, Func f6, Func f7, Func f8, Func f9, Func f10, Func f11, Func f12, Func f13, Func f14, Func f15, Func f16, Func f17, Func f18, Func f19, Func f20) @@ -392,14 +394,18 @@ public TResult Match(Func f0, Func f1, Func remainder) +#if NET + public bool TryPickT0([NotNullWhen(true)] out T0? value, out OneOf remainder) +#else + public bool TryPickT0(out T0? value, out OneOf remainder) +#endif { value = IsT0 ? AsT0 : default; remainder = _index switch @@ -425,12 +431,16 @@ public bool TryPickT0(out T0 value, out OneOf AsT18, 19 => AsT19, 20 => AsT20, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT0; } - public bool TryPickT1(out T1 value, out OneOf remainder) +#if NET + public bool TryPickT1([NotNullWhen(true)] out T1? value, out OneOf remainder) +#else + public bool TryPickT1(out T1? value, out OneOf remainder) +#endif { value = IsT1 ? AsT1 : default; remainder = _index switch @@ -456,12 +466,16 @@ public bool TryPickT1(out T1 value, out OneOf AsT18, 19 => AsT19, 20 => AsT20, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT1; } - public bool TryPickT2(out T2 value, out OneOf remainder) +#if NET + public bool TryPickT2([NotNullWhen(true)] out T2? value, out OneOf remainder) +#else + public bool TryPickT2(out T2? value, out OneOf remainder) +#endif { value = IsT2 ? AsT2 : default; remainder = _index switch @@ -487,12 +501,16 @@ public bool TryPickT2(out T2 value, out OneOf AsT18, 19 => AsT19, 20 => AsT20, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT2; } - public bool TryPickT3(out T3 value, out OneOf remainder) +#if NET + public bool TryPickT3([NotNullWhen(true)] out T3? value, out OneOf remainder) +#else + public bool TryPickT3(out T3? value, out OneOf remainder) +#endif { value = IsT3 ? AsT3 : default; remainder = _index switch @@ -518,12 +536,16 @@ public bool TryPickT3(out T3 value, out OneOf AsT18, 19 => AsT19, 20 => AsT20, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT3; } - public bool TryPickT4(out T4 value, out OneOf remainder) +#if NET + public bool TryPickT4([NotNullWhen(true)] out T4? value, out OneOf remainder) +#else + public bool TryPickT4(out T4? value, out OneOf remainder) +#endif { value = IsT4 ? AsT4 : default; remainder = _index switch @@ -549,12 +571,16 @@ public bool TryPickT4(out T4 value, out OneOf AsT18, 19 => AsT19, 20 => AsT20, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT4; } - public bool TryPickT5(out T5 value, out OneOf remainder) +#if NET + public bool TryPickT5([NotNullWhen(true)] out T5? value, out OneOf remainder) +#else + public bool TryPickT5(out T5? value, out OneOf remainder) +#endif { value = IsT5 ? AsT5 : default; remainder = _index switch @@ -580,12 +606,16 @@ public bool TryPickT5(out T5 value, out OneOf AsT18, 19 => AsT19, 20 => AsT20, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT5; } - public bool TryPickT6(out T6 value, out OneOf remainder) +#if NET + public bool TryPickT6([NotNullWhen(true)] out T6? value, out OneOf remainder) +#else + public bool TryPickT6(out T6? value, out OneOf remainder) +#endif { value = IsT6 ? AsT6 : default; remainder = _index switch @@ -611,12 +641,16 @@ public bool TryPickT6(out T6 value, out OneOf AsT18, 19 => AsT19, 20 => AsT20, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT6; } - public bool TryPickT7(out T7 value, out OneOf remainder) +#if NET + public bool TryPickT7([NotNullWhen(true)] out T7? value, out OneOf remainder) +#else + public bool TryPickT7(out T7? value, out OneOf remainder) +#endif { value = IsT7 ? AsT7 : default; remainder = _index switch @@ -642,12 +676,16 @@ public bool TryPickT7(out T7 value, out OneOf AsT18, 19 => AsT19, 20 => AsT20, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT7; } - public bool TryPickT8(out T8 value, out OneOf remainder) +#if NET + public bool TryPickT8([NotNullWhen(true)] out T8? value, out OneOf remainder) +#else + public bool TryPickT8(out T8? value, out OneOf remainder) +#endif { value = IsT8 ? AsT8 : default; remainder = _index switch @@ -673,12 +711,16 @@ public bool TryPickT8(out T8 value, out OneOf AsT18, 19 => AsT19, 20 => AsT20, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT8; } - public bool TryPickT9(out T9 value, out OneOf remainder) +#if NET + public bool TryPickT9([NotNullWhen(true)] out T9? value, out OneOf remainder) +#else + public bool TryPickT9(out T9? value, out OneOf remainder) +#endif { value = IsT9 ? AsT9 : default; remainder = _index switch @@ -704,12 +746,16 @@ public bool TryPickT9(out T9 value, out OneOf AsT18, 19 => AsT19, 20 => AsT20, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT9; } - public bool TryPickT10(out T10 value, out OneOf remainder) +#if NET + public bool TryPickT10([NotNullWhen(true)] out T10? value, out OneOf remainder) +#else + public bool TryPickT10(out T10? value, out OneOf remainder) +#endif { value = IsT10 ? AsT10 : default; remainder = _index switch @@ -735,12 +781,16 @@ public bool TryPickT10(out T10 value, out OneOf AsT18, 19 => AsT19, 20 => AsT20, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT10; } - public bool TryPickT11(out T11 value, out OneOf remainder) +#if NET + public bool TryPickT11([NotNullWhen(true)] out T11? value, out OneOf remainder) +#else + public bool TryPickT11(out T11? value, out OneOf remainder) +#endif { value = IsT11 ? AsT11 : default; remainder = _index switch @@ -766,12 +816,16 @@ public bool TryPickT11(out T11 value, out OneOf AsT18, 19 => AsT19, 20 => AsT20, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT11; } - public bool TryPickT12(out T12 value, out OneOf remainder) +#if NET + public bool TryPickT12([NotNullWhen(true)] out T12? value, out OneOf remainder) +#else + public bool TryPickT12(out T12? value, out OneOf remainder) +#endif { value = IsT12 ? AsT12 : default; remainder = _index switch @@ -797,12 +851,16 @@ public bool TryPickT12(out T12 value, out OneOf AsT18, 19 => AsT19, 20 => AsT20, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT12; } - public bool TryPickT13(out T13 value, out OneOf remainder) +#if NET + public bool TryPickT13([NotNullWhen(true)] out T13? value, out OneOf remainder) +#else + public bool TryPickT13(out T13? value, out OneOf remainder) +#endif { value = IsT13 ? AsT13 : default; remainder = _index switch @@ -828,12 +886,16 @@ public bool TryPickT13(out T13 value, out OneOf AsT18, 19 => AsT19, 20 => AsT20, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT13; } - public bool TryPickT14(out T14 value, out OneOf remainder) +#if NET + public bool TryPickT14([NotNullWhen(true)] out T14? value, out OneOf remainder) +#else + public bool TryPickT14(out T14? value, out OneOf remainder) +#endif { value = IsT14 ? AsT14 : default; remainder = _index switch @@ -859,12 +921,16 @@ public bool TryPickT14(out T14 value, out OneOf AsT18, 19 => AsT19, 20 => AsT20, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT14; } - public bool TryPickT15(out T15 value, out OneOf remainder) +#if NET + public bool TryPickT15([NotNullWhen(true)] out T15? value, out OneOf remainder) +#else + public bool TryPickT15(out T15? value, out OneOf remainder) +#endif { value = IsT15 ? AsT15 : default; remainder = _index switch @@ -890,12 +956,16 @@ public bool TryPickT15(out T15 value, out OneOf AsT18, 19 => AsT19, 20 => AsT20, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT15; } - public bool TryPickT16(out T16 value, out OneOf remainder) +#if NET + public bool TryPickT16([NotNullWhen(true)] out T16? value, out OneOf remainder) +#else + public bool TryPickT16(out T16? value, out OneOf remainder) +#endif { value = IsT16 ? AsT16 : default; remainder = _index switch @@ -921,12 +991,16 @@ public bool TryPickT16(out T16 value, out OneOf AsT18, 19 => AsT19, 20 => AsT20, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT16; } - public bool TryPickT17(out T17 value, out OneOf remainder) +#if NET + public bool TryPickT17([NotNullWhen(true)] out T17? value, out OneOf remainder) +#else + public bool TryPickT17(out T17? value, out OneOf remainder) +#endif { value = IsT17 ? AsT17 : default; remainder = _index switch @@ -952,12 +1026,16 @@ public bool TryPickT17(out T17 value, out OneOf AsT18, 19 => AsT19, 20 => AsT20, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT17; } - public bool TryPickT18(out T18 value, out OneOf remainder) +#if NET + public bool TryPickT18([NotNullWhen(true)] out T18? value, out OneOf remainder) +#else + public bool TryPickT18(out T18? value, out OneOf remainder) +#endif { value = IsT18 ? AsT18 : default; remainder = _index switch @@ -983,12 +1061,16 @@ public bool TryPickT18(out T18 value, out OneOf default, 19 => AsT19, 20 => AsT20, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT18; } - public bool TryPickT19(out T19 value, out OneOf remainder) +#if NET + public bool TryPickT19([NotNullWhen(true)] out T19? value, out OneOf remainder) +#else + public bool TryPickT19(out T19? value, out OneOf remainder) +#endif { value = IsT19 ? AsT19 : default; remainder = _index switch @@ -1014,12 +1096,16 @@ public bool TryPickT19(out T19 value, out OneOf AsT18, 19 => default, 20 => AsT20, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT19; } - public bool TryPickT20(out T20 value, out OneOf remainder) +#if NET + public bool TryPickT20([NotNullWhen(true)] out T20? value, out OneOf remainder) +#else + public bool TryPickT20(out T20? value, out OneOf remainder) +#endif { value = IsT20 ? AsT20 : default; remainder = _index switch @@ -1045,7 +1131,7 @@ public bool TryPickT20(out T20 value, out OneOf AsT18, 19 => AsT19, 20 => default, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT20; } @@ -1078,7 +1164,7 @@ bool Equals(OneOfBase false }; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/OneOf.Extended/OneOfBaseT21.generated.cs b/OneOf.Extended/OneOfBaseT21.generated.cs index a6b02ee..a97ebc5 100644 --- a/OneOf.Extended/OneOfBaseT21.generated.cs +++ b/OneOf.Extended/OneOfBaseT21.generated.cs @@ -1,32 +1,34 @@ +#nullable enable using System; +using System.Diagnostics.CodeAnalysis; using static OneOf.Functions; namespace OneOf { public class OneOfBase : IOneOf { - readonly T0 _value0; - readonly T1 _value1; - readonly T2 _value2; - readonly T3 _value3; - readonly T4 _value4; - readonly T5 _value5; - readonly T6 _value6; - readonly T7 _value7; - readonly T8 _value8; - readonly T9 _value9; - readonly T10 _value10; - readonly T11 _value11; - readonly T12 _value12; - readonly T13 _value13; - readonly T14 _value14; - readonly T15 _value15; - readonly T16 _value16; - readonly T17 _value17; - readonly T18 _value18; - readonly T19 _value19; - readonly T20 _value20; - readonly T21 _value21; + readonly T0 _value0 = default!; + readonly T1 _value1 = default!; + readonly T2 _value2 = default!; + readonly T3 _value3 = default!; + readonly T4 _value4 = default!; + readonly T5 _value5 = default!; + readonly T6 _value6 = default!; + readonly T7 _value7 = default!; + readonly T8 _value8 = default!; + readonly T9 _value9 = default!; + readonly T10 _value10 = default!; + readonly T11 _value11 = default!; + readonly T12 _value12 = default!; + readonly T13 _value13 = default!; + readonly T14 _value14 = default!; + readonly T15 _value15 = default!; + readonly T16 _value16 = default!; + readonly T17 _value17 = default!; + readonly T18 _value18 = default!; + readonly T19 _value19 = default!; + readonly T20 _value20 = default!; + readonly T21 _value21 = default!; readonly int _index; protected OneOfBase(OneOf input) @@ -56,11 +58,11 @@ protected OneOfBase(OneOf + public object? Value => _index switch { 0 => _value0, @@ -85,7 +87,7 @@ protected OneOfBase(OneOf _value19, 20 => _value20, 21 => _value21, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; public int Index => _index; @@ -316,7 +318,7 @@ public void Switch(Action f0, Action f1, Action f2, Action f3, A f21(_value21); return; } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } public TResult Match(Func f0, Func f1, Func f2, Func f3, Func f4, Func f5, Func f6, Func f7, Func f8, Func f9, Func f10, Func f11, Func f12, Func f13, Func f14, Func f15, Func f16, Func f17, Func f18, Func f19, Func f20, Func f21) @@ -409,14 +411,18 @@ public TResult Match(Func f0, Func f1, Func remainder) +#if NET + public bool TryPickT0([NotNullWhen(true)] out T0? value, out OneOf remainder) +#else + public bool TryPickT0(out T0? value, out OneOf remainder) +#endif { value = IsT0 ? AsT0 : default; remainder = _index switch @@ -443,12 +449,16 @@ public bool TryPickT0(out T0 value, out OneOf AsT19, 20 => AsT20, 21 => AsT21, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT0; } - public bool TryPickT1(out T1 value, out OneOf remainder) +#if NET + public bool TryPickT1([NotNullWhen(true)] out T1? value, out OneOf remainder) +#else + public bool TryPickT1(out T1? value, out OneOf remainder) +#endif { value = IsT1 ? AsT1 : default; remainder = _index switch @@ -475,12 +485,16 @@ public bool TryPickT1(out T1 value, out OneOf AsT19, 20 => AsT20, 21 => AsT21, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT1; } - public bool TryPickT2(out T2 value, out OneOf remainder) +#if NET + public bool TryPickT2([NotNullWhen(true)] out T2? value, out OneOf remainder) +#else + public bool TryPickT2(out T2? value, out OneOf remainder) +#endif { value = IsT2 ? AsT2 : default; remainder = _index switch @@ -507,12 +521,16 @@ public bool TryPickT2(out T2 value, out OneOf AsT19, 20 => AsT20, 21 => AsT21, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT2; } - public bool TryPickT3(out T3 value, out OneOf remainder) +#if NET + public bool TryPickT3([NotNullWhen(true)] out T3? value, out OneOf remainder) +#else + public bool TryPickT3(out T3? value, out OneOf remainder) +#endif { value = IsT3 ? AsT3 : default; remainder = _index switch @@ -539,12 +557,16 @@ public bool TryPickT3(out T3 value, out OneOf AsT19, 20 => AsT20, 21 => AsT21, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT3; } - public bool TryPickT4(out T4 value, out OneOf remainder) +#if NET + public bool TryPickT4([NotNullWhen(true)] out T4? value, out OneOf remainder) +#else + public bool TryPickT4(out T4? value, out OneOf remainder) +#endif { value = IsT4 ? AsT4 : default; remainder = _index switch @@ -571,12 +593,16 @@ public bool TryPickT4(out T4 value, out OneOf AsT19, 20 => AsT20, 21 => AsT21, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT4; } - public bool TryPickT5(out T5 value, out OneOf remainder) +#if NET + public bool TryPickT5([NotNullWhen(true)] out T5? value, out OneOf remainder) +#else + public bool TryPickT5(out T5? value, out OneOf remainder) +#endif { value = IsT5 ? AsT5 : default; remainder = _index switch @@ -603,12 +629,16 @@ public bool TryPickT5(out T5 value, out OneOf AsT19, 20 => AsT20, 21 => AsT21, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT5; } - public bool TryPickT6(out T6 value, out OneOf remainder) +#if NET + public bool TryPickT6([NotNullWhen(true)] out T6? value, out OneOf remainder) +#else + public bool TryPickT6(out T6? value, out OneOf remainder) +#endif { value = IsT6 ? AsT6 : default; remainder = _index switch @@ -635,12 +665,16 @@ public bool TryPickT6(out T6 value, out OneOf AsT19, 20 => AsT20, 21 => AsT21, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT6; } - public bool TryPickT7(out T7 value, out OneOf remainder) +#if NET + public bool TryPickT7([NotNullWhen(true)] out T7? value, out OneOf remainder) +#else + public bool TryPickT7(out T7? value, out OneOf remainder) +#endif { value = IsT7 ? AsT7 : default; remainder = _index switch @@ -667,12 +701,16 @@ public bool TryPickT7(out T7 value, out OneOf AsT19, 20 => AsT20, 21 => AsT21, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT7; } - public bool TryPickT8(out T8 value, out OneOf remainder) +#if NET + public bool TryPickT8([NotNullWhen(true)] out T8? value, out OneOf remainder) +#else + public bool TryPickT8(out T8? value, out OneOf remainder) +#endif { value = IsT8 ? AsT8 : default; remainder = _index switch @@ -699,12 +737,16 @@ public bool TryPickT8(out T8 value, out OneOf AsT19, 20 => AsT20, 21 => AsT21, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT8; } - public bool TryPickT9(out T9 value, out OneOf remainder) +#if NET + public bool TryPickT9([NotNullWhen(true)] out T9? value, out OneOf remainder) +#else + public bool TryPickT9(out T9? value, out OneOf remainder) +#endif { value = IsT9 ? AsT9 : default; remainder = _index switch @@ -731,12 +773,16 @@ public bool TryPickT9(out T9 value, out OneOf AsT19, 20 => AsT20, 21 => AsT21, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT9; } - public bool TryPickT10(out T10 value, out OneOf remainder) +#if NET + public bool TryPickT10([NotNullWhen(true)] out T10? value, out OneOf remainder) +#else + public bool TryPickT10(out T10? value, out OneOf remainder) +#endif { value = IsT10 ? AsT10 : default; remainder = _index switch @@ -763,12 +809,16 @@ public bool TryPickT10(out T10 value, out OneOf AsT19, 20 => AsT20, 21 => AsT21, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT10; } - public bool TryPickT11(out T11 value, out OneOf remainder) +#if NET + public bool TryPickT11([NotNullWhen(true)] out T11? value, out OneOf remainder) +#else + public bool TryPickT11(out T11? value, out OneOf remainder) +#endif { value = IsT11 ? AsT11 : default; remainder = _index switch @@ -795,12 +845,16 @@ public bool TryPickT11(out T11 value, out OneOf AsT19, 20 => AsT20, 21 => AsT21, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT11; } - public bool TryPickT12(out T12 value, out OneOf remainder) +#if NET + public bool TryPickT12([NotNullWhen(true)] out T12? value, out OneOf remainder) +#else + public bool TryPickT12(out T12? value, out OneOf remainder) +#endif { value = IsT12 ? AsT12 : default; remainder = _index switch @@ -827,12 +881,16 @@ public bool TryPickT12(out T12 value, out OneOf AsT19, 20 => AsT20, 21 => AsT21, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT12; } - public bool TryPickT13(out T13 value, out OneOf remainder) +#if NET + public bool TryPickT13([NotNullWhen(true)] out T13? value, out OneOf remainder) +#else + public bool TryPickT13(out T13? value, out OneOf remainder) +#endif { value = IsT13 ? AsT13 : default; remainder = _index switch @@ -859,12 +917,16 @@ public bool TryPickT13(out T13 value, out OneOf AsT19, 20 => AsT20, 21 => AsT21, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT13; } - public bool TryPickT14(out T14 value, out OneOf remainder) +#if NET + public bool TryPickT14([NotNullWhen(true)] out T14? value, out OneOf remainder) +#else + public bool TryPickT14(out T14? value, out OneOf remainder) +#endif { value = IsT14 ? AsT14 : default; remainder = _index switch @@ -891,12 +953,16 @@ public bool TryPickT14(out T14 value, out OneOf AsT19, 20 => AsT20, 21 => AsT21, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT14; } - public bool TryPickT15(out T15 value, out OneOf remainder) +#if NET + public bool TryPickT15([NotNullWhen(true)] out T15? value, out OneOf remainder) +#else + public bool TryPickT15(out T15? value, out OneOf remainder) +#endif { value = IsT15 ? AsT15 : default; remainder = _index switch @@ -923,12 +989,16 @@ public bool TryPickT15(out T15 value, out OneOf AsT19, 20 => AsT20, 21 => AsT21, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT15; } - public bool TryPickT16(out T16 value, out OneOf remainder) +#if NET + public bool TryPickT16([NotNullWhen(true)] out T16? value, out OneOf remainder) +#else + public bool TryPickT16(out T16? value, out OneOf remainder) +#endif { value = IsT16 ? AsT16 : default; remainder = _index switch @@ -955,12 +1025,16 @@ public bool TryPickT16(out T16 value, out OneOf AsT19, 20 => AsT20, 21 => AsT21, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT16; } - public bool TryPickT17(out T17 value, out OneOf remainder) +#if NET + public bool TryPickT17([NotNullWhen(true)] out T17? value, out OneOf remainder) +#else + public bool TryPickT17(out T17? value, out OneOf remainder) +#endif { value = IsT17 ? AsT17 : default; remainder = _index switch @@ -987,12 +1061,16 @@ public bool TryPickT17(out T17 value, out OneOf AsT19, 20 => AsT20, 21 => AsT21, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT17; } - public bool TryPickT18(out T18 value, out OneOf remainder) +#if NET + public bool TryPickT18([NotNullWhen(true)] out T18? value, out OneOf remainder) +#else + public bool TryPickT18(out T18? value, out OneOf remainder) +#endif { value = IsT18 ? AsT18 : default; remainder = _index switch @@ -1019,12 +1097,16 @@ public bool TryPickT18(out T18 value, out OneOf AsT19, 20 => AsT20, 21 => AsT21, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT18; } - public bool TryPickT19(out T19 value, out OneOf remainder) +#if NET + public bool TryPickT19([NotNullWhen(true)] out T19? value, out OneOf remainder) +#else + public bool TryPickT19(out T19? value, out OneOf remainder) +#endif { value = IsT19 ? AsT19 : default; remainder = _index switch @@ -1051,12 +1133,16 @@ public bool TryPickT19(out T19 value, out OneOf default, 20 => AsT20, 21 => AsT21, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT19; } - public bool TryPickT20(out T20 value, out OneOf remainder) +#if NET + public bool TryPickT20([NotNullWhen(true)] out T20? value, out OneOf remainder) +#else + public bool TryPickT20(out T20? value, out OneOf remainder) +#endif { value = IsT20 ? AsT20 : default; remainder = _index switch @@ -1083,12 +1169,16 @@ public bool TryPickT20(out T20 value, out OneOf AsT19, 20 => default, 21 => AsT21, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT20; } - public bool TryPickT21(out T21 value, out OneOf remainder) +#if NET + public bool TryPickT21([NotNullWhen(true)] out T21? value, out OneOf remainder) +#else + public bool TryPickT21(out T21? value, out OneOf remainder) +#endif { value = IsT21 ? AsT21 : default; remainder = _index switch @@ -1115,7 +1205,7 @@ public bool TryPickT21(out T21 value, out OneOf AsT19, 20 => AsT20, 21 => default, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT21; } @@ -1149,7 +1239,7 @@ bool Equals(OneOfBase false }; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/OneOf.Extended/OneOfBaseT22.generated.cs b/OneOf.Extended/OneOfBaseT22.generated.cs index daca4ef..df7e6a9 100644 --- a/OneOf.Extended/OneOfBaseT22.generated.cs +++ b/OneOf.Extended/OneOfBaseT22.generated.cs @@ -1,33 +1,35 @@ +#nullable enable using System; +using System.Diagnostics.CodeAnalysis; using static OneOf.Functions; namespace OneOf { public class OneOfBase : IOneOf { - readonly T0 _value0; - readonly T1 _value1; - readonly T2 _value2; - readonly T3 _value3; - readonly T4 _value4; - readonly T5 _value5; - readonly T6 _value6; - readonly T7 _value7; - readonly T8 _value8; - readonly T9 _value9; - readonly T10 _value10; - readonly T11 _value11; - readonly T12 _value12; - readonly T13 _value13; - readonly T14 _value14; - readonly T15 _value15; - readonly T16 _value16; - readonly T17 _value17; - readonly T18 _value18; - readonly T19 _value19; - readonly T20 _value20; - readonly T21 _value21; - readonly T22 _value22; + readonly T0 _value0 = default!; + readonly T1 _value1 = default!; + readonly T2 _value2 = default!; + readonly T3 _value3 = default!; + readonly T4 _value4 = default!; + readonly T5 _value5 = default!; + readonly T6 _value6 = default!; + readonly T7 _value7 = default!; + readonly T8 _value8 = default!; + readonly T9 _value9 = default!; + readonly T10 _value10 = default!; + readonly T11 _value11 = default!; + readonly T12 _value12 = default!; + readonly T13 _value13 = default!; + readonly T14 _value14 = default!; + readonly T15 _value15 = default!; + readonly T16 _value16 = default!; + readonly T17 _value17 = default!; + readonly T18 _value18 = default!; + readonly T19 _value19 = default!; + readonly T20 _value20 = default!; + readonly T21 _value21 = default!; + readonly T22 _value22 = default!; readonly int _index; protected OneOfBase(OneOf input) @@ -58,11 +60,11 @@ protected OneOfBase(OneOf + public object? Value => _index switch { 0 => _value0, @@ -88,7 +90,7 @@ protected OneOfBase(OneOf _value20, 21 => _value21, 22 => _value22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; public int Index => _index; @@ -329,7 +331,7 @@ public void Switch(Action f0, Action f1, Action f2, Action f3, A f22(_value22); return; } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } public TResult Match(Func f0, Func f1, Func f2, Func f3, Func f4, Func f5, Func f6, Func f7, Func f8, Func f9, Func f10, Func f11, Func f12, Func f13, Func f14, Func f15, Func f16, Func f17, Func f18, Func f19, Func f20, Func f21, Func f22) @@ -426,14 +428,18 @@ public TResult Match(Func f0, Func f1, Func remainder) +#if NET + public bool TryPickT0([NotNullWhen(true)] out T0? value, out OneOf remainder) +#else + public bool TryPickT0(out T0? value, out OneOf remainder) +#endif { value = IsT0 ? AsT0 : default; remainder = _index switch @@ -461,12 +467,16 @@ public bool TryPickT0(out T0 value, out OneOf AsT20, 21 => AsT21, 22 => AsT22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT0; } - public bool TryPickT1(out T1 value, out OneOf remainder) +#if NET + public bool TryPickT1([NotNullWhen(true)] out T1? value, out OneOf remainder) +#else + public bool TryPickT1(out T1? value, out OneOf remainder) +#endif { value = IsT1 ? AsT1 : default; remainder = _index switch @@ -494,12 +504,16 @@ public bool TryPickT1(out T1 value, out OneOf AsT20, 21 => AsT21, 22 => AsT22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT1; } - public bool TryPickT2(out T2 value, out OneOf remainder) +#if NET + public bool TryPickT2([NotNullWhen(true)] out T2? value, out OneOf remainder) +#else + public bool TryPickT2(out T2? value, out OneOf remainder) +#endif { value = IsT2 ? AsT2 : default; remainder = _index switch @@ -527,12 +541,16 @@ public bool TryPickT2(out T2 value, out OneOf AsT20, 21 => AsT21, 22 => AsT22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT2; } - public bool TryPickT3(out T3 value, out OneOf remainder) +#if NET + public bool TryPickT3([NotNullWhen(true)] out T3? value, out OneOf remainder) +#else + public bool TryPickT3(out T3? value, out OneOf remainder) +#endif { value = IsT3 ? AsT3 : default; remainder = _index switch @@ -560,12 +578,16 @@ public bool TryPickT3(out T3 value, out OneOf AsT20, 21 => AsT21, 22 => AsT22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT3; } - public bool TryPickT4(out T4 value, out OneOf remainder) +#if NET + public bool TryPickT4([NotNullWhen(true)] out T4? value, out OneOf remainder) +#else + public bool TryPickT4(out T4? value, out OneOf remainder) +#endif { value = IsT4 ? AsT4 : default; remainder = _index switch @@ -593,12 +615,16 @@ public bool TryPickT4(out T4 value, out OneOf AsT20, 21 => AsT21, 22 => AsT22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT4; } - public bool TryPickT5(out T5 value, out OneOf remainder) +#if NET + public bool TryPickT5([NotNullWhen(true)] out T5? value, out OneOf remainder) +#else + public bool TryPickT5(out T5? value, out OneOf remainder) +#endif { value = IsT5 ? AsT5 : default; remainder = _index switch @@ -626,12 +652,16 @@ public bool TryPickT5(out T5 value, out OneOf AsT20, 21 => AsT21, 22 => AsT22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT5; } - public bool TryPickT6(out T6 value, out OneOf remainder) +#if NET + public bool TryPickT6([NotNullWhen(true)] out T6? value, out OneOf remainder) +#else + public bool TryPickT6(out T6? value, out OneOf remainder) +#endif { value = IsT6 ? AsT6 : default; remainder = _index switch @@ -659,12 +689,16 @@ public bool TryPickT6(out T6 value, out OneOf AsT20, 21 => AsT21, 22 => AsT22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT6; } - public bool TryPickT7(out T7 value, out OneOf remainder) +#if NET + public bool TryPickT7([NotNullWhen(true)] out T7? value, out OneOf remainder) +#else + public bool TryPickT7(out T7? value, out OneOf remainder) +#endif { value = IsT7 ? AsT7 : default; remainder = _index switch @@ -692,12 +726,16 @@ public bool TryPickT7(out T7 value, out OneOf AsT20, 21 => AsT21, 22 => AsT22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT7; } - public bool TryPickT8(out T8 value, out OneOf remainder) +#if NET + public bool TryPickT8([NotNullWhen(true)] out T8? value, out OneOf remainder) +#else + public bool TryPickT8(out T8? value, out OneOf remainder) +#endif { value = IsT8 ? AsT8 : default; remainder = _index switch @@ -725,12 +763,16 @@ public bool TryPickT8(out T8 value, out OneOf AsT20, 21 => AsT21, 22 => AsT22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT8; } - public bool TryPickT9(out T9 value, out OneOf remainder) +#if NET + public bool TryPickT9([NotNullWhen(true)] out T9? value, out OneOf remainder) +#else + public bool TryPickT9(out T9? value, out OneOf remainder) +#endif { value = IsT9 ? AsT9 : default; remainder = _index switch @@ -758,12 +800,16 @@ public bool TryPickT9(out T9 value, out OneOf AsT20, 21 => AsT21, 22 => AsT22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT9; } - public bool TryPickT10(out T10 value, out OneOf remainder) +#if NET + public bool TryPickT10([NotNullWhen(true)] out T10? value, out OneOf remainder) +#else + public bool TryPickT10(out T10? value, out OneOf remainder) +#endif { value = IsT10 ? AsT10 : default; remainder = _index switch @@ -791,12 +837,16 @@ public bool TryPickT10(out T10 value, out OneOf AsT20, 21 => AsT21, 22 => AsT22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT10; } - public bool TryPickT11(out T11 value, out OneOf remainder) +#if NET + public bool TryPickT11([NotNullWhen(true)] out T11? value, out OneOf remainder) +#else + public bool TryPickT11(out T11? value, out OneOf remainder) +#endif { value = IsT11 ? AsT11 : default; remainder = _index switch @@ -824,12 +874,16 @@ public bool TryPickT11(out T11 value, out OneOf AsT20, 21 => AsT21, 22 => AsT22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT11; } - public bool TryPickT12(out T12 value, out OneOf remainder) +#if NET + public bool TryPickT12([NotNullWhen(true)] out T12? value, out OneOf remainder) +#else + public bool TryPickT12(out T12? value, out OneOf remainder) +#endif { value = IsT12 ? AsT12 : default; remainder = _index switch @@ -857,12 +911,16 @@ public bool TryPickT12(out T12 value, out OneOf AsT20, 21 => AsT21, 22 => AsT22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT12; } - public bool TryPickT13(out T13 value, out OneOf remainder) +#if NET + public bool TryPickT13([NotNullWhen(true)] out T13? value, out OneOf remainder) +#else + public bool TryPickT13(out T13? value, out OneOf remainder) +#endif { value = IsT13 ? AsT13 : default; remainder = _index switch @@ -890,12 +948,16 @@ public bool TryPickT13(out T13 value, out OneOf AsT20, 21 => AsT21, 22 => AsT22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT13; } - public bool TryPickT14(out T14 value, out OneOf remainder) +#if NET + public bool TryPickT14([NotNullWhen(true)] out T14? value, out OneOf remainder) +#else + public bool TryPickT14(out T14? value, out OneOf remainder) +#endif { value = IsT14 ? AsT14 : default; remainder = _index switch @@ -923,12 +985,16 @@ public bool TryPickT14(out T14 value, out OneOf AsT20, 21 => AsT21, 22 => AsT22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT14; } - public bool TryPickT15(out T15 value, out OneOf remainder) +#if NET + public bool TryPickT15([NotNullWhen(true)] out T15? value, out OneOf remainder) +#else + public bool TryPickT15(out T15? value, out OneOf remainder) +#endif { value = IsT15 ? AsT15 : default; remainder = _index switch @@ -956,12 +1022,16 @@ public bool TryPickT15(out T15 value, out OneOf AsT20, 21 => AsT21, 22 => AsT22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT15; } - public bool TryPickT16(out T16 value, out OneOf remainder) +#if NET + public bool TryPickT16([NotNullWhen(true)] out T16? value, out OneOf remainder) +#else + public bool TryPickT16(out T16? value, out OneOf remainder) +#endif { value = IsT16 ? AsT16 : default; remainder = _index switch @@ -989,12 +1059,16 @@ public bool TryPickT16(out T16 value, out OneOf AsT20, 21 => AsT21, 22 => AsT22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT16; } - public bool TryPickT17(out T17 value, out OneOf remainder) +#if NET + public bool TryPickT17([NotNullWhen(true)] out T17? value, out OneOf remainder) +#else + public bool TryPickT17(out T17? value, out OneOf remainder) +#endif { value = IsT17 ? AsT17 : default; remainder = _index switch @@ -1022,12 +1096,16 @@ public bool TryPickT17(out T17 value, out OneOf AsT20, 21 => AsT21, 22 => AsT22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT17; } - public bool TryPickT18(out T18 value, out OneOf remainder) +#if NET + public bool TryPickT18([NotNullWhen(true)] out T18? value, out OneOf remainder) +#else + public bool TryPickT18(out T18? value, out OneOf remainder) +#endif { value = IsT18 ? AsT18 : default; remainder = _index switch @@ -1055,12 +1133,16 @@ public bool TryPickT18(out T18 value, out OneOf AsT20, 21 => AsT21, 22 => AsT22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT18; } - public bool TryPickT19(out T19 value, out OneOf remainder) +#if NET + public bool TryPickT19([NotNullWhen(true)] out T19? value, out OneOf remainder) +#else + public bool TryPickT19(out T19? value, out OneOf remainder) +#endif { value = IsT19 ? AsT19 : default; remainder = _index switch @@ -1088,12 +1170,16 @@ public bool TryPickT19(out T19 value, out OneOf AsT20, 21 => AsT21, 22 => AsT22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT19; } - public bool TryPickT20(out T20 value, out OneOf remainder) +#if NET + public bool TryPickT20([NotNullWhen(true)] out T20? value, out OneOf remainder) +#else + public bool TryPickT20(out T20? value, out OneOf remainder) +#endif { value = IsT20 ? AsT20 : default; remainder = _index switch @@ -1121,12 +1207,16 @@ public bool TryPickT20(out T20 value, out OneOf default, 21 => AsT21, 22 => AsT22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT20; } - public bool TryPickT21(out T21 value, out OneOf remainder) +#if NET + public bool TryPickT21([NotNullWhen(true)] out T21? value, out OneOf remainder) +#else + public bool TryPickT21(out T21? value, out OneOf remainder) +#endif { value = IsT21 ? AsT21 : default; remainder = _index switch @@ -1154,12 +1244,16 @@ public bool TryPickT21(out T21 value, out OneOf AsT20, 21 => default, 22 => AsT22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT21; } - public bool TryPickT22(out T22 value, out OneOf remainder) +#if NET + public bool TryPickT22([NotNullWhen(true)] out T22? value, out OneOf remainder) +#else + public bool TryPickT22(out T22? value, out OneOf remainder) +#endif { value = IsT22 ? AsT22 : default; remainder = _index switch @@ -1187,7 +1281,7 @@ public bool TryPickT22(out T22 value, out OneOf AsT20, 21 => AsT21, 22 => default, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT22; } @@ -1222,7 +1316,7 @@ bool Equals(OneOfBase false }; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/OneOf.Extended/OneOfBaseT23.generated.cs b/OneOf.Extended/OneOfBaseT23.generated.cs index 78a26b5..9eb35c7 100644 --- a/OneOf.Extended/OneOfBaseT23.generated.cs +++ b/OneOf.Extended/OneOfBaseT23.generated.cs @@ -1,34 +1,36 @@ +#nullable enable using System; +using System.Diagnostics.CodeAnalysis; using static OneOf.Functions; namespace OneOf { public class OneOfBase : IOneOf { - readonly T0 _value0; - readonly T1 _value1; - readonly T2 _value2; - readonly T3 _value3; - readonly T4 _value4; - readonly T5 _value5; - readonly T6 _value6; - readonly T7 _value7; - readonly T8 _value8; - readonly T9 _value9; - readonly T10 _value10; - readonly T11 _value11; - readonly T12 _value12; - readonly T13 _value13; - readonly T14 _value14; - readonly T15 _value15; - readonly T16 _value16; - readonly T17 _value17; - readonly T18 _value18; - readonly T19 _value19; - readonly T20 _value20; - readonly T21 _value21; - readonly T22 _value22; - readonly T23 _value23; + readonly T0 _value0 = default!; + readonly T1 _value1 = default!; + readonly T2 _value2 = default!; + readonly T3 _value3 = default!; + readonly T4 _value4 = default!; + readonly T5 _value5 = default!; + readonly T6 _value6 = default!; + readonly T7 _value7 = default!; + readonly T8 _value8 = default!; + readonly T9 _value9 = default!; + readonly T10 _value10 = default!; + readonly T11 _value11 = default!; + readonly T12 _value12 = default!; + readonly T13 _value13 = default!; + readonly T14 _value14 = default!; + readonly T15 _value15 = default!; + readonly T16 _value16 = default!; + readonly T17 _value17 = default!; + readonly T18 _value18 = default!; + readonly T19 _value19 = default!; + readonly T20 _value20 = default!; + readonly T21 _value21 = default!; + readonly T22 _value22 = default!; + readonly T23 _value23 = default!; readonly int _index; protected OneOfBase(OneOf input) @@ -60,11 +62,11 @@ protected OneOfBase(OneOf + public object? Value => _index switch { 0 => _value0, @@ -91,7 +93,7 @@ protected OneOfBase(OneOf _value21, 22 => _value22, 23 => _value23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; public int Index => _index; @@ -342,7 +344,7 @@ public void Switch(Action f0, Action f1, Action f2, Action f3, A f23(_value23); return; } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } public TResult Match(Func f0, Func f1, Func f2, Func f3, Func f4, Func f5, Func f6, Func f7, Func f8, Func f9, Func f10, Func f11, Func f12, Func f13, Func f14, Func f15, Func f16, Func f17, Func f18, Func f19, Func f20, Func f21, Func f22, Func f23) @@ -443,14 +445,18 @@ public TResult Match(Func f0, Func f1, Func remainder) +#if NET + public bool TryPickT0([NotNullWhen(true)] out T0? value, out OneOf remainder) +#else + public bool TryPickT0(out T0? value, out OneOf remainder) +#endif { value = IsT0 ? AsT0 : default; remainder = _index switch @@ -479,12 +485,16 @@ public bool TryPickT0(out T0 value, out OneOf AsT21, 22 => AsT22, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT0; } - public bool TryPickT1(out T1 value, out OneOf remainder) +#if NET + public bool TryPickT1([NotNullWhen(true)] out T1? value, out OneOf remainder) +#else + public bool TryPickT1(out T1? value, out OneOf remainder) +#endif { value = IsT1 ? AsT1 : default; remainder = _index switch @@ -513,12 +523,16 @@ public bool TryPickT1(out T1 value, out OneOf AsT21, 22 => AsT22, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT1; } - public bool TryPickT2(out T2 value, out OneOf remainder) +#if NET + public bool TryPickT2([NotNullWhen(true)] out T2? value, out OneOf remainder) +#else + public bool TryPickT2(out T2? value, out OneOf remainder) +#endif { value = IsT2 ? AsT2 : default; remainder = _index switch @@ -547,12 +561,16 @@ public bool TryPickT2(out T2 value, out OneOf AsT21, 22 => AsT22, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT2; } - public bool TryPickT3(out T3 value, out OneOf remainder) +#if NET + public bool TryPickT3([NotNullWhen(true)] out T3? value, out OneOf remainder) +#else + public bool TryPickT3(out T3? value, out OneOf remainder) +#endif { value = IsT3 ? AsT3 : default; remainder = _index switch @@ -581,12 +599,16 @@ public bool TryPickT3(out T3 value, out OneOf AsT21, 22 => AsT22, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT3; } - public bool TryPickT4(out T4 value, out OneOf remainder) +#if NET + public bool TryPickT4([NotNullWhen(true)] out T4? value, out OneOf remainder) +#else + public bool TryPickT4(out T4? value, out OneOf remainder) +#endif { value = IsT4 ? AsT4 : default; remainder = _index switch @@ -615,12 +637,16 @@ public bool TryPickT4(out T4 value, out OneOf AsT21, 22 => AsT22, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT4; } - public bool TryPickT5(out T5 value, out OneOf remainder) +#if NET + public bool TryPickT5([NotNullWhen(true)] out T5? value, out OneOf remainder) +#else + public bool TryPickT5(out T5? value, out OneOf remainder) +#endif { value = IsT5 ? AsT5 : default; remainder = _index switch @@ -649,12 +675,16 @@ public bool TryPickT5(out T5 value, out OneOf AsT21, 22 => AsT22, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT5; } - public bool TryPickT6(out T6 value, out OneOf remainder) +#if NET + public bool TryPickT6([NotNullWhen(true)] out T6? value, out OneOf remainder) +#else + public bool TryPickT6(out T6? value, out OneOf remainder) +#endif { value = IsT6 ? AsT6 : default; remainder = _index switch @@ -683,12 +713,16 @@ public bool TryPickT6(out T6 value, out OneOf AsT21, 22 => AsT22, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT6; } - public bool TryPickT7(out T7 value, out OneOf remainder) +#if NET + public bool TryPickT7([NotNullWhen(true)] out T7? value, out OneOf remainder) +#else + public bool TryPickT7(out T7? value, out OneOf remainder) +#endif { value = IsT7 ? AsT7 : default; remainder = _index switch @@ -717,12 +751,16 @@ public bool TryPickT7(out T7 value, out OneOf AsT21, 22 => AsT22, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT7; } - public bool TryPickT8(out T8 value, out OneOf remainder) +#if NET + public bool TryPickT8([NotNullWhen(true)] out T8? value, out OneOf remainder) +#else + public bool TryPickT8(out T8? value, out OneOf remainder) +#endif { value = IsT8 ? AsT8 : default; remainder = _index switch @@ -751,12 +789,16 @@ public bool TryPickT8(out T8 value, out OneOf AsT21, 22 => AsT22, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT8; } - public bool TryPickT9(out T9 value, out OneOf remainder) +#if NET + public bool TryPickT9([NotNullWhen(true)] out T9? value, out OneOf remainder) +#else + public bool TryPickT9(out T9? value, out OneOf remainder) +#endif { value = IsT9 ? AsT9 : default; remainder = _index switch @@ -785,12 +827,16 @@ public bool TryPickT9(out T9 value, out OneOf AsT21, 22 => AsT22, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT9; } - public bool TryPickT10(out T10 value, out OneOf remainder) +#if NET + public bool TryPickT10([NotNullWhen(true)] out T10? value, out OneOf remainder) +#else + public bool TryPickT10(out T10? value, out OneOf remainder) +#endif { value = IsT10 ? AsT10 : default; remainder = _index switch @@ -819,12 +865,16 @@ public bool TryPickT10(out T10 value, out OneOf AsT21, 22 => AsT22, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT10; } - public bool TryPickT11(out T11 value, out OneOf remainder) +#if NET + public bool TryPickT11([NotNullWhen(true)] out T11? value, out OneOf remainder) +#else + public bool TryPickT11(out T11? value, out OneOf remainder) +#endif { value = IsT11 ? AsT11 : default; remainder = _index switch @@ -853,12 +903,16 @@ public bool TryPickT11(out T11 value, out OneOf AsT21, 22 => AsT22, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT11; } - public bool TryPickT12(out T12 value, out OneOf remainder) +#if NET + public bool TryPickT12([NotNullWhen(true)] out T12? value, out OneOf remainder) +#else + public bool TryPickT12(out T12? value, out OneOf remainder) +#endif { value = IsT12 ? AsT12 : default; remainder = _index switch @@ -887,12 +941,16 @@ public bool TryPickT12(out T12 value, out OneOf AsT21, 22 => AsT22, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT12; } - public bool TryPickT13(out T13 value, out OneOf remainder) +#if NET + public bool TryPickT13([NotNullWhen(true)] out T13? value, out OneOf remainder) +#else + public bool TryPickT13(out T13? value, out OneOf remainder) +#endif { value = IsT13 ? AsT13 : default; remainder = _index switch @@ -921,12 +979,16 @@ public bool TryPickT13(out T13 value, out OneOf AsT21, 22 => AsT22, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT13; } - public bool TryPickT14(out T14 value, out OneOf remainder) +#if NET + public bool TryPickT14([NotNullWhen(true)] out T14? value, out OneOf remainder) +#else + public bool TryPickT14(out T14? value, out OneOf remainder) +#endif { value = IsT14 ? AsT14 : default; remainder = _index switch @@ -955,12 +1017,16 @@ public bool TryPickT14(out T14 value, out OneOf AsT21, 22 => AsT22, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT14; } - public bool TryPickT15(out T15 value, out OneOf remainder) +#if NET + public bool TryPickT15([NotNullWhen(true)] out T15? value, out OneOf remainder) +#else + public bool TryPickT15(out T15? value, out OneOf remainder) +#endif { value = IsT15 ? AsT15 : default; remainder = _index switch @@ -989,12 +1055,16 @@ public bool TryPickT15(out T15 value, out OneOf AsT21, 22 => AsT22, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT15; } - public bool TryPickT16(out T16 value, out OneOf remainder) +#if NET + public bool TryPickT16([NotNullWhen(true)] out T16? value, out OneOf remainder) +#else + public bool TryPickT16(out T16? value, out OneOf remainder) +#endif { value = IsT16 ? AsT16 : default; remainder = _index switch @@ -1023,12 +1093,16 @@ public bool TryPickT16(out T16 value, out OneOf AsT21, 22 => AsT22, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT16; } - public bool TryPickT17(out T17 value, out OneOf remainder) +#if NET + public bool TryPickT17([NotNullWhen(true)] out T17? value, out OneOf remainder) +#else + public bool TryPickT17(out T17? value, out OneOf remainder) +#endif { value = IsT17 ? AsT17 : default; remainder = _index switch @@ -1057,12 +1131,16 @@ public bool TryPickT17(out T17 value, out OneOf AsT21, 22 => AsT22, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT17; } - public bool TryPickT18(out T18 value, out OneOf remainder) +#if NET + public bool TryPickT18([NotNullWhen(true)] out T18? value, out OneOf remainder) +#else + public bool TryPickT18(out T18? value, out OneOf remainder) +#endif { value = IsT18 ? AsT18 : default; remainder = _index switch @@ -1091,12 +1169,16 @@ public bool TryPickT18(out T18 value, out OneOf AsT21, 22 => AsT22, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT18; } - public bool TryPickT19(out T19 value, out OneOf remainder) +#if NET + public bool TryPickT19([NotNullWhen(true)] out T19? value, out OneOf remainder) +#else + public bool TryPickT19(out T19? value, out OneOf remainder) +#endif { value = IsT19 ? AsT19 : default; remainder = _index switch @@ -1125,12 +1207,16 @@ public bool TryPickT19(out T19 value, out OneOf AsT21, 22 => AsT22, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT19; } - public bool TryPickT20(out T20 value, out OneOf remainder) +#if NET + public bool TryPickT20([NotNullWhen(true)] out T20? value, out OneOf remainder) +#else + public bool TryPickT20(out T20? value, out OneOf remainder) +#endif { value = IsT20 ? AsT20 : default; remainder = _index switch @@ -1159,12 +1245,16 @@ public bool TryPickT20(out T20 value, out OneOf AsT21, 22 => AsT22, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT20; } - public bool TryPickT21(out T21 value, out OneOf remainder) +#if NET + public bool TryPickT21([NotNullWhen(true)] out T21? value, out OneOf remainder) +#else + public bool TryPickT21(out T21? value, out OneOf remainder) +#endif { value = IsT21 ? AsT21 : default; remainder = _index switch @@ -1193,12 +1283,16 @@ public bool TryPickT21(out T21 value, out OneOf default, 22 => AsT22, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT21; } - public bool TryPickT22(out T22 value, out OneOf remainder) +#if NET + public bool TryPickT22([NotNullWhen(true)] out T22? value, out OneOf remainder) +#else + public bool TryPickT22(out T22? value, out OneOf remainder) +#endif { value = IsT22 ? AsT22 : default; remainder = _index switch @@ -1227,12 +1321,16 @@ public bool TryPickT22(out T22 value, out OneOf AsT21, 22 => default, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT22; } - public bool TryPickT23(out T23 value, out OneOf remainder) +#if NET + public bool TryPickT23([NotNullWhen(true)] out T23? value, out OneOf remainder) +#else + public bool TryPickT23(out T23? value, out OneOf remainder) +#endif { value = IsT23 ? AsT23 : default; remainder = _index switch @@ -1261,7 +1359,7 @@ public bool TryPickT23(out T23 value, out OneOf AsT21, 22 => AsT22, 23 => default, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT23; } @@ -1297,7 +1395,7 @@ bool Equals(OneOfBase false }; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/OneOf.Extended/OneOfBaseT24.generated.cs b/OneOf.Extended/OneOfBaseT24.generated.cs index c291a10..17f9eaf 100644 --- a/OneOf.Extended/OneOfBaseT24.generated.cs +++ b/OneOf.Extended/OneOfBaseT24.generated.cs @@ -1,35 +1,37 @@ +#nullable enable using System; +using System.Diagnostics.CodeAnalysis; using static OneOf.Functions; namespace OneOf { public class OneOfBase : IOneOf { - readonly T0 _value0; - readonly T1 _value1; - readonly T2 _value2; - readonly T3 _value3; - readonly T4 _value4; - readonly T5 _value5; - readonly T6 _value6; - readonly T7 _value7; - readonly T8 _value8; - readonly T9 _value9; - readonly T10 _value10; - readonly T11 _value11; - readonly T12 _value12; - readonly T13 _value13; - readonly T14 _value14; - readonly T15 _value15; - readonly T16 _value16; - readonly T17 _value17; - readonly T18 _value18; - readonly T19 _value19; - readonly T20 _value20; - readonly T21 _value21; - readonly T22 _value22; - readonly T23 _value23; - readonly T24 _value24; + readonly T0 _value0 = default!; + readonly T1 _value1 = default!; + readonly T2 _value2 = default!; + readonly T3 _value3 = default!; + readonly T4 _value4 = default!; + readonly T5 _value5 = default!; + readonly T6 _value6 = default!; + readonly T7 _value7 = default!; + readonly T8 _value8 = default!; + readonly T9 _value9 = default!; + readonly T10 _value10 = default!; + readonly T11 _value11 = default!; + readonly T12 _value12 = default!; + readonly T13 _value13 = default!; + readonly T14 _value14 = default!; + readonly T15 _value15 = default!; + readonly T16 _value16 = default!; + readonly T17 _value17 = default!; + readonly T18 _value18 = default!; + readonly T19 _value19 = default!; + readonly T20 _value20 = default!; + readonly T21 _value21 = default!; + readonly T22 _value22 = default!; + readonly T23 _value23 = default!; + readonly T24 _value24 = default!; readonly int _index; protected OneOfBase(OneOf input) @@ -62,11 +64,11 @@ protected OneOfBase(OneOf + public object? Value => _index switch { 0 => _value0, @@ -94,7 +96,7 @@ protected OneOfBase(OneOf _value22, 23 => _value23, 24 => _value24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; public int Index => _index; @@ -355,7 +357,7 @@ public void Switch(Action f0, Action f1, Action f2, Action f3, A f24(_value24); return; } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } public TResult Match(Func f0, Func f1, Func f2, Func f3, Func f4, Func f5, Func f6, Func f7, Func f8, Func f9, Func f10, Func f11, Func f12, Func f13, Func f14, Func f15, Func f16, Func f17, Func f18, Func f19, Func f20, Func f21, Func f22, Func f23, Func f24) @@ -460,14 +462,18 @@ public TResult Match(Func f0, Func f1, Func remainder) +#if NET + public bool TryPickT0([NotNullWhen(true)] out T0? value, out OneOf remainder) +#else + public bool TryPickT0(out T0? value, out OneOf remainder) +#endif { value = IsT0 ? AsT0 : default; remainder = _index switch @@ -497,12 +503,16 @@ public bool TryPickT0(out T0 value, out OneOf AsT22, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT0; } - public bool TryPickT1(out T1 value, out OneOf remainder) +#if NET + public bool TryPickT1([NotNullWhen(true)] out T1? value, out OneOf remainder) +#else + public bool TryPickT1(out T1? value, out OneOf remainder) +#endif { value = IsT1 ? AsT1 : default; remainder = _index switch @@ -532,12 +542,16 @@ public bool TryPickT1(out T1 value, out OneOf AsT22, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT1; } - public bool TryPickT2(out T2 value, out OneOf remainder) +#if NET + public bool TryPickT2([NotNullWhen(true)] out T2? value, out OneOf remainder) +#else + public bool TryPickT2(out T2? value, out OneOf remainder) +#endif { value = IsT2 ? AsT2 : default; remainder = _index switch @@ -567,12 +581,16 @@ public bool TryPickT2(out T2 value, out OneOf AsT22, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT2; } - public bool TryPickT3(out T3 value, out OneOf remainder) +#if NET + public bool TryPickT3([NotNullWhen(true)] out T3? value, out OneOf remainder) +#else + public bool TryPickT3(out T3? value, out OneOf remainder) +#endif { value = IsT3 ? AsT3 : default; remainder = _index switch @@ -602,12 +620,16 @@ public bool TryPickT3(out T3 value, out OneOf AsT22, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT3; } - public bool TryPickT4(out T4 value, out OneOf remainder) +#if NET + public bool TryPickT4([NotNullWhen(true)] out T4? value, out OneOf remainder) +#else + public bool TryPickT4(out T4? value, out OneOf remainder) +#endif { value = IsT4 ? AsT4 : default; remainder = _index switch @@ -637,12 +659,16 @@ public bool TryPickT4(out T4 value, out OneOf AsT22, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT4; } - public bool TryPickT5(out T5 value, out OneOf remainder) +#if NET + public bool TryPickT5([NotNullWhen(true)] out T5? value, out OneOf remainder) +#else + public bool TryPickT5(out T5? value, out OneOf remainder) +#endif { value = IsT5 ? AsT5 : default; remainder = _index switch @@ -672,12 +698,16 @@ public bool TryPickT5(out T5 value, out OneOf AsT22, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT5; } - public bool TryPickT6(out T6 value, out OneOf remainder) +#if NET + public bool TryPickT6([NotNullWhen(true)] out T6? value, out OneOf remainder) +#else + public bool TryPickT6(out T6? value, out OneOf remainder) +#endif { value = IsT6 ? AsT6 : default; remainder = _index switch @@ -707,12 +737,16 @@ public bool TryPickT6(out T6 value, out OneOf AsT22, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT6; } - public bool TryPickT7(out T7 value, out OneOf remainder) +#if NET + public bool TryPickT7([NotNullWhen(true)] out T7? value, out OneOf remainder) +#else + public bool TryPickT7(out T7? value, out OneOf remainder) +#endif { value = IsT7 ? AsT7 : default; remainder = _index switch @@ -742,12 +776,16 @@ public bool TryPickT7(out T7 value, out OneOf AsT22, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT7; } - public bool TryPickT8(out T8 value, out OneOf remainder) +#if NET + public bool TryPickT8([NotNullWhen(true)] out T8? value, out OneOf remainder) +#else + public bool TryPickT8(out T8? value, out OneOf remainder) +#endif { value = IsT8 ? AsT8 : default; remainder = _index switch @@ -777,12 +815,16 @@ public bool TryPickT8(out T8 value, out OneOf AsT22, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT8; } - public bool TryPickT9(out T9 value, out OneOf remainder) +#if NET + public bool TryPickT9([NotNullWhen(true)] out T9? value, out OneOf remainder) +#else + public bool TryPickT9(out T9? value, out OneOf remainder) +#endif { value = IsT9 ? AsT9 : default; remainder = _index switch @@ -812,12 +854,16 @@ public bool TryPickT9(out T9 value, out OneOf AsT22, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT9; } - public bool TryPickT10(out T10 value, out OneOf remainder) +#if NET + public bool TryPickT10([NotNullWhen(true)] out T10? value, out OneOf remainder) +#else + public bool TryPickT10(out T10? value, out OneOf remainder) +#endif { value = IsT10 ? AsT10 : default; remainder = _index switch @@ -847,12 +893,16 @@ public bool TryPickT10(out T10 value, out OneOf AsT22, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT10; } - public bool TryPickT11(out T11 value, out OneOf remainder) +#if NET + public bool TryPickT11([NotNullWhen(true)] out T11? value, out OneOf remainder) +#else + public bool TryPickT11(out T11? value, out OneOf remainder) +#endif { value = IsT11 ? AsT11 : default; remainder = _index switch @@ -882,12 +932,16 @@ public bool TryPickT11(out T11 value, out OneOf AsT22, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT11; } - public bool TryPickT12(out T12 value, out OneOf remainder) +#if NET + public bool TryPickT12([NotNullWhen(true)] out T12? value, out OneOf remainder) +#else + public bool TryPickT12(out T12? value, out OneOf remainder) +#endif { value = IsT12 ? AsT12 : default; remainder = _index switch @@ -917,12 +971,16 @@ public bool TryPickT12(out T12 value, out OneOf AsT22, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT12; } - public bool TryPickT13(out T13 value, out OneOf remainder) +#if NET + public bool TryPickT13([NotNullWhen(true)] out T13? value, out OneOf remainder) +#else + public bool TryPickT13(out T13? value, out OneOf remainder) +#endif { value = IsT13 ? AsT13 : default; remainder = _index switch @@ -952,12 +1010,16 @@ public bool TryPickT13(out T13 value, out OneOf AsT22, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT13; } - public bool TryPickT14(out T14 value, out OneOf remainder) +#if NET + public bool TryPickT14([NotNullWhen(true)] out T14? value, out OneOf remainder) +#else + public bool TryPickT14(out T14? value, out OneOf remainder) +#endif { value = IsT14 ? AsT14 : default; remainder = _index switch @@ -987,12 +1049,16 @@ public bool TryPickT14(out T14 value, out OneOf AsT22, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT14; } - public bool TryPickT15(out T15 value, out OneOf remainder) +#if NET + public bool TryPickT15([NotNullWhen(true)] out T15? value, out OneOf remainder) +#else + public bool TryPickT15(out T15? value, out OneOf remainder) +#endif { value = IsT15 ? AsT15 : default; remainder = _index switch @@ -1022,12 +1088,16 @@ public bool TryPickT15(out T15 value, out OneOf AsT22, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT15; } - public bool TryPickT16(out T16 value, out OneOf remainder) +#if NET + public bool TryPickT16([NotNullWhen(true)] out T16? value, out OneOf remainder) +#else + public bool TryPickT16(out T16? value, out OneOf remainder) +#endif { value = IsT16 ? AsT16 : default; remainder = _index switch @@ -1057,12 +1127,16 @@ public bool TryPickT16(out T16 value, out OneOf AsT22, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT16; } - public bool TryPickT17(out T17 value, out OneOf remainder) +#if NET + public bool TryPickT17([NotNullWhen(true)] out T17? value, out OneOf remainder) +#else + public bool TryPickT17(out T17? value, out OneOf remainder) +#endif { value = IsT17 ? AsT17 : default; remainder = _index switch @@ -1092,12 +1166,16 @@ public bool TryPickT17(out T17 value, out OneOf AsT22, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT17; } - public bool TryPickT18(out T18 value, out OneOf remainder) +#if NET + public bool TryPickT18([NotNullWhen(true)] out T18? value, out OneOf remainder) +#else + public bool TryPickT18(out T18? value, out OneOf remainder) +#endif { value = IsT18 ? AsT18 : default; remainder = _index switch @@ -1127,12 +1205,16 @@ public bool TryPickT18(out T18 value, out OneOf AsT22, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT18; } - public bool TryPickT19(out T19 value, out OneOf remainder) +#if NET + public bool TryPickT19([NotNullWhen(true)] out T19? value, out OneOf remainder) +#else + public bool TryPickT19(out T19? value, out OneOf remainder) +#endif { value = IsT19 ? AsT19 : default; remainder = _index switch @@ -1162,12 +1244,16 @@ public bool TryPickT19(out T19 value, out OneOf AsT22, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT19; } - public bool TryPickT20(out T20 value, out OneOf remainder) +#if NET + public bool TryPickT20([NotNullWhen(true)] out T20? value, out OneOf remainder) +#else + public bool TryPickT20(out T20? value, out OneOf remainder) +#endif { value = IsT20 ? AsT20 : default; remainder = _index switch @@ -1197,12 +1283,16 @@ public bool TryPickT20(out T20 value, out OneOf AsT22, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT20; } - public bool TryPickT21(out T21 value, out OneOf remainder) +#if NET + public bool TryPickT21([NotNullWhen(true)] out T21? value, out OneOf remainder) +#else + public bool TryPickT21(out T21? value, out OneOf remainder) +#endif { value = IsT21 ? AsT21 : default; remainder = _index switch @@ -1232,12 +1322,16 @@ public bool TryPickT21(out T21 value, out OneOf AsT22, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT21; } - public bool TryPickT22(out T22 value, out OneOf remainder) +#if NET + public bool TryPickT22([NotNullWhen(true)] out T22? value, out OneOf remainder) +#else + public bool TryPickT22(out T22? value, out OneOf remainder) +#endif { value = IsT22 ? AsT22 : default; remainder = _index switch @@ -1267,12 +1361,16 @@ public bool TryPickT22(out T22 value, out OneOf default, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT22; } - public bool TryPickT23(out T23 value, out OneOf remainder) +#if NET + public bool TryPickT23([NotNullWhen(true)] out T23? value, out OneOf remainder) +#else + public bool TryPickT23(out T23? value, out OneOf remainder) +#endif { value = IsT23 ? AsT23 : default; remainder = _index switch @@ -1302,12 +1400,16 @@ public bool TryPickT23(out T23 value, out OneOf AsT22, 23 => default, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT23; } - public bool TryPickT24(out T24 value, out OneOf remainder) +#if NET + public bool TryPickT24([NotNullWhen(true)] out T24? value, out OneOf remainder) +#else + public bool TryPickT24(out T24? value, out OneOf remainder) +#endif { value = IsT24 ? AsT24 : default; remainder = _index switch @@ -1337,7 +1439,7 @@ public bool TryPickT24(out T24 value, out OneOf AsT22, 23 => AsT23, 24 => default, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT24; } @@ -1374,7 +1476,7 @@ bool Equals(OneOfBase false }; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/OneOf.Extended/OneOfBaseT25.generated.cs b/OneOf.Extended/OneOfBaseT25.generated.cs index dc06dc9..f6c2cb0 100644 --- a/OneOf.Extended/OneOfBaseT25.generated.cs +++ b/OneOf.Extended/OneOfBaseT25.generated.cs @@ -1,36 +1,38 @@ +#nullable enable using System; +using System.Diagnostics.CodeAnalysis; using static OneOf.Functions; namespace OneOf { public class OneOfBase : IOneOf { - readonly T0 _value0; - readonly T1 _value1; - readonly T2 _value2; - readonly T3 _value3; - readonly T4 _value4; - readonly T5 _value5; - readonly T6 _value6; - readonly T7 _value7; - readonly T8 _value8; - readonly T9 _value9; - readonly T10 _value10; - readonly T11 _value11; - readonly T12 _value12; - readonly T13 _value13; - readonly T14 _value14; - readonly T15 _value15; - readonly T16 _value16; - readonly T17 _value17; - readonly T18 _value18; - readonly T19 _value19; - readonly T20 _value20; - readonly T21 _value21; - readonly T22 _value22; - readonly T23 _value23; - readonly T24 _value24; - readonly T25 _value25; + readonly T0 _value0 = default!; + readonly T1 _value1 = default!; + readonly T2 _value2 = default!; + readonly T3 _value3 = default!; + readonly T4 _value4 = default!; + readonly T5 _value5 = default!; + readonly T6 _value6 = default!; + readonly T7 _value7 = default!; + readonly T8 _value8 = default!; + readonly T9 _value9 = default!; + readonly T10 _value10 = default!; + readonly T11 _value11 = default!; + readonly T12 _value12 = default!; + readonly T13 _value13 = default!; + readonly T14 _value14 = default!; + readonly T15 _value15 = default!; + readonly T16 _value16 = default!; + readonly T17 _value17 = default!; + readonly T18 _value18 = default!; + readonly T19 _value19 = default!; + readonly T20 _value20 = default!; + readonly T21 _value21 = default!; + readonly T22 _value22 = default!; + readonly T23 _value23 = default!; + readonly T24 _value24 = default!; + readonly T25 _value25 = default!; readonly int _index; protected OneOfBase(OneOf input) @@ -64,11 +66,11 @@ protected OneOfBase(OneOf + public object? Value => _index switch { 0 => _value0, @@ -97,7 +99,7 @@ protected OneOfBase(OneOf _value23, 24 => _value24, 25 => _value25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; public int Index => _index; @@ -368,7 +370,7 @@ public void Switch(Action f0, Action f1, Action f2, Action f3, A f25(_value25); return; } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } public TResult Match(Func f0, Func f1, Func f2, Func f3, Func f4, Func f5, Func f6, Func f7, Func f8, Func f9, Func f10, Func f11, Func f12, Func f13, Func f14, Func f15, Func f16, Func f17, Func f18, Func f19, Func f20, Func f21, Func f22, Func f23, Func f24, Func f25) @@ -477,14 +479,18 @@ public TResult Match(Func f0, Func f1, Func remainder) +#if NET + public bool TryPickT0([NotNullWhen(true)] out T0? value, out OneOf remainder) +#else + public bool TryPickT0(out T0? value, out OneOf remainder) +#endif { value = IsT0 ? AsT0 : default; remainder = _index switch @@ -515,12 +521,16 @@ public bool TryPickT0(out T0 value, out OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT0; } - public bool TryPickT1(out T1 value, out OneOf remainder) +#if NET + public bool TryPickT1([NotNullWhen(true)] out T1? value, out OneOf remainder) +#else + public bool TryPickT1(out T1? value, out OneOf remainder) +#endif { value = IsT1 ? AsT1 : default; remainder = _index switch @@ -551,12 +561,16 @@ public bool TryPickT1(out T1 value, out OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT1; } - public bool TryPickT2(out T2 value, out OneOf remainder) +#if NET + public bool TryPickT2([NotNullWhen(true)] out T2? value, out OneOf remainder) +#else + public bool TryPickT2(out T2? value, out OneOf remainder) +#endif { value = IsT2 ? AsT2 : default; remainder = _index switch @@ -587,12 +601,16 @@ public bool TryPickT2(out T2 value, out OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT2; } - public bool TryPickT3(out T3 value, out OneOf remainder) +#if NET + public bool TryPickT3([NotNullWhen(true)] out T3? value, out OneOf remainder) +#else + public bool TryPickT3(out T3? value, out OneOf remainder) +#endif { value = IsT3 ? AsT3 : default; remainder = _index switch @@ -623,12 +641,16 @@ public bool TryPickT3(out T3 value, out OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT3; } - public bool TryPickT4(out T4 value, out OneOf remainder) +#if NET + public bool TryPickT4([NotNullWhen(true)] out T4? value, out OneOf remainder) +#else + public bool TryPickT4(out T4? value, out OneOf remainder) +#endif { value = IsT4 ? AsT4 : default; remainder = _index switch @@ -659,12 +681,16 @@ public bool TryPickT4(out T4 value, out OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT4; } - public bool TryPickT5(out T5 value, out OneOf remainder) +#if NET + public bool TryPickT5([NotNullWhen(true)] out T5? value, out OneOf remainder) +#else + public bool TryPickT5(out T5? value, out OneOf remainder) +#endif { value = IsT5 ? AsT5 : default; remainder = _index switch @@ -695,12 +721,16 @@ public bool TryPickT5(out T5 value, out OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT5; } - public bool TryPickT6(out T6 value, out OneOf remainder) +#if NET + public bool TryPickT6([NotNullWhen(true)] out T6? value, out OneOf remainder) +#else + public bool TryPickT6(out T6? value, out OneOf remainder) +#endif { value = IsT6 ? AsT6 : default; remainder = _index switch @@ -731,12 +761,16 @@ public bool TryPickT6(out T6 value, out OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT6; } - public bool TryPickT7(out T7 value, out OneOf remainder) +#if NET + public bool TryPickT7([NotNullWhen(true)] out T7? value, out OneOf remainder) +#else + public bool TryPickT7(out T7? value, out OneOf remainder) +#endif { value = IsT7 ? AsT7 : default; remainder = _index switch @@ -767,12 +801,16 @@ public bool TryPickT7(out T7 value, out OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT7; } - public bool TryPickT8(out T8 value, out OneOf remainder) +#if NET + public bool TryPickT8([NotNullWhen(true)] out T8? value, out OneOf remainder) +#else + public bool TryPickT8(out T8? value, out OneOf remainder) +#endif { value = IsT8 ? AsT8 : default; remainder = _index switch @@ -803,12 +841,16 @@ public bool TryPickT8(out T8 value, out OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT8; } - public bool TryPickT9(out T9 value, out OneOf remainder) +#if NET + public bool TryPickT9([NotNullWhen(true)] out T9? value, out OneOf remainder) +#else + public bool TryPickT9(out T9? value, out OneOf remainder) +#endif { value = IsT9 ? AsT9 : default; remainder = _index switch @@ -839,12 +881,16 @@ public bool TryPickT9(out T9 value, out OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT9; } - public bool TryPickT10(out T10 value, out OneOf remainder) +#if NET + public bool TryPickT10([NotNullWhen(true)] out T10? value, out OneOf remainder) +#else + public bool TryPickT10(out T10? value, out OneOf remainder) +#endif { value = IsT10 ? AsT10 : default; remainder = _index switch @@ -875,12 +921,16 @@ public bool TryPickT10(out T10 value, out OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT10; } - public bool TryPickT11(out T11 value, out OneOf remainder) +#if NET + public bool TryPickT11([NotNullWhen(true)] out T11? value, out OneOf remainder) +#else + public bool TryPickT11(out T11? value, out OneOf remainder) +#endif { value = IsT11 ? AsT11 : default; remainder = _index switch @@ -911,12 +961,16 @@ public bool TryPickT11(out T11 value, out OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT11; } - public bool TryPickT12(out T12 value, out OneOf remainder) +#if NET + public bool TryPickT12([NotNullWhen(true)] out T12? value, out OneOf remainder) +#else + public bool TryPickT12(out T12? value, out OneOf remainder) +#endif { value = IsT12 ? AsT12 : default; remainder = _index switch @@ -947,12 +1001,16 @@ public bool TryPickT12(out T12 value, out OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT12; } - public bool TryPickT13(out T13 value, out OneOf remainder) +#if NET + public bool TryPickT13([NotNullWhen(true)] out T13? value, out OneOf remainder) +#else + public bool TryPickT13(out T13? value, out OneOf remainder) +#endif { value = IsT13 ? AsT13 : default; remainder = _index switch @@ -983,12 +1041,16 @@ public bool TryPickT13(out T13 value, out OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT13; } - public bool TryPickT14(out T14 value, out OneOf remainder) +#if NET + public bool TryPickT14([NotNullWhen(true)] out T14? value, out OneOf remainder) +#else + public bool TryPickT14(out T14? value, out OneOf remainder) +#endif { value = IsT14 ? AsT14 : default; remainder = _index switch @@ -1019,12 +1081,16 @@ public bool TryPickT14(out T14 value, out OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT14; } - public bool TryPickT15(out T15 value, out OneOf remainder) +#if NET + public bool TryPickT15([NotNullWhen(true)] out T15? value, out OneOf remainder) +#else + public bool TryPickT15(out T15? value, out OneOf remainder) +#endif { value = IsT15 ? AsT15 : default; remainder = _index switch @@ -1055,12 +1121,16 @@ public bool TryPickT15(out T15 value, out OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT15; } - public bool TryPickT16(out T16 value, out OneOf remainder) +#if NET + public bool TryPickT16([NotNullWhen(true)] out T16? value, out OneOf remainder) +#else + public bool TryPickT16(out T16? value, out OneOf remainder) +#endif { value = IsT16 ? AsT16 : default; remainder = _index switch @@ -1091,12 +1161,16 @@ public bool TryPickT16(out T16 value, out OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT16; } - public bool TryPickT17(out T17 value, out OneOf remainder) +#if NET + public bool TryPickT17([NotNullWhen(true)] out T17? value, out OneOf remainder) +#else + public bool TryPickT17(out T17? value, out OneOf remainder) +#endif { value = IsT17 ? AsT17 : default; remainder = _index switch @@ -1127,12 +1201,16 @@ public bool TryPickT17(out T17 value, out OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT17; } - public bool TryPickT18(out T18 value, out OneOf remainder) +#if NET + public bool TryPickT18([NotNullWhen(true)] out T18? value, out OneOf remainder) +#else + public bool TryPickT18(out T18? value, out OneOf remainder) +#endif { value = IsT18 ? AsT18 : default; remainder = _index switch @@ -1163,12 +1241,16 @@ public bool TryPickT18(out T18 value, out OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT18; } - public bool TryPickT19(out T19 value, out OneOf remainder) +#if NET + public bool TryPickT19([NotNullWhen(true)] out T19? value, out OneOf remainder) +#else + public bool TryPickT19(out T19? value, out OneOf remainder) +#endif { value = IsT19 ? AsT19 : default; remainder = _index switch @@ -1199,12 +1281,16 @@ public bool TryPickT19(out T19 value, out OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT19; } - public bool TryPickT20(out T20 value, out OneOf remainder) +#if NET + public bool TryPickT20([NotNullWhen(true)] out T20? value, out OneOf remainder) +#else + public bool TryPickT20(out T20? value, out OneOf remainder) +#endif { value = IsT20 ? AsT20 : default; remainder = _index switch @@ -1235,12 +1321,16 @@ public bool TryPickT20(out T20 value, out OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT20; } - public bool TryPickT21(out T21 value, out OneOf remainder) +#if NET + public bool TryPickT21([NotNullWhen(true)] out T21? value, out OneOf remainder) +#else + public bool TryPickT21(out T21? value, out OneOf remainder) +#endif { value = IsT21 ? AsT21 : default; remainder = _index switch @@ -1271,12 +1361,16 @@ public bool TryPickT21(out T21 value, out OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT21; } - public bool TryPickT22(out T22 value, out OneOf remainder) +#if NET + public bool TryPickT22([NotNullWhen(true)] out T22? value, out OneOf remainder) +#else + public bool TryPickT22(out T22? value, out OneOf remainder) +#endif { value = IsT22 ? AsT22 : default; remainder = _index switch @@ -1307,12 +1401,16 @@ public bool TryPickT22(out T22 value, out OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT22; } - public bool TryPickT23(out T23 value, out OneOf remainder) +#if NET + public bool TryPickT23([NotNullWhen(true)] out T23? value, out OneOf remainder) +#else + public bool TryPickT23(out T23? value, out OneOf remainder) +#endif { value = IsT23 ? AsT23 : default; remainder = _index switch @@ -1343,12 +1441,16 @@ public bool TryPickT23(out T23 value, out OneOf default, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT23; } - public bool TryPickT24(out T24 value, out OneOf remainder) +#if NET + public bool TryPickT24([NotNullWhen(true)] out T24? value, out OneOf remainder) +#else + public bool TryPickT24(out T24? value, out OneOf remainder) +#endif { value = IsT24 ? AsT24 : default; remainder = _index switch @@ -1379,12 +1481,16 @@ public bool TryPickT24(out T24 value, out OneOf AsT23, 24 => default, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT24; } - public bool TryPickT25(out T25 value, out OneOf remainder) +#if NET + public bool TryPickT25([NotNullWhen(true)] out T25? value, out OneOf remainder) +#else + public bool TryPickT25(out T25? value, out OneOf remainder) +#endif { value = IsT25 ? AsT25 : default; remainder = _index switch @@ -1415,7 +1521,7 @@ public bool TryPickT25(out T25 value, out OneOf AsT23, 24 => AsT24, 25 => default, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT25; } @@ -1453,7 +1559,7 @@ bool Equals(OneOfBase false }; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/OneOf.Extended/OneOfBaseT26.generated.cs b/OneOf.Extended/OneOfBaseT26.generated.cs index edd010b..189336c 100644 --- a/OneOf.Extended/OneOfBaseT26.generated.cs +++ b/OneOf.Extended/OneOfBaseT26.generated.cs @@ -1,37 +1,39 @@ +#nullable enable using System; +using System.Diagnostics.CodeAnalysis; using static OneOf.Functions; namespace OneOf { public class OneOfBase : IOneOf { - readonly T0 _value0; - readonly T1 _value1; - readonly T2 _value2; - readonly T3 _value3; - readonly T4 _value4; - readonly T5 _value5; - readonly T6 _value6; - readonly T7 _value7; - readonly T8 _value8; - readonly T9 _value9; - readonly T10 _value10; - readonly T11 _value11; - readonly T12 _value12; - readonly T13 _value13; - readonly T14 _value14; - readonly T15 _value15; - readonly T16 _value16; - readonly T17 _value17; - readonly T18 _value18; - readonly T19 _value19; - readonly T20 _value20; - readonly T21 _value21; - readonly T22 _value22; - readonly T23 _value23; - readonly T24 _value24; - readonly T25 _value25; - readonly T26 _value26; + readonly T0 _value0 = default!; + readonly T1 _value1 = default!; + readonly T2 _value2 = default!; + readonly T3 _value3 = default!; + readonly T4 _value4 = default!; + readonly T5 _value5 = default!; + readonly T6 _value6 = default!; + readonly T7 _value7 = default!; + readonly T8 _value8 = default!; + readonly T9 _value9 = default!; + readonly T10 _value10 = default!; + readonly T11 _value11 = default!; + readonly T12 _value12 = default!; + readonly T13 _value13 = default!; + readonly T14 _value14 = default!; + readonly T15 _value15 = default!; + readonly T16 _value16 = default!; + readonly T17 _value17 = default!; + readonly T18 _value18 = default!; + readonly T19 _value19 = default!; + readonly T20 _value20 = default!; + readonly T21 _value21 = default!; + readonly T22 _value22 = default!; + readonly T23 _value23 = default!; + readonly T24 _value24 = default!; + readonly T25 _value25 = default!; + readonly T26 _value26 = default!; readonly int _index; protected OneOfBase(OneOf input) @@ -66,11 +68,11 @@ protected OneOfBase(OneOf + public object? Value => _index switch { 0 => _value0, @@ -100,7 +102,7 @@ protected OneOfBase(OneOf _value24, 25 => _value25, 26 => _value26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; public int Index => _index; @@ -381,7 +383,7 @@ public void Switch(Action f0, Action f1, Action f2, Action f3, A f26(_value26); return; } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } public TResult Match(Func f0, Func f1, Func f2, Func f3, Func f4, Func f5, Func f6, Func f7, Func f8, Func f9, Func f10, Func f11, Func f12, Func f13, Func f14, Func f15, Func f16, Func f17, Func f18, Func f19, Func f20, Func f21, Func f22, Func f23, Func f24, Func f25, Func f26) @@ -494,14 +496,18 @@ public TResult Match(Func f0, Func f1, Func remainder) +#if NET + public bool TryPickT0([NotNullWhen(true)] out T0? value, out OneOf remainder) +#else + public bool TryPickT0(out T0? value, out OneOf remainder) +#endif { value = IsT0 ? AsT0 : default; remainder = _index switch @@ -533,12 +539,16 @@ public bool TryPickT0(out T0 value, out OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT0; } - public bool TryPickT1(out T1 value, out OneOf remainder) +#if NET + public bool TryPickT1([NotNullWhen(true)] out T1? value, out OneOf remainder) +#else + public bool TryPickT1(out T1? value, out OneOf remainder) +#endif { value = IsT1 ? AsT1 : default; remainder = _index switch @@ -570,12 +580,16 @@ public bool TryPickT1(out T1 value, out OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT1; } - public bool TryPickT2(out T2 value, out OneOf remainder) +#if NET + public bool TryPickT2([NotNullWhen(true)] out T2? value, out OneOf remainder) +#else + public bool TryPickT2(out T2? value, out OneOf remainder) +#endif { value = IsT2 ? AsT2 : default; remainder = _index switch @@ -607,12 +621,16 @@ public bool TryPickT2(out T2 value, out OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT2; } - public bool TryPickT3(out T3 value, out OneOf remainder) +#if NET + public bool TryPickT3([NotNullWhen(true)] out T3? value, out OneOf remainder) +#else + public bool TryPickT3(out T3? value, out OneOf remainder) +#endif { value = IsT3 ? AsT3 : default; remainder = _index switch @@ -644,12 +662,16 @@ public bool TryPickT3(out T3 value, out OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT3; } - public bool TryPickT4(out T4 value, out OneOf remainder) +#if NET + public bool TryPickT4([NotNullWhen(true)] out T4? value, out OneOf remainder) +#else + public bool TryPickT4(out T4? value, out OneOf remainder) +#endif { value = IsT4 ? AsT4 : default; remainder = _index switch @@ -681,12 +703,16 @@ public bool TryPickT4(out T4 value, out OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT4; } - public bool TryPickT5(out T5 value, out OneOf remainder) +#if NET + public bool TryPickT5([NotNullWhen(true)] out T5? value, out OneOf remainder) +#else + public bool TryPickT5(out T5? value, out OneOf remainder) +#endif { value = IsT5 ? AsT5 : default; remainder = _index switch @@ -718,12 +744,16 @@ public bool TryPickT5(out T5 value, out OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT5; } - public bool TryPickT6(out T6 value, out OneOf remainder) +#if NET + public bool TryPickT6([NotNullWhen(true)] out T6? value, out OneOf remainder) +#else + public bool TryPickT6(out T6? value, out OneOf remainder) +#endif { value = IsT6 ? AsT6 : default; remainder = _index switch @@ -755,12 +785,16 @@ public bool TryPickT6(out T6 value, out OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT6; } - public bool TryPickT7(out T7 value, out OneOf remainder) +#if NET + public bool TryPickT7([NotNullWhen(true)] out T7? value, out OneOf remainder) +#else + public bool TryPickT7(out T7? value, out OneOf remainder) +#endif { value = IsT7 ? AsT7 : default; remainder = _index switch @@ -792,12 +826,16 @@ public bool TryPickT7(out T7 value, out OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT7; } - public bool TryPickT8(out T8 value, out OneOf remainder) +#if NET + public bool TryPickT8([NotNullWhen(true)] out T8? value, out OneOf remainder) +#else + public bool TryPickT8(out T8? value, out OneOf remainder) +#endif { value = IsT8 ? AsT8 : default; remainder = _index switch @@ -829,12 +867,16 @@ public bool TryPickT8(out T8 value, out OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT8; } - public bool TryPickT9(out T9 value, out OneOf remainder) +#if NET + public bool TryPickT9([NotNullWhen(true)] out T9? value, out OneOf remainder) +#else + public bool TryPickT9(out T9? value, out OneOf remainder) +#endif { value = IsT9 ? AsT9 : default; remainder = _index switch @@ -866,12 +908,16 @@ public bool TryPickT9(out T9 value, out OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT9; } - public bool TryPickT10(out T10 value, out OneOf remainder) +#if NET + public bool TryPickT10([NotNullWhen(true)] out T10? value, out OneOf remainder) +#else + public bool TryPickT10(out T10? value, out OneOf remainder) +#endif { value = IsT10 ? AsT10 : default; remainder = _index switch @@ -903,12 +949,16 @@ public bool TryPickT10(out T10 value, out OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT10; } - public bool TryPickT11(out T11 value, out OneOf remainder) +#if NET + public bool TryPickT11([NotNullWhen(true)] out T11? value, out OneOf remainder) +#else + public bool TryPickT11(out T11? value, out OneOf remainder) +#endif { value = IsT11 ? AsT11 : default; remainder = _index switch @@ -940,12 +990,16 @@ public bool TryPickT11(out T11 value, out OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT11; } - public bool TryPickT12(out T12 value, out OneOf remainder) +#if NET + public bool TryPickT12([NotNullWhen(true)] out T12? value, out OneOf remainder) +#else + public bool TryPickT12(out T12? value, out OneOf remainder) +#endif { value = IsT12 ? AsT12 : default; remainder = _index switch @@ -977,12 +1031,16 @@ public bool TryPickT12(out T12 value, out OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT12; } - public bool TryPickT13(out T13 value, out OneOf remainder) +#if NET + public bool TryPickT13([NotNullWhen(true)] out T13? value, out OneOf remainder) +#else + public bool TryPickT13(out T13? value, out OneOf remainder) +#endif { value = IsT13 ? AsT13 : default; remainder = _index switch @@ -1014,12 +1072,16 @@ public bool TryPickT13(out T13 value, out OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT13; } - public bool TryPickT14(out T14 value, out OneOf remainder) +#if NET + public bool TryPickT14([NotNullWhen(true)] out T14? value, out OneOf remainder) +#else + public bool TryPickT14(out T14? value, out OneOf remainder) +#endif { value = IsT14 ? AsT14 : default; remainder = _index switch @@ -1051,12 +1113,16 @@ public bool TryPickT14(out T14 value, out OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT14; } - public bool TryPickT15(out T15 value, out OneOf remainder) +#if NET + public bool TryPickT15([NotNullWhen(true)] out T15? value, out OneOf remainder) +#else + public bool TryPickT15(out T15? value, out OneOf remainder) +#endif { value = IsT15 ? AsT15 : default; remainder = _index switch @@ -1088,12 +1154,16 @@ public bool TryPickT15(out T15 value, out OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT15; } - public bool TryPickT16(out T16 value, out OneOf remainder) +#if NET + public bool TryPickT16([NotNullWhen(true)] out T16? value, out OneOf remainder) +#else + public bool TryPickT16(out T16? value, out OneOf remainder) +#endif { value = IsT16 ? AsT16 : default; remainder = _index switch @@ -1125,12 +1195,16 @@ public bool TryPickT16(out T16 value, out OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT16; } - public bool TryPickT17(out T17 value, out OneOf remainder) +#if NET + public bool TryPickT17([NotNullWhen(true)] out T17? value, out OneOf remainder) +#else + public bool TryPickT17(out T17? value, out OneOf remainder) +#endif { value = IsT17 ? AsT17 : default; remainder = _index switch @@ -1162,12 +1236,16 @@ public bool TryPickT17(out T17 value, out OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT17; } - public bool TryPickT18(out T18 value, out OneOf remainder) +#if NET + public bool TryPickT18([NotNullWhen(true)] out T18? value, out OneOf remainder) +#else + public bool TryPickT18(out T18? value, out OneOf remainder) +#endif { value = IsT18 ? AsT18 : default; remainder = _index switch @@ -1199,12 +1277,16 @@ public bool TryPickT18(out T18 value, out OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT18; } - public bool TryPickT19(out T19 value, out OneOf remainder) +#if NET + public bool TryPickT19([NotNullWhen(true)] out T19? value, out OneOf remainder) +#else + public bool TryPickT19(out T19? value, out OneOf remainder) +#endif { value = IsT19 ? AsT19 : default; remainder = _index switch @@ -1236,12 +1318,16 @@ public bool TryPickT19(out T19 value, out OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT19; } - public bool TryPickT20(out T20 value, out OneOf remainder) +#if NET + public bool TryPickT20([NotNullWhen(true)] out T20? value, out OneOf remainder) +#else + public bool TryPickT20(out T20? value, out OneOf remainder) +#endif { value = IsT20 ? AsT20 : default; remainder = _index switch @@ -1273,12 +1359,16 @@ public bool TryPickT20(out T20 value, out OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT20; } - public bool TryPickT21(out T21 value, out OneOf remainder) +#if NET + public bool TryPickT21([NotNullWhen(true)] out T21? value, out OneOf remainder) +#else + public bool TryPickT21(out T21? value, out OneOf remainder) +#endif { value = IsT21 ? AsT21 : default; remainder = _index switch @@ -1310,12 +1400,16 @@ public bool TryPickT21(out T21 value, out OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT21; } - public bool TryPickT22(out T22 value, out OneOf remainder) +#if NET + public bool TryPickT22([NotNullWhen(true)] out T22? value, out OneOf remainder) +#else + public bool TryPickT22(out T22? value, out OneOf remainder) +#endif { value = IsT22 ? AsT22 : default; remainder = _index switch @@ -1347,12 +1441,16 @@ public bool TryPickT22(out T22 value, out OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT22; } - public bool TryPickT23(out T23 value, out OneOf remainder) +#if NET + public bool TryPickT23([NotNullWhen(true)] out T23? value, out OneOf remainder) +#else + public bool TryPickT23(out T23? value, out OneOf remainder) +#endif { value = IsT23 ? AsT23 : default; remainder = _index switch @@ -1384,12 +1482,16 @@ public bool TryPickT23(out T23 value, out OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT23; } - public bool TryPickT24(out T24 value, out OneOf remainder) +#if NET + public bool TryPickT24([NotNullWhen(true)] out T24? value, out OneOf remainder) +#else + public bool TryPickT24(out T24? value, out OneOf remainder) +#endif { value = IsT24 ? AsT24 : default; remainder = _index switch @@ -1421,12 +1523,16 @@ public bool TryPickT24(out T24 value, out OneOf default, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT24; } - public bool TryPickT25(out T25 value, out OneOf remainder) +#if NET + public bool TryPickT25([NotNullWhen(true)] out T25? value, out OneOf remainder) +#else + public bool TryPickT25(out T25? value, out OneOf remainder) +#endif { value = IsT25 ? AsT25 : default; remainder = _index switch @@ -1458,12 +1564,16 @@ public bool TryPickT25(out T25 value, out OneOf AsT24, 25 => default, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT25; } - public bool TryPickT26(out T26 value, out OneOf remainder) +#if NET + public bool TryPickT26([NotNullWhen(true)] out T26? value, out OneOf remainder) +#else + public bool TryPickT26(out T26? value, out OneOf remainder) +#endif { value = IsT26 ? AsT26 : default; remainder = _index switch @@ -1495,7 +1605,7 @@ public bool TryPickT26(out T26 value, out OneOf AsT24, 25 => AsT25, 26 => default, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT26; } @@ -1534,7 +1644,7 @@ bool Equals(OneOfBase false }; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/OneOf.Extended/OneOfBaseT27.generated.cs b/OneOf.Extended/OneOfBaseT27.generated.cs index ae54cde..984f8d1 100644 --- a/OneOf.Extended/OneOfBaseT27.generated.cs +++ b/OneOf.Extended/OneOfBaseT27.generated.cs @@ -1,38 +1,40 @@ +#nullable enable using System; +using System.Diagnostics.CodeAnalysis; using static OneOf.Functions; namespace OneOf { public class OneOfBase : IOneOf { - readonly T0 _value0; - readonly T1 _value1; - readonly T2 _value2; - readonly T3 _value3; - readonly T4 _value4; - readonly T5 _value5; - readonly T6 _value6; - readonly T7 _value7; - readonly T8 _value8; - readonly T9 _value9; - readonly T10 _value10; - readonly T11 _value11; - readonly T12 _value12; - readonly T13 _value13; - readonly T14 _value14; - readonly T15 _value15; - readonly T16 _value16; - readonly T17 _value17; - readonly T18 _value18; - readonly T19 _value19; - readonly T20 _value20; - readonly T21 _value21; - readonly T22 _value22; - readonly T23 _value23; - readonly T24 _value24; - readonly T25 _value25; - readonly T26 _value26; - readonly T27 _value27; + readonly T0 _value0 = default!; + readonly T1 _value1 = default!; + readonly T2 _value2 = default!; + readonly T3 _value3 = default!; + readonly T4 _value4 = default!; + readonly T5 _value5 = default!; + readonly T6 _value6 = default!; + readonly T7 _value7 = default!; + readonly T8 _value8 = default!; + readonly T9 _value9 = default!; + readonly T10 _value10 = default!; + readonly T11 _value11 = default!; + readonly T12 _value12 = default!; + readonly T13 _value13 = default!; + readonly T14 _value14 = default!; + readonly T15 _value15 = default!; + readonly T16 _value16 = default!; + readonly T17 _value17 = default!; + readonly T18 _value18 = default!; + readonly T19 _value19 = default!; + readonly T20 _value20 = default!; + readonly T21 _value21 = default!; + readonly T22 _value22 = default!; + readonly T23 _value23 = default!; + readonly T24 _value24 = default!; + readonly T25 _value25 = default!; + readonly T26 _value26 = default!; + readonly T27 _value27 = default!; readonly int _index; protected OneOfBase(OneOf input) @@ -68,11 +70,11 @@ protected OneOfBase(OneOf + public object? Value => _index switch { 0 => _value0, @@ -103,7 +105,7 @@ protected OneOfBase(OneOf _value25, 26 => _value26, 27 => _value27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; public int Index => _index; @@ -394,7 +396,7 @@ public void Switch(Action f0, Action f1, Action f2, Action f3, A f27(_value27); return; } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } public TResult Match(Func f0, Func f1, Func f2, Func f3, Func f4, Func f5, Func f6, Func f7, Func f8, Func f9, Func f10, Func f11, Func f12, Func f13, Func f14, Func f15, Func f16, Func f17, Func f18, Func f19, Func f20, Func f21, Func f22, Func f23, Func f24, Func f25, Func f26, Func f27) @@ -511,14 +513,18 @@ public TResult Match(Func f0, Func f1, Func remainder) +#if NET + public bool TryPickT0([NotNullWhen(true)] out T0? value, out OneOf remainder) +#else + public bool TryPickT0(out T0? value, out OneOf remainder) +#endif { value = IsT0 ? AsT0 : default; remainder = _index switch @@ -551,12 +557,16 @@ public bool TryPickT0(out T0 value, out OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT0; } - public bool TryPickT1(out T1 value, out OneOf remainder) +#if NET + public bool TryPickT1([NotNullWhen(true)] out T1? value, out OneOf remainder) +#else + public bool TryPickT1(out T1? value, out OneOf remainder) +#endif { value = IsT1 ? AsT1 : default; remainder = _index switch @@ -589,12 +599,16 @@ public bool TryPickT1(out T1 value, out OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT1; } - public bool TryPickT2(out T2 value, out OneOf remainder) +#if NET + public bool TryPickT2([NotNullWhen(true)] out T2? value, out OneOf remainder) +#else + public bool TryPickT2(out T2? value, out OneOf remainder) +#endif { value = IsT2 ? AsT2 : default; remainder = _index switch @@ -627,12 +641,16 @@ public bool TryPickT2(out T2 value, out OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT2; } - public bool TryPickT3(out T3 value, out OneOf remainder) +#if NET + public bool TryPickT3([NotNullWhen(true)] out T3? value, out OneOf remainder) +#else + public bool TryPickT3(out T3? value, out OneOf remainder) +#endif { value = IsT3 ? AsT3 : default; remainder = _index switch @@ -665,12 +683,16 @@ public bool TryPickT3(out T3 value, out OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT3; } - public bool TryPickT4(out T4 value, out OneOf remainder) +#if NET + public bool TryPickT4([NotNullWhen(true)] out T4? value, out OneOf remainder) +#else + public bool TryPickT4(out T4? value, out OneOf remainder) +#endif { value = IsT4 ? AsT4 : default; remainder = _index switch @@ -703,12 +725,16 @@ public bool TryPickT4(out T4 value, out OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT4; } - public bool TryPickT5(out T5 value, out OneOf remainder) +#if NET + public bool TryPickT5([NotNullWhen(true)] out T5? value, out OneOf remainder) +#else + public bool TryPickT5(out T5? value, out OneOf remainder) +#endif { value = IsT5 ? AsT5 : default; remainder = _index switch @@ -741,12 +767,16 @@ public bool TryPickT5(out T5 value, out OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT5; } - public bool TryPickT6(out T6 value, out OneOf remainder) +#if NET + public bool TryPickT6([NotNullWhen(true)] out T6? value, out OneOf remainder) +#else + public bool TryPickT6(out T6? value, out OneOf remainder) +#endif { value = IsT6 ? AsT6 : default; remainder = _index switch @@ -779,12 +809,16 @@ public bool TryPickT6(out T6 value, out OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT6; } - public bool TryPickT7(out T7 value, out OneOf remainder) +#if NET + public bool TryPickT7([NotNullWhen(true)] out T7? value, out OneOf remainder) +#else + public bool TryPickT7(out T7? value, out OneOf remainder) +#endif { value = IsT7 ? AsT7 : default; remainder = _index switch @@ -817,12 +851,16 @@ public bool TryPickT7(out T7 value, out OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT7; } - public bool TryPickT8(out T8 value, out OneOf remainder) +#if NET + public bool TryPickT8([NotNullWhen(true)] out T8? value, out OneOf remainder) +#else + public bool TryPickT8(out T8? value, out OneOf remainder) +#endif { value = IsT8 ? AsT8 : default; remainder = _index switch @@ -855,12 +893,16 @@ public bool TryPickT8(out T8 value, out OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT8; } - public bool TryPickT9(out T9 value, out OneOf remainder) +#if NET + public bool TryPickT9([NotNullWhen(true)] out T9? value, out OneOf remainder) +#else + public bool TryPickT9(out T9? value, out OneOf remainder) +#endif { value = IsT9 ? AsT9 : default; remainder = _index switch @@ -893,12 +935,16 @@ public bool TryPickT9(out T9 value, out OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT9; } - public bool TryPickT10(out T10 value, out OneOf remainder) +#if NET + public bool TryPickT10([NotNullWhen(true)] out T10? value, out OneOf remainder) +#else + public bool TryPickT10(out T10? value, out OneOf remainder) +#endif { value = IsT10 ? AsT10 : default; remainder = _index switch @@ -931,12 +977,16 @@ public bool TryPickT10(out T10 value, out OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT10; } - public bool TryPickT11(out T11 value, out OneOf remainder) +#if NET + public bool TryPickT11([NotNullWhen(true)] out T11? value, out OneOf remainder) +#else + public bool TryPickT11(out T11? value, out OneOf remainder) +#endif { value = IsT11 ? AsT11 : default; remainder = _index switch @@ -969,12 +1019,16 @@ public bool TryPickT11(out T11 value, out OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT11; } - public bool TryPickT12(out T12 value, out OneOf remainder) +#if NET + public bool TryPickT12([NotNullWhen(true)] out T12? value, out OneOf remainder) +#else + public bool TryPickT12(out T12? value, out OneOf remainder) +#endif { value = IsT12 ? AsT12 : default; remainder = _index switch @@ -1007,12 +1061,16 @@ public bool TryPickT12(out T12 value, out OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT12; } - public bool TryPickT13(out T13 value, out OneOf remainder) +#if NET + public bool TryPickT13([NotNullWhen(true)] out T13? value, out OneOf remainder) +#else + public bool TryPickT13(out T13? value, out OneOf remainder) +#endif { value = IsT13 ? AsT13 : default; remainder = _index switch @@ -1045,12 +1103,16 @@ public bool TryPickT13(out T13 value, out OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT13; } - public bool TryPickT14(out T14 value, out OneOf remainder) +#if NET + public bool TryPickT14([NotNullWhen(true)] out T14? value, out OneOf remainder) +#else + public bool TryPickT14(out T14? value, out OneOf remainder) +#endif { value = IsT14 ? AsT14 : default; remainder = _index switch @@ -1083,12 +1145,16 @@ public bool TryPickT14(out T14 value, out OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT14; } - public bool TryPickT15(out T15 value, out OneOf remainder) +#if NET + public bool TryPickT15([NotNullWhen(true)] out T15? value, out OneOf remainder) +#else + public bool TryPickT15(out T15? value, out OneOf remainder) +#endif { value = IsT15 ? AsT15 : default; remainder = _index switch @@ -1121,12 +1187,16 @@ public bool TryPickT15(out T15 value, out OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT15; } - public bool TryPickT16(out T16 value, out OneOf remainder) +#if NET + public bool TryPickT16([NotNullWhen(true)] out T16? value, out OneOf remainder) +#else + public bool TryPickT16(out T16? value, out OneOf remainder) +#endif { value = IsT16 ? AsT16 : default; remainder = _index switch @@ -1159,12 +1229,16 @@ public bool TryPickT16(out T16 value, out OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT16; } - public bool TryPickT17(out T17 value, out OneOf remainder) +#if NET + public bool TryPickT17([NotNullWhen(true)] out T17? value, out OneOf remainder) +#else + public bool TryPickT17(out T17? value, out OneOf remainder) +#endif { value = IsT17 ? AsT17 : default; remainder = _index switch @@ -1197,12 +1271,16 @@ public bool TryPickT17(out T17 value, out OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT17; } - public bool TryPickT18(out T18 value, out OneOf remainder) +#if NET + public bool TryPickT18([NotNullWhen(true)] out T18? value, out OneOf remainder) +#else + public bool TryPickT18(out T18? value, out OneOf remainder) +#endif { value = IsT18 ? AsT18 : default; remainder = _index switch @@ -1235,12 +1313,16 @@ public bool TryPickT18(out T18 value, out OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT18; } - public bool TryPickT19(out T19 value, out OneOf remainder) +#if NET + public bool TryPickT19([NotNullWhen(true)] out T19? value, out OneOf remainder) +#else + public bool TryPickT19(out T19? value, out OneOf remainder) +#endif { value = IsT19 ? AsT19 : default; remainder = _index switch @@ -1273,12 +1355,16 @@ public bool TryPickT19(out T19 value, out OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT19; } - public bool TryPickT20(out T20 value, out OneOf remainder) +#if NET + public bool TryPickT20([NotNullWhen(true)] out T20? value, out OneOf remainder) +#else + public bool TryPickT20(out T20? value, out OneOf remainder) +#endif { value = IsT20 ? AsT20 : default; remainder = _index switch @@ -1311,12 +1397,16 @@ public bool TryPickT20(out T20 value, out OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT20; } - public bool TryPickT21(out T21 value, out OneOf remainder) +#if NET + public bool TryPickT21([NotNullWhen(true)] out T21? value, out OneOf remainder) +#else + public bool TryPickT21(out T21? value, out OneOf remainder) +#endif { value = IsT21 ? AsT21 : default; remainder = _index switch @@ -1349,12 +1439,16 @@ public bool TryPickT21(out T21 value, out OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT21; } - public bool TryPickT22(out T22 value, out OneOf remainder) +#if NET + public bool TryPickT22([NotNullWhen(true)] out T22? value, out OneOf remainder) +#else + public bool TryPickT22(out T22? value, out OneOf remainder) +#endif { value = IsT22 ? AsT22 : default; remainder = _index switch @@ -1387,12 +1481,16 @@ public bool TryPickT22(out T22 value, out OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT22; } - public bool TryPickT23(out T23 value, out OneOf remainder) +#if NET + public bool TryPickT23([NotNullWhen(true)] out T23? value, out OneOf remainder) +#else + public bool TryPickT23(out T23? value, out OneOf remainder) +#endif { value = IsT23 ? AsT23 : default; remainder = _index switch @@ -1425,12 +1523,16 @@ public bool TryPickT23(out T23 value, out OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT23; } - public bool TryPickT24(out T24 value, out OneOf remainder) +#if NET + public bool TryPickT24([NotNullWhen(true)] out T24? value, out OneOf remainder) +#else + public bool TryPickT24(out T24? value, out OneOf remainder) +#endif { value = IsT24 ? AsT24 : default; remainder = _index switch @@ -1463,12 +1565,16 @@ public bool TryPickT24(out T24 value, out OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT24; } - public bool TryPickT25(out T25 value, out OneOf remainder) +#if NET + public bool TryPickT25([NotNullWhen(true)] out T25? value, out OneOf remainder) +#else + public bool TryPickT25(out T25? value, out OneOf remainder) +#endif { value = IsT25 ? AsT25 : default; remainder = _index switch @@ -1501,12 +1607,16 @@ public bool TryPickT25(out T25 value, out OneOf default, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT25; } - public bool TryPickT26(out T26 value, out OneOf remainder) +#if NET + public bool TryPickT26([NotNullWhen(true)] out T26? value, out OneOf remainder) +#else + public bool TryPickT26(out T26? value, out OneOf remainder) +#endif { value = IsT26 ? AsT26 : default; remainder = _index switch @@ -1539,12 +1649,16 @@ public bool TryPickT26(out T26 value, out OneOf AsT25, 26 => default, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT26; } - public bool TryPickT27(out T27 value, out OneOf remainder) +#if NET + public bool TryPickT27([NotNullWhen(true)] out T27? value, out OneOf remainder) +#else + public bool TryPickT27(out T27? value, out OneOf remainder) +#endif { value = IsT27 ? AsT27 : default; remainder = _index switch @@ -1577,7 +1691,7 @@ public bool TryPickT27(out T27 value, out OneOf AsT25, 26 => AsT26, 27 => default, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT27; } @@ -1617,7 +1731,7 @@ bool Equals(OneOfBase false }; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/OneOf.Extended/OneOfBaseT28.generated.cs b/OneOf.Extended/OneOfBaseT28.generated.cs index 611c63e..1a83762 100644 --- a/OneOf.Extended/OneOfBaseT28.generated.cs +++ b/OneOf.Extended/OneOfBaseT28.generated.cs @@ -1,39 +1,41 @@ +#nullable enable using System; +using System.Diagnostics.CodeAnalysis; using static OneOf.Functions; namespace OneOf { public class OneOfBase : IOneOf { - readonly T0 _value0; - readonly T1 _value1; - readonly T2 _value2; - readonly T3 _value3; - readonly T4 _value4; - readonly T5 _value5; - readonly T6 _value6; - readonly T7 _value7; - readonly T8 _value8; - readonly T9 _value9; - readonly T10 _value10; - readonly T11 _value11; - readonly T12 _value12; - readonly T13 _value13; - readonly T14 _value14; - readonly T15 _value15; - readonly T16 _value16; - readonly T17 _value17; - readonly T18 _value18; - readonly T19 _value19; - readonly T20 _value20; - readonly T21 _value21; - readonly T22 _value22; - readonly T23 _value23; - readonly T24 _value24; - readonly T25 _value25; - readonly T26 _value26; - readonly T27 _value27; - readonly T28 _value28; + readonly T0 _value0 = default!; + readonly T1 _value1 = default!; + readonly T2 _value2 = default!; + readonly T3 _value3 = default!; + readonly T4 _value4 = default!; + readonly T5 _value5 = default!; + readonly T6 _value6 = default!; + readonly T7 _value7 = default!; + readonly T8 _value8 = default!; + readonly T9 _value9 = default!; + readonly T10 _value10 = default!; + readonly T11 _value11 = default!; + readonly T12 _value12 = default!; + readonly T13 _value13 = default!; + readonly T14 _value14 = default!; + readonly T15 _value15 = default!; + readonly T16 _value16 = default!; + readonly T17 _value17 = default!; + readonly T18 _value18 = default!; + readonly T19 _value19 = default!; + readonly T20 _value20 = default!; + readonly T21 _value21 = default!; + readonly T22 _value22 = default!; + readonly T23 _value23 = default!; + readonly T24 _value24 = default!; + readonly T25 _value25 = default!; + readonly T26 _value26 = default!; + readonly T27 _value27 = default!; + readonly T28 _value28 = default!; readonly int _index; protected OneOfBase(OneOf input) @@ -70,11 +72,11 @@ protected OneOfBase(OneOf + public object? Value => _index switch { 0 => _value0, @@ -106,7 +108,7 @@ protected OneOfBase(OneOf _value26, 27 => _value27, 28 => _value28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; public int Index => _index; @@ -407,7 +409,7 @@ public void Switch(Action f0, Action f1, Action f2, Action f3, A f28(_value28); return; } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } public TResult Match(Func f0, Func f1, Func f2, Func f3, Func f4, Func f5, Func f6, Func f7, Func f8, Func f9, Func f10, Func f11, Func f12, Func f13, Func f14, Func f15, Func f16, Func f17, Func f18, Func f19, Func f20, Func f21, Func f22, Func f23, Func f24, Func f25, Func f26, Func f27, Func f28) @@ -528,14 +530,18 @@ public TResult Match(Func f0, Func f1, Func remainder) +#if NET + public bool TryPickT0([NotNullWhen(true)] out T0? value, out OneOf remainder) +#else + public bool TryPickT0(out T0? value, out OneOf remainder) +#endif { value = IsT0 ? AsT0 : default; remainder = _index switch @@ -569,12 +575,16 @@ public bool TryPickT0(out T0 value, out OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT0; } - public bool TryPickT1(out T1 value, out OneOf remainder) +#if NET + public bool TryPickT1([NotNullWhen(true)] out T1? value, out OneOf remainder) +#else + public bool TryPickT1(out T1? value, out OneOf remainder) +#endif { value = IsT1 ? AsT1 : default; remainder = _index switch @@ -608,12 +618,16 @@ public bool TryPickT1(out T1 value, out OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT1; } - public bool TryPickT2(out T2 value, out OneOf remainder) +#if NET + public bool TryPickT2([NotNullWhen(true)] out T2? value, out OneOf remainder) +#else + public bool TryPickT2(out T2? value, out OneOf remainder) +#endif { value = IsT2 ? AsT2 : default; remainder = _index switch @@ -647,12 +661,16 @@ public bool TryPickT2(out T2 value, out OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT2; } - public bool TryPickT3(out T3 value, out OneOf remainder) +#if NET + public bool TryPickT3([NotNullWhen(true)] out T3? value, out OneOf remainder) +#else + public bool TryPickT3(out T3? value, out OneOf remainder) +#endif { value = IsT3 ? AsT3 : default; remainder = _index switch @@ -686,12 +704,16 @@ public bool TryPickT3(out T3 value, out OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT3; } - public bool TryPickT4(out T4 value, out OneOf remainder) +#if NET + public bool TryPickT4([NotNullWhen(true)] out T4? value, out OneOf remainder) +#else + public bool TryPickT4(out T4? value, out OneOf remainder) +#endif { value = IsT4 ? AsT4 : default; remainder = _index switch @@ -725,12 +747,16 @@ public bool TryPickT4(out T4 value, out OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT4; } - public bool TryPickT5(out T5 value, out OneOf remainder) +#if NET + public bool TryPickT5([NotNullWhen(true)] out T5? value, out OneOf remainder) +#else + public bool TryPickT5(out T5? value, out OneOf remainder) +#endif { value = IsT5 ? AsT5 : default; remainder = _index switch @@ -764,12 +790,16 @@ public bool TryPickT5(out T5 value, out OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT5; } - public bool TryPickT6(out T6 value, out OneOf remainder) +#if NET + public bool TryPickT6([NotNullWhen(true)] out T6? value, out OneOf remainder) +#else + public bool TryPickT6(out T6? value, out OneOf remainder) +#endif { value = IsT6 ? AsT6 : default; remainder = _index switch @@ -803,12 +833,16 @@ public bool TryPickT6(out T6 value, out OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT6; } - public bool TryPickT7(out T7 value, out OneOf remainder) +#if NET + public bool TryPickT7([NotNullWhen(true)] out T7? value, out OneOf remainder) +#else + public bool TryPickT7(out T7? value, out OneOf remainder) +#endif { value = IsT7 ? AsT7 : default; remainder = _index switch @@ -842,12 +876,16 @@ public bool TryPickT7(out T7 value, out OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT7; } - public bool TryPickT8(out T8 value, out OneOf remainder) +#if NET + public bool TryPickT8([NotNullWhen(true)] out T8? value, out OneOf remainder) +#else + public bool TryPickT8(out T8? value, out OneOf remainder) +#endif { value = IsT8 ? AsT8 : default; remainder = _index switch @@ -881,12 +919,16 @@ public bool TryPickT8(out T8 value, out OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT8; } - public bool TryPickT9(out T9 value, out OneOf remainder) +#if NET + public bool TryPickT9([NotNullWhen(true)] out T9? value, out OneOf remainder) +#else + public bool TryPickT9(out T9? value, out OneOf remainder) +#endif { value = IsT9 ? AsT9 : default; remainder = _index switch @@ -920,12 +962,16 @@ public bool TryPickT9(out T9 value, out OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT9; } - public bool TryPickT10(out T10 value, out OneOf remainder) +#if NET + public bool TryPickT10([NotNullWhen(true)] out T10? value, out OneOf remainder) +#else + public bool TryPickT10(out T10? value, out OneOf remainder) +#endif { value = IsT10 ? AsT10 : default; remainder = _index switch @@ -959,12 +1005,16 @@ public bool TryPickT10(out T10 value, out OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT10; } - public bool TryPickT11(out T11 value, out OneOf remainder) +#if NET + public bool TryPickT11([NotNullWhen(true)] out T11? value, out OneOf remainder) +#else + public bool TryPickT11(out T11? value, out OneOf remainder) +#endif { value = IsT11 ? AsT11 : default; remainder = _index switch @@ -998,12 +1048,16 @@ public bool TryPickT11(out T11 value, out OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT11; } - public bool TryPickT12(out T12 value, out OneOf remainder) +#if NET + public bool TryPickT12([NotNullWhen(true)] out T12? value, out OneOf remainder) +#else + public bool TryPickT12(out T12? value, out OneOf remainder) +#endif { value = IsT12 ? AsT12 : default; remainder = _index switch @@ -1037,12 +1091,16 @@ public bool TryPickT12(out T12 value, out OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT12; } - public bool TryPickT13(out T13 value, out OneOf remainder) +#if NET + public bool TryPickT13([NotNullWhen(true)] out T13? value, out OneOf remainder) +#else + public bool TryPickT13(out T13? value, out OneOf remainder) +#endif { value = IsT13 ? AsT13 : default; remainder = _index switch @@ -1076,12 +1134,16 @@ public bool TryPickT13(out T13 value, out OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT13; } - public bool TryPickT14(out T14 value, out OneOf remainder) +#if NET + public bool TryPickT14([NotNullWhen(true)] out T14? value, out OneOf remainder) +#else + public bool TryPickT14(out T14? value, out OneOf remainder) +#endif { value = IsT14 ? AsT14 : default; remainder = _index switch @@ -1115,12 +1177,16 @@ public bool TryPickT14(out T14 value, out OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT14; } - public bool TryPickT15(out T15 value, out OneOf remainder) +#if NET + public bool TryPickT15([NotNullWhen(true)] out T15? value, out OneOf remainder) +#else + public bool TryPickT15(out T15? value, out OneOf remainder) +#endif { value = IsT15 ? AsT15 : default; remainder = _index switch @@ -1154,12 +1220,16 @@ public bool TryPickT15(out T15 value, out OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT15; } - public bool TryPickT16(out T16 value, out OneOf remainder) +#if NET + public bool TryPickT16([NotNullWhen(true)] out T16? value, out OneOf remainder) +#else + public bool TryPickT16(out T16? value, out OneOf remainder) +#endif { value = IsT16 ? AsT16 : default; remainder = _index switch @@ -1193,12 +1263,16 @@ public bool TryPickT16(out T16 value, out OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT16; } - public bool TryPickT17(out T17 value, out OneOf remainder) +#if NET + public bool TryPickT17([NotNullWhen(true)] out T17? value, out OneOf remainder) +#else + public bool TryPickT17(out T17? value, out OneOf remainder) +#endif { value = IsT17 ? AsT17 : default; remainder = _index switch @@ -1232,12 +1306,16 @@ public bool TryPickT17(out T17 value, out OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT17; } - public bool TryPickT18(out T18 value, out OneOf remainder) +#if NET + public bool TryPickT18([NotNullWhen(true)] out T18? value, out OneOf remainder) +#else + public bool TryPickT18(out T18? value, out OneOf remainder) +#endif { value = IsT18 ? AsT18 : default; remainder = _index switch @@ -1271,12 +1349,16 @@ public bool TryPickT18(out T18 value, out OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT18; } - public bool TryPickT19(out T19 value, out OneOf remainder) +#if NET + public bool TryPickT19([NotNullWhen(true)] out T19? value, out OneOf remainder) +#else + public bool TryPickT19(out T19? value, out OneOf remainder) +#endif { value = IsT19 ? AsT19 : default; remainder = _index switch @@ -1310,12 +1392,16 @@ public bool TryPickT19(out T19 value, out OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT19; } - public bool TryPickT20(out T20 value, out OneOf remainder) +#if NET + public bool TryPickT20([NotNullWhen(true)] out T20? value, out OneOf remainder) +#else + public bool TryPickT20(out T20? value, out OneOf remainder) +#endif { value = IsT20 ? AsT20 : default; remainder = _index switch @@ -1349,12 +1435,16 @@ public bool TryPickT20(out T20 value, out OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT20; } - public bool TryPickT21(out T21 value, out OneOf remainder) +#if NET + public bool TryPickT21([NotNullWhen(true)] out T21? value, out OneOf remainder) +#else + public bool TryPickT21(out T21? value, out OneOf remainder) +#endif { value = IsT21 ? AsT21 : default; remainder = _index switch @@ -1388,12 +1478,16 @@ public bool TryPickT21(out T21 value, out OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT21; } - public bool TryPickT22(out T22 value, out OneOf remainder) +#if NET + public bool TryPickT22([NotNullWhen(true)] out T22? value, out OneOf remainder) +#else + public bool TryPickT22(out T22? value, out OneOf remainder) +#endif { value = IsT22 ? AsT22 : default; remainder = _index switch @@ -1427,12 +1521,16 @@ public bool TryPickT22(out T22 value, out OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT22; } - public bool TryPickT23(out T23 value, out OneOf remainder) +#if NET + public bool TryPickT23([NotNullWhen(true)] out T23? value, out OneOf remainder) +#else + public bool TryPickT23(out T23? value, out OneOf remainder) +#endif { value = IsT23 ? AsT23 : default; remainder = _index switch @@ -1466,12 +1564,16 @@ public bool TryPickT23(out T23 value, out OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT23; } - public bool TryPickT24(out T24 value, out OneOf remainder) +#if NET + public bool TryPickT24([NotNullWhen(true)] out T24? value, out OneOf remainder) +#else + public bool TryPickT24(out T24? value, out OneOf remainder) +#endif { value = IsT24 ? AsT24 : default; remainder = _index switch @@ -1505,12 +1607,16 @@ public bool TryPickT24(out T24 value, out OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT24; } - public bool TryPickT25(out T25 value, out OneOf remainder) +#if NET + public bool TryPickT25([NotNullWhen(true)] out T25? value, out OneOf remainder) +#else + public bool TryPickT25(out T25? value, out OneOf remainder) +#endif { value = IsT25 ? AsT25 : default; remainder = _index switch @@ -1544,12 +1650,16 @@ public bool TryPickT25(out T25 value, out OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT25; } - public bool TryPickT26(out T26 value, out OneOf remainder) +#if NET + public bool TryPickT26([NotNullWhen(true)] out T26? value, out OneOf remainder) +#else + public bool TryPickT26(out T26? value, out OneOf remainder) +#endif { value = IsT26 ? AsT26 : default; remainder = _index switch @@ -1583,12 +1693,16 @@ public bool TryPickT26(out T26 value, out OneOf default, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT26; } - public bool TryPickT27(out T27 value, out OneOf remainder) +#if NET + public bool TryPickT27([NotNullWhen(true)] out T27? value, out OneOf remainder) +#else + public bool TryPickT27(out T27? value, out OneOf remainder) +#endif { value = IsT27 ? AsT27 : default; remainder = _index switch @@ -1622,12 +1736,16 @@ public bool TryPickT27(out T27 value, out OneOf AsT26, 27 => default, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT27; } - public bool TryPickT28(out T28 value, out OneOf remainder) +#if NET + public bool TryPickT28([NotNullWhen(true)] out T28? value, out OneOf remainder) +#else + public bool TryPickT28(out T28? value, out OneOf remainder) +#endif { value = IsT28 ? AsT28 : default; remainder = _index switch @@ -1661,7 +1779,7 @@ public bool TryPickT28(out T28 value, out OneOf AsT26, 27 => AsT27, 28 => default, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT28; } @@ -1702,7 +1820,7 @@ bool Equals(OneOfBase false }; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/OneOf.Extended/OneOfBaseT29.generated.cs b/OneOf.Extended/OneOfBaseT29.generated.cs index 8348e0d..8ac57ca 100644 --- a/OneOf.Extended/OneOfBaseT29.generated.cs +++ b/OneOf.Extended/OneOfBaseT29.generated.cs @@ -1,40 +1,42 @@ +#nullable enable using System; +using System.Diagnostics.CodeAnalysis; using static OneOf.Functions; namespace OneOf { public class OneOfBase : IOneOf { - readonly T0 _value0; - readonly T1 _value1; - readonly T2 _value2; - readonly T3 _value3; - readonly T4 _value4; - readonly T5 _value5; - readonly T6 _value6; - readonly T7 _value7; - readonly T8 _value8; - readonly T9 _value9; - readonly T10 _value10; - readonly T11 _value11; - readonly T12 _value12; - readonly T13 _value13; - readonly T14 _value14; - readonly T15 _value15; - readonly T16 _value16; - readonly T17 _value17; - readonly T18 _value18; - readonly T19 _value19; - readonly T20 _value20; - readonly T21 _value21; - readonly T22 _value22; - readonly T23 _value23; - readonly T24 _value24; - readonly T25 _value25; - readonly T26 _value26; - readonly T27 _value27; - readonly T28 _value28; - readonly T29 _value29; + readonly T0 _value0 = default!; + readonly T1 _value1 = default!; + readonly T2 _value2 = default!; + readonly T3 _value3 = default!; + readonly T4 _value4 = default!; + readonly T5 _value5 = default!; + readonly T6 _value6 = default!; + readonly T7 _value7 = default!; + readonly T8 _value8 = default!; + readonly T9 _value9 = default!; + readonly T10 _value10 = default!; + readonly T11 _value11 = default!; + readonly T12 _value12 = default!; + readonly T13 _value13 = default!; + readonly T14 _value14 = default!; + readonly T15 _value15 = default!; + readonly T16 _value16 = default!; + readonly T17 _value17 = default!; + readonly T18 _value18 = default!; + readonly T19 _value19 = default!; + readonly T20 _value20 = default!; + readonly T21 _value21 = default!; + readonly T22 _value22 = default!; + readonly T23 _value23 = default!; + readonly T24 _value24 = default!; + readonly T25 _value25 = default!; + readonly T26 _value26 = default!; + readonly T27 _value27 = default!; + readonly T28 _value28 = default!; + readonly T29 _value29 = default!; readonly int _index; protected OneOfBase(OneOf input) @@ -72,11 +74,11 @@ protected OneOfBase(OneOf + public object? Value => _index switch { 0 => _value0, @@ -109,7 +111,7 @@ protected OneOfBase(OneOf _value27, 28 => _value28, 29 => _value29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; public int Index => _index; @@ -420,7 +422,7 @@ public void Switch(Action f0, Action f1, Action f2, Action f3, A f29(_value29); return; } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } public TResult Match(Func f0, Func f1, Func f2, Func f3, Func f4, Func f5, Func f6, Func f7, Func f8, Func f9, Func f10, Func f11, Func f12, Func f13, Func f14, Func f15, Func f16, Func f17, Func f18, Func f19, Func f20, Func f21, Func f22, Func f23, Func f24, Func f25, Func f26, Func f27, Func f28, Func f29) @@ -545,14 +547,18 @@ public TResult Match(Func f0, Func f1, Func remainder) +#if NET + public bool TryPickT0([NotNullWhen(true)] out T0? value, out OneOf remainder) +#else + public bool TryPickT0(out T0? value, out OneOf remainder) +#endif { value = IsT0 ? AsT0 : default; remainder = _index switch @@ -587,12 +593,16 @@ public bool TryPickT0(out T0 value, out OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT0; } - public bool TryPickT1(out T1 value, out OneOf remainder) +#if NET + public bool TryPickT1([NotNullWhen(true)] out T1? value, out OneOf remainder) +#else + public bool TryPickT1(out T1? value, out OneOf remainder) +#endif { value = IsT1 ? AsT1 : default; remainder = _index switch @@ -627,12 +637,16 @@ public bool TryPickT1(out T1 value, out OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT1; } - public bool TryPickT2(out T2 value, out OneOf remainder) +#if NET + public bool TryPickT2([NotNullWhen(true)] out T2? value, out OneOf remainder) +#else + public bool TryPickT2(out T2? value, out OneOf remainder) +#endif { value = IsT2 ? AsT2 : default; remainder = _index switch @@ -667,12 +681,16 @@ public bool TryPickT2(out T2 value, out OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT2; } - public bool TryPickT3(out T3 value, out OneOf remainder) +#if NET + public bool TryPickT3([NotNullWhen(true)] out T3? value, out OneOf remainder) +#else + public bool TryPickT3(out T3? value, out OneOf remainder) +#endif { value = IsT3 ? AsT3 : default; remainder = _index switch @@ -707,12 +725,16 @@ public bool TryPickT3(out T3 value, out OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT3; } - public bool TryPickT4(out T4 value, out OneOf remainder) +#if NET + public bool TryPickT4([NotNullWhen(true)] out T4? value, out OneOf remainder) +#else + public bool TryPickT4(out T4? value, out OneOf remainder) +#endif { value = IsT4 ? AsT4 : default; remainder = _index switch @@ -747,12 +769,16 @@ public bool TryPickT4(out T4 value, out OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT4; } - public bool TryPickT5(out T5 value, out OneOf remainder) +#if NET + public bool TryPickT5([NotNullWhen(true)] out T5? value, out OneOf remainder) +#else + public bool TryPickT5(out T5? value, out OneOf remainder) +#endif { value = IsT5 ? AsT5 : default; remainder = _index switch @@ -787,12 +813,16 @@ public bool TryPickT5(out T5 value, out OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT5; } - public bool TryPickT6(out T6 value, out OneOf remainder) +#if NET + public bool TryPickT6([NotNullWhen(true)] out T6? value, out OneOf remainder) +#else + public bool TryPickT6(out T6? value, out OneOf remainder) +#endif { value = IsT6 ? AsT6 : default; remainder = _index switch @@ -827,12 +857,16 @@ public bool TryPickT6(out T6 value, out OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT6; } - public bool TryPickT7(out T7 value, out OneOf remainder) +#if NET + public bool TryPickT7([NotNullWhen(true)] out T7? value, out OneOf remainder) +#else + public bool TryPickT7(out T7? value, out OneOf remainder) +#endif { value = IsT7 ? AsT7 : default; remainder = _index switch @@ -867,12 +901,16 @@ public bool TryPickT7(out T7 value, out OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT7; } - public bool TryPickT8(out T8 value, out OneOf remainder) +#if NET + public bool TryPickT8([NotNullWhen(true)] out T8? value, out OneOf remainder) +#else + public bool TryPickT8(out T8? value, out OneOf remainder) +#endif { value = IsT8 ? AsT8 : default; remainder = _index switch @@ -907,12 +945,16 @@ public bool TryPickT8(out T8 value, out OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT8; } - public bool TryPickT9(out T9 value, out OneOf remainder) +#if NET + public bool TryPickT9([NotNullWhen(true)] out T9? value, out OneOf remainder) +#else + public bool TryPickT9(out T9? value, out OneOf remainder) +#endif { value = IsT9 ? AsT9 : default; remainder = _index switch @@ -947,12 +989,16 @@ public bool TryPickT9(out T9 value, out OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT9; } - public bool TryPickT10(out T10 value, out OneOf remainder) +#if NET + public bool TryPickT10([NotNullWhen(true)] out T10? value, out OneOf remainder) +#else + public bool TryPickT10(out T10? value, out OneOf remainder) +#endif { value = IsT10 ? AsT10 : default; remainder = _index switch @@ -987,12 +1033,16 @@ public bool TryPickT10(out T10 value, out OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT10; } - public bool TryPickT11(out T11 value, out OneOf remainder) +#if NET + public bool TryPickT11([NotNullWhen(true)] out T11? value, out OneOf remainder) +#else + public bool TryPickT11(out T11? value, out OneOf remainder) +#endif { value = IsT11 ? AsT11 : default; remainder = _index switch @@ -1027,12 +1077,16 @@ public bool TryPickT11(out T11 value, out OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT11; } - public bool TryPickT12(out T12 value, out OneOf remainder) +#if NET + public bool TryPickT12([NotNullWhen(true)] out T12? value, out OneOf remainder) +#else + public bool TryPickT12(out T12? value, out OneOf remainder) +#endif { value = IsT12 ? AsT12 : default; remainder = _index switch @@ -1067,12 +1121,16 @@ public bool TryPickT12(out T12 value, out OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT12; } - public bool TryPickT13(out T13 value, out OneOf remainder) +#if NET + public bool TryPickT13([NotNullWhen(true)] out T13? value, out OneOf remainder) +#else + public bool TryPickT13(out T13? value, out OneOf remainder) +#endif { value = IsT13 ? AsT13 : default; remainder = _index switch @@ -1107,12 +1165,16 @@ public bool TryPickT13(out T13 value, out OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT13; } - public bool TryPickT14(out T14 value, out OneOf remainder) +#if NET + public bool TryPickT14([NotNullWhen(true)] out T14? value, out OneOf remainder) +#else + public bool TryPickT14(out T14? value, out OneOf remainder) +#endif { value = IsT14 ? AsT14 : default; remainder = _index switch @@ -1147,12 +1209,16 @@ public bool TryPickT14(out T14 value, out OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT14; } - public bool TryPickT15(out T15 value, out OneOf remainder) +#if NET + public bool TryPickT15([NotNullWhen(true)] out T15? value, out OneOf remainder) +#else + public bool TryPickT15(out T15? value, out OneOf remainder) +#endif { value = IsT15 ? AsT15 : default; remainder = _index switch @@ -1187,12 +1253,16 @@ public bool TryPickT15(out T15 value, out OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT15; } - public bool TryPickT16(out T16 value, out OneOf remainder) +#if NET + public bool TryPickT16([NotNullWhen(true)] out T16? value, out OneOf remainder) +#else + public bool TryPickT16(out T16? value, out OneOf remainder) +#endif { value = IsT16 ? AsT16 : default; remainder = _index switch @@ -1227,12 +1297,16 @@ public bool TryPickT16(out T16 value, out OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT16; } - public bool TryPickT17(out T17 value, out OneOf remainder) +#if NET + public bool TryPickT17([NotNullWhen(true)] out T17? value, out OneOf remainder) +#else + public bool TryPickT17(out T17? value, out OneOf remainder) +#endif { value = IsT17 ? AsT17 : default; remainder = _index switch @@ -1267,12 +1341,16 @@ public bool TryPickT17(out T17 value, out OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT17; } - public bool TryPickT18(out T18 value, out OneOf remainder) +#if NET + public bool TryPickT18([NotNullWhen(true)] out T18? value, out OneOf remainder) +#else + public bool TryPickT18(out T18? value, out OneOf remainder) +#endif { value = IsT18 ? AsT18 : default; remainder = _index switch @@ -1307,12 +1385,16 @@ public bool TryPickT18(out T18 value, out OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT18; } - public bool TryPickT19(out T19 value, out OneOf remainder) +#if NET + public bool TryPickT19([NotNullWhen(true)] out T19? value, out OneOf remainder) +#else + public bool TryPickT19(out T19? value, out OneOf remainder) +#endif { value = IsT19 ? AsT19 : default; remainder = _index switch @@ -1347,12 +1429,16 @@ public bool TryPickT19(out T19 value, out OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT19; } - public bool TryPickT20(out T20 value, out OneOf remainder) +#if NET + public bool TryPickT20([NotNullWhen(true)] out T20? value, out OneOf remainder) +#else + public bool TryPickT20(out T20? value, out OneOf remainder) +#endif { value = IsT20 ? AsT20 : default; remainder = _index switch @@ -1387,12 +1473,16 @@ public bool TryPickT20(out T20 value, out OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT20; } - public bool TryPickT21(out T21 value, out OneOf remainder) +#if NET + public bool TryPickT21([NotNullWhen(true)] out T21? value, out OneOf remainder) +#else + public bool TryPickT21(out T21? value, out OneOf remainder) +#endif { value = IsT21 ? AsT21 : default; remainder = _index switch @@ -1427,12 +1517,16 @@ public bool TryPickT21(out T21 value, out OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT21; } - public bool TryPickT22(out T22 value, out OneOf remainder) +#if NET + public bool TryPickT22([NotNullWhen(true)] out T22? value, out OneOf remainder) +#else + public bool TryPickT22(out T22? value, out OneOf remainder) +#endif { value = IsT22 ? AsT22 : default; remainder = _index switch @@ -1467,12 +1561,16 @@ public bool TryPickT22(out T22 value, out OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT22; } - public bool TryPickT23(out T23 value, out OneOf remainder) +#if NET + public bool TryPickT23([NotNullWhen(true)] out T23? value, out OneOf remainder) +#else + public bool TryPickT23(out T23? value, out OneOf remainder) +#endif { value = IsT23 ? AsT23 : default; remainder = _index switch @@ -1507,12 +1605,16 @@ public bool TryPickT23(out T23 value, out OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT23; } - public bool TryPickT24(out T24 value, out OneOf remainder) +#if NET + public bool TryPickT24([NotNullWhen(true)] out T24? value, out OneOf remainder) +#else + public bool TryPickT24(out T24? value, out OneOf remainder) +#endif { value = IsT24 ? AsT24 : default; remainder = _index switch @@ -1547,12 +1649,16 @@ public bool TryPickT24(out T24 value, out OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT24; } - public bool TryPickT25(out T25 value, out OneOf remainder) +#if NET + public bool TryPickT25([NotNullWhen(true)] out T25? value, out OneOf remainder) +#else + public bool TryPickT25(out T25? value, out OneOf remainder) +#endif { value = IsT25 ? AsT25 : default; remainder = _index switch @@ -1587,12 +1693,16 @@ public bool TryPickT25(out T25 value, out OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT25; } - public bool TryPickT26(out T26 value, out OneOf remainder) +#if NET + public bool TryPickT26([NotNullWhen(true)] out T26? value, out OneOf remainder) +#else + public bool TryPickT26(out T26? value, out OneOf remainder) +#endif { value = IsT26 ? AsT26 : default; remainder = _index switch @@ -1627,12 +1737,16 @@ public bool TryPickT26(out T26 value, out OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT26; } - public bool TryPickT27(out T27 value, out OneOf remainder) +#if NET + public bool TryPickT27([NotNullWhen(true)] out T27? value, out OneOf remainder) +#else + public bool TryPickT27(out T27? value, out OneOf remainder) +#endif { value = IsT27 ? AsT27 : default; remainder = _index switch @@ -1667,12 +1781,16 @@ public bool TryPickT27(out T27 value, out OneOf default, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT27; } - public bool TryPickT28(out T28 value, out OneOf remainder) +#if NET + public bool TryPickT28([NotNullWhen(true)] out T28? value, out OneOf remainder) +#else + public bool TryPickT28(out T28? value, out OneOf remainder) +#endif { value = IsT28 ? AsT28 : default; remainder = _index switch @@ -1707,12 +1825,16 @@ public bool TryPickT28(out T28 value, out OneOf AsT27, 28 => default, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT28; } - public bool TryPickT29(out T29 value, out OneOf remainder) +#if NET + public bool TryPickT29([NotNullWhen(true)] out T29? value, out OneOf remainder) +#else + public bool TryPickT29(out T29? value, out OneOf remainder) +#endif { value = IsT29 ? AsT29 : default; remainder = _index switch @@ -1747,7 +1869,7 @@ public bool TryPickT29(out T29 value, out OneOf AsT27, 28 => AsT28, 29 => default, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT29; } @@ -1789,7 +1911,7 @@ bool Equals(OneOfBase false }; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/OneOf.Extended/OneOfBaseT30.generated.cs b/OneOf.Extended/OneOfBaseT30.generated.cs index 25229bd..8f743f7 100644 --- a/OneOf.Extended/OneOfBaseT30.generated.cs +++ b/OneOf.Extended/OneOfBaseT30.generated.cs @@ -1,41 +1,43 @@ +#nullable enable using System; +using System.Diagnostics.CodeAnalysis; using static OneOf.Functions; namespace OneOf { public class OneOfBase : IOneOf { - readonly T0 _value0; - readonly T1 _value1; - readonly T2 _value2; - readonly T3 _value3; - readonly T4 _value4; - readonly T5 _value5; - readonly T6 _value6; - readonly T7 _value7; - readonly T8 _value8; - readonly T9 _value9; - readonly T10 _value10; - readonly T11 _value11; - readonly T12 _value12; - readonly T13 _value13; - readonly T14 _value14; - readonly T15 _value15; - readonly T16 _value16; - readonly T17 _value17; - readonly T18 _value18; - readonly T19 _value19; - readonly T20 _value20; - readonly T21 _value21; - readonly T22 _value22; - readonly T23 _value23; - readonly T24 _value24; - readonly T25 _value25; - readonly T26 _value26; - readonly T27 _value27; - readonly T28 _value28; - readonly T29 _value29; - readonly T30 _value30; + readonly T0 _value0 = default!; + readonly T1 _value1 = default!; + readonly T2 _value2 = default!; + readonly T3 _value3 = default!; + readonly T4 _value4 = default!; + readonly T5 _value5 = default!; + readonly T6 _value6 = default!; + readonly T7 _value7 = default!; + readonly T8 _value8 = default!; + readonly T9 _value9 = default!; + readonly T10 _value10 = default!; + readonly T11 _value11 = default!; + readonly T12 _value12 = default!; + readonly T13 _value13 = default!; + readonly T14 _value14 = default!; + readonly T15 _value15 = default!; + readonly T16 _value16 = default!; + readonly T17 _value17 = default!; + readonly T18 _value18 = default!; + readonly T19 _value19 = default!; + readonly T20 _value20 = default!; + readonly T21 _value21 = default!; + readonly T22 _value22 = default!; + readonly T23 _value23 = default!; + readonly T24 _value24 = default!; + readonly T25 _value25 = default!; + readonly T26 _value26 = default!; + readonly T27 _value27 = default!; + readonly T28 _value28 = default!; + readonly T29 _value29 = default!; + readonly T30 _value30 = default!; readonly int _index; protected OneOfBase(OneOf input) @@ -74,11 +76,11 @@ protected OneOfBase(OneOf + public object? Value => _index switch { 0 => _value0, @@ -112,7 +114,7 @@ protected OneOfBase(OneOf _value28, 29 => _value29, 30 => _value30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; public int Index => _index; @@ -433,7 +435,7 @@ public void Switch(Action f0, Action f1, Action f2, Action f3, A f30(_value30); return; } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } public TResult Match(Func f0, Func f1, Func f2, Func f3, Func f4, Func f5, Func f6, Func f7, Func f8, Func f9, Func f10, Func f11, Func f12, Func f13, Func f14, Func f15, Func f16, Func f17, Func f18, Func f19, Func f20, Func f21, Func f22, Func f23, Func f24, Func f25, Func f26, Func f27, Func f28, Func f29, Func f30) @@ -562,14 +564,18 @@ public TResult Match(Func f0, Func f1, Func remainder) +#if NET + public bool TryPickT0([NotNullWhen(true)] out T0? value, out OneOf remainder) +#else + public bool TryPickT0(out T0? value, out OneOf remainder) +#endif { value = IsT0 ? AsT0 : default; remainder = _index switch @@ -605,12 +611,16 @@ public bool TryPickT0(out T0 value, out OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT0; } - public bool TryPickT1(out T1 value, out OneOf remainder) +#if NET + public bool TryPickT1([NotNullWhen(true)] out T1? value, out OneOf remainder) +#else + public bool TryPickT1(out T1? value, out OneOf remainder) +#endif { value = IsT1 ? AsT1 : default; remainder = _index switch @@ -646,12 +656,16 @@ public bool TryPickT1(out T1 value, out OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT1; } - public bool TryPickT2(out T2 value, out OneOf remainder) +#if NET + public bool TryPickT2([NotNullWhen(true)] out T2? value, out OneOf remainder) +#else + public bool TryPickT2(out T2? value, out OneOf remainder) +#endif { value = IsT2 ? AsT2 : default; remainder = _index switch @@ -687,12 +701,16 @@ public bool TryPickT2(out T2 value, out OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT2; } - public bool TryPickT3(out T3 value, out OneOf remainder) +#if NET + public bool TryPickT3([NotNullWhen(true)] out T3? value, out OneOf remainder) +#else + public bool TryPickT3(out T3? value, out OneOf remainder) +#endif { value = IsT3 ? AsT3 : default; remainder = _index switch @@ -728,12 +746,16 @@ public bool TryPickT3(out T3 value, out OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT3; } - public bool TryPickT4(out T4 value, out OneOf remainder) +#if NET + public bool TryPickT4([NotNullWhen(true)] out T4? value, out OneOf remainder) +#else + public bool TryPickT4(out T4? value, out OneOf remainder) +#endif { value = IsT4 ? AsT4 : default; remainder = _index switch @@ -769,12 +791,16 @@ public bool TryPickT4(out T4 value, out OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT4; } - public bool TryPickT5(out T5 value, out OneOf remainder) +#if NET + public bool TryPickT5([NotNullWhen(true)] out T5? value, out OneOf remainder) +#else + public bool TryPickT5(out T5? value, out OneOf remainder) +#endif { value = IsT5 ? AsT5 : default; remainder = _index switch @@ -810,12 +836,16 @@ public bool TryPickT5(out T5 value, out OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT5; } - public bool TryPickT6(out T6 value, out OneOf remainder) +#if NET + public bool TryPickT6([NotNullWhen(true)] out T6? value, out OneOf remainder) +#else + public bool TryPickT6(out T6? value, out OneOf remainder) +#endif { value = IsT6 ? AsT6 : default; remainder = _index switch @@ -851,12 +881,16 @@ public bool TryPickT6(out T6 value, out OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT6; } - public bool TryPickT7(out T7 value, out OneOf remainder) +#if NET + public bool TryPickT7([NotNullWhen(true)] out T7? value, out OneOf remainder) +#else + public bool TryPickT7(out T7? value, out OneOf remainder) +#endif { value = IsT7 ? AsT7 : default; remainder = _index switch @@ -892,12 +926,16 @@ public bool TryPickT7(out T7 value, out OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT7; } - public bool TryPickT8(out T8 value, out OneOf remainder) +#if NET + public bool TryPickT8([NotNullWhen(true)] out T8? value, out OneOf remainder) +#else + public bool TryPickT8(out T8? value, out OneOf remainder) +#endif { value = IsT8 ? AsT8 : default; remainder = _index switch @@ -933,12 +971,16 @@ public bool TryPickT8(out T8 value, out OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT8; } - public bool TryPickT9(out T9 value, out OneOf remainder) +#if NET + public bool TryPickT9([NotNullWhen(true)] out T9? value, out OneOf remainder) +#else + public bool TryPickT9(out T9? value, out OneOf remainder) +#endif { value = IsT9 ? AsT9 : default; remainder = _index switch @@ -974,12 +1016,16 @@ public bool TryPickT9(out T9 value, out OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT9; } - public bool TryPickT10(out T10 value, out OneOf remainder) +#if NET + public bool TryPickT10([NotNullWhen(true)] out T10? value, out OneOf remainder) +#else + public bool TryPickT10(out T10? value, out OneOf remainder) +#endif { value = IsT10 ? AsT10 : default; remainder = _index switch @@ -1015,12 +1061,16 @@ public bool TryPickT10(out T10 value, out OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT10; } - public bool TryPickT11(out T11 value, out OneOf remainder) +#if NET + public bool TryPickT11([NotNullWhen(true)] out T11? value, out OneOf remainder) +#else + public bool TryPickT11(out T11? value, out OneOf remainder) +#endif { value = IsT11 ? AsT11 : default; remainder = _index switch @@ -1056,12 +1106,16 @@ public bool TryPickT11(out T11 value, out OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT11; } - public bool TryPickT12(out T12 value, out OneOf remainder) +#if NET + public bool TryPickT12([NotNullWhen(true)] out T12? value, out OneOf remainder) +#else + public bool TryPickT12(out T12? value, out OneOf remainder) +#endif { value = IsT12 ? AsT12 : default; remainder = _index switch @@ -1097,12 +1151,16 @@ public bool TryPickT12(out T12 value, out OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT12; } - public bool TryPickT13(out T13 value, out OneOf remainder) +#if NET + public bool TryPickT13([NotNullWhen(true)] out T13? value, out OneOf remainder) +#else + public bool TryPickT13(out T13? value, out OneOf remainder) +#endif { value = IsT13 ? AsT13 : default; remainder = _index switch @@ -1138,12 +1196,16 @@ public bool TryPickT13(out T13 value, out OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT13; } - public bool TryPickT14(out T14 value, out OneOf remainder) +#if NET + public bool TryPickT14([NotNullWhen(true)] out T14? value, out OneOf remainder) +#else + public bool TryPickT14(out T14? value, out OneOf remainder) +#endif { value = IsT14 ? AsT14 : default; remainder = _index switch @@ -1179,12 +1241,16 @@ public bool TryPickT14(out T14 value, out OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT14; } - public bool TryPickT15(out T15 value, out OneOf remainder) +#if NET + public bool TryPickT15([NotNullWhen(true)] out T15? value, out OneOf remainder) +#else + public bool TryPickT15(out T15? value, out OneOf remainder) +#endif { value = IsT15 ? AsT15 : default; remainder = _index switch @@ -1220,12 +1286,16 @@ public bool TryPickT15(out T15 value, out OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT15; } - public bool TryPickT16(out T16 value, out OneOf remainder) +#if NET + public bool TryPickT16([NotNullWhen(true)] out T16? value, out OneOf remainder) +#else + public bool TryPickT16(out T16? value, out OneOf remainder) +#endif { value = IsT16 ? AsT16 : default; remainder = _index switch @@ -1261,12 +1331,16 @@ public bool TryPickT16(out T16 value, out OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT16; } - public bool TryPickT17(out T17 value, out OneOf remainder) +#if NET + public bool TryPickT17([NotNullWhen(true)] out T17? value, out OneOf remainder) +#else + public bool TryPickT17(out T17? value, out OneOf remainder) +#endif { value = IsT17 ? AsT17 : default; remainder = _index switch @@ -1302,12 +1376,16 @@ public bool TryPickT17(out T17 value, out OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT17; } - public bool TryPickT18(out T18 value, out OneOf remainder) +#if NET + public bool TryPickT18([NotNullWhen(true)] out T18? value, out OneOf remainder) +#else + public bool TryPickT18(out T18? value, out OneOf remainder) +#endif { value = IsT18 ? AsT18 : default; remainder = _index switch @@ -1343,12 +1421,16 @@ public bool TryPickT18(out T18 value, out OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT18; } - public bool TryPickT19(out T19 value, out OneOf remainder) +#if NET + public bool TryPickT19([NotNullWhen(true)] out T19? value, out OneOf remainder) +#else + public bool TryPickT19(out T19? value, out OneOf remainder) +#endif { value = IsT19 ? AsT19 : default; remainder = _index switch @@ -1384,12 +1466,16 @@ public bool TryPickT19(out T19 value, out OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT19; } - public bool TryPickT20(out T20 value, out OneOf remainder) +#if NET + public bool TryPickT20([NotNullWhen(true)] out T20? value, out OneOf remainder) +#else + public bool TryPickT20(out T20? value, out OneOf remainder) +#endif { value = IsT20 ? AsT20 : default; remainder = _index switch @@ -1425,12 +1511,16 @@ public bool TryPickT20(out T20 value, out OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT20; } - public bool TryPickT21(out T21 value, out OneOf remainder) +#if NET + public bool TryPickT21([NotNullWhen(true)] out T21? value, out OneOf remainder) +#else + public bool TryPickT21(out T21? value, out OneOf remainder) +#endif { value = IsT21 ? AsT21 : default; remainder = _index switch @@ -1466,12 +1556,16 @@ public bool TryPickT21(out T21 value, out OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT21; } - public bool TryPickT22(out T22 value, out OneOf remainder) +#if NET + public bool TryPickT22([NotNullWhen(true)] out T22? value, out OneOf remainder) +#else + public bool TryPickT22(out T22? value, out OneOf remainder) +#endif { value = IsT22 ? AsT22 : default; remainder = _index switch @@ -1507,12 +1601,16 @@ public bool TryPickT22(out T22 value, out OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT22; } - public bool TryPickT23(out T23 value, out OneOf remainder) +#if NET + public bool TryPickT23([NotNullWhen(true)] out T23? value, out OneOf remainder) +#else + public bool TryPickT23(out T23? value, out OneOf remainder) +#endif { value = IsT23 ? AsT23 : default; remainder = _index switch @@ -1548,12 +1646,16 @@ public bool TryPickT23(out T23 value, out OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT23; } - public bool TryPickT24(out T24 value, out OneOf remainder) +#if NET + public bool TryPickT24([NotNullWhen(true)] out T24? value, out OneOf remainder) +#else + public bool TryPickT24(out T24? value, out OneOf remainder) +#endif { value = IsT24 ? AsT24 : default; remainder = _index switch @@ -1589,12 +1691,16 @@ public bool TryPickT24(out T24 value, out OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT24; } - public bool TryPickT25(out T25 value, out OneOf remainder) +#if NET + public bool TryPickT25([NotNullWhen(true)] out T25? value, out OneOf remainder) +#else + public bool TryPickT25(out T25? value, out OneOf remainder) +#endif { value = IsT25 ? AsT25 : default; remainder = _index switch @@ -1630,12 +1736,16 @@ public bool TryPickT25(out T25 value, out OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT25; } - public bool TryPickT26(out T26 value, out OneOf remainder) +#if NET + public bool TryPickT26([NotNullWhen(true)] out T26? value, out OneOf remainder) +#else + public bool TryPickT26(out T26? value, out OneOf remainder) +#endif { value = IsT26 ? AsT26 : default; remainder = _index switch @@ -1671,12 +1781,16 @@ public bool TryPickT26(out T26 value, out OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT26; } - public bool TryPickT27(out T27 value, out OneOf remainder) +#if NET + public bool TryPickT27([NotNullWhen(true)] out T27? value, out OneOf remainder) +#else + public bool TryPickT27(out T27? value, out OneOf remainder) +#endif { value = IsT27 ? AsT27 : default; remainder = _index switch @@ -1712,12 +1826,16 @@ public bool TryPickT27(out T27 value, out OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT27; } - public bool TryPickT28(out T28 value, out OneOf remainder) +#if NET + public bool TryPickT28([NotNullWhen(true)] out T28? value, out OneOf remainder) +#else + public bool TryPickT28(out T28? value, out OneOf remainder) +#endif { value = IsT28 ? AsT28 : default; remainder = _index switch @@ -1753,12 +1871,16 @@ public bool TryPickT28(out T28 value, out OneOf default, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT28; } - public bool TryPickT29(out T29 value, out OneOf remainder) +#if NET + public bool TryPickT29([NotNullWhen(true)] out T29? value, out OneOf remainder) +#else + public bool TryPickT29(out T29? value, out OneOf remainder) +#endif { value = IsT29 ? AsT29 : default; remainder = _index switch @@ -1794,12 +1916,16 @@ public bool TryPickT29(out T29 value, out OneOf AsT28, 29 => default, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT29; } - public bool TryPickT30(out T30 value, out OneOf remainder) +#if NET + public bool TryPickT30([NotNullWhen(true)] out T30? value, out OneOf remainder) +#else + public bool TryPickT30(out T30? value, out OneOf remainder) +#endif { value = IsT30 ? AsT30 : default; remainder = _index switch @@ -1835,7 +1961,7 @@ public bool TryPickT30(out T30 value, out OneOf AsT28, 29 => AsT29, 30 => default, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT30; } @@ -1878,7 +2004,7 @@ bool Equals(OneOfBase false }; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/OneOf.Extended/OneOfBaseT31.generated.cs b/OneOf.Extended/OneOfBaseT31.generated.cs index 9a1fa4d..e01ae55 100644 --- a/OneOf.Extended/OneOfBaseT31.generated.cs +++ b/OneOf.Extended/OneOfBaseT31.generated.cs @@ -1,42 +1,44 @@ +#nullable enable using System; +using System.Diagnostics.CodeAnalysis; using static OneOf.Functions; namespace OneOf { public class OneOfBase : IOneOf { - readonly T0 _value0; - readonly T1 _value1; - readonly T2 _value2; - readonly T3 _value3; - readonly T4 _value4; - readonly T5 _value5; - readonly T6 _value6; - readonly T7 _value7; - readonly T8 _value8; - readonly T9 _value9; - readonly T10 _value10; - readonly T11 _value11; - readonly T12 _value12; - readonly T13 _value13; - readonly T14 _value14; - readonly T15 _value15; - readonly T16 _value16; - readonly T17 _value17; - readonly T18 _value18; - readonly T19 _value19; - readonly T20 _value20; - readonly T21 _value21; - readonly T22 _value22; - readonly T23 _value23; - readonly T24 _value24; - readonly T25 _value25; - readonly T26 _value26; - readonly T27 _value27; - readonly T28 _value28; - readonly T29 _value29; - readonly T30 _value30; - readonly T31 _value31; + readonly T0 _value0 = default!; + readonly T1 _value1 = default!; + readonly T2 _value2 = default!; + readonly T3 _value3 = default!; + readonly T4 _value4 = default!; + readonly T5 _value5 = default!; + readonly T6 _value6 = default!; + readonly T7 _value7 = default!; + readonly T8 _value8 = default!; + readonly T9 _value9 = default!; + readonly T10 _value10 = default!; + readonly T11 _value11 = default!; + readonly T12 _value12 = default!; + readonly T13 _value13 = default!; + readonly T14 _value14 = default!; + readonly T15 _value15 = default!; + readonly T16 _value16 = default!; + readonly T17 _value17 = default!; + readonly T18 _value18 = default!; + readonly T19 _value19 = default!; + readonly T20 _value20 = default!; + readonly T21 _value21 = default!; + readonly T22 _value22 = default!; + readonly T23 _value23 = default!; + readonly T24 _value24 = default!; + readonly T25 _value25 = default!; + readonly T26 _value26 = default!; + readonly T27 _value27 = default!; + readonly T28 _value28 = default!; + readonly T29 _value29 = default!; + readonly T30 _value30 = default!; + readonly T31 _value31 = default!; readonly int _index; protected OneOfBase(OneOf input) @@ -76,11 +78,11 @@ protected OneOfBase(OneOf + public object? Value => _index switch { 0 => _value0, @@ -115,7 +117,7 @@ protected OneOfBase(OneOf _value29, 30 => _value30, 31 => _value31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; public int Index => _index; @@ -446,7 +448,7 @@ public void Switch(Action f0, Action f1, Action f2, Action f3, A f31(_value31); return; } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } public TResult Match(Func f0, Func f1, Func f2, Func f3, Func f4, Func f5, Func f6, Func f7, Func f8, Func f9, Func f10, Func f11, Func f12, Func f13, Func f14, Func f15, Func f16, Func f17, Func f18, Func f19, Func f20, Func f21, Func f22, Func f23, Func f24, Func f25, Func f26, Func f27, Func f28, Func f29, Func f30, Func f31) @@ -579,14 +581,18 @@ public TResult Match(Func f0, Func f1, Func remainder) +#if NET + public bool TryPickT0([NotNullWhen(true)] out T0? value, out OneOf remainder) +#else + public bool TryPickT0(out T0? value, out OneOf remainder) +#endif { value = IsT0 ? AsT0 : default; remainder = _index switch @@ -623,12 +629,16 @@ public bool TryPickT0(out T0 value, out OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT0; } - public bool TryPickT1(out T1 value, out OneOf remainder) +#if NET + public bool TryPickT1([NotNullWhen(true)] out T1? value, out OneOf remainder) +#else + public bool TryPickT1(out T1? value, out OneOf remainder) +#endif { value = IsT1 ? AsT1 : default; remainder = _index switch @@ -665,12 +675,16 @@ public bool TryPickT1(out T1 value, out OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT1; } - public bool TryPickT2(out T2 value, out OneOf remainder) +#if NET + public bool TryPickT2([NotNullWhen(true)] out T2? value, out OneOf remainder) +#else + public bool TryPickT2(out T2? value, out OneOf remainder) +#endif { value = IsT2 ? AsT2 : default; remainder = _index switch @@ -707,12 +721,16 @@ public bool TryPickT2(out T2 value, out OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT2; } - public bool TryPickT3(out T3 value, out OneOf remainder) +#if NET + public bool TryPickT3([NotNullWhen(true)] out T3? value, out OneOf remainder) +#else + public bool TryPickT3(out T3? value, out OneOf remainder) +#endif { value = IsT3 ? AsT3 : default; remainder = _index switch @@ -749,12 +767,16 @@ public bool TryPickT3(out T3 value, out OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT3; } - public bool TryPickT4(out T4 value, out OneOf remainder) +#if NET + public bool TryPickT4([NotNullWhen(true)] out T4? value, out OneOf remainder) +#else + public bool TryPickT4(out T4? value, out OneOf remainder) +#endif { value = IsT4 ? AsT4 : default; remainder = _index switch @@ -791,12 +813,16 @@ public bool TryPickT4(out T4 value, out OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT4; } - public bool TryPickT5(out T5 value, out OneOf remainder) +#if NET + public bool TryPickT5([NotNullWhen(true)] out T5? value, out OneOf remainder) +#else + public bool TryPickT5(out T5? value, out OneOf remainder) +#endif { value = IsT5 ? AsT5 : default; remainder = _index switch @@ -833,12 +859,16 @@ public bool TryPickT5(out T5 value, out OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT5; } - public bool TryPickT6(out T6 value, out OneOf remainder) +#if NET + public bool TryPickT6([NotNullWhen(true)] out T6? value, out OneOf remainder) +#else + public bool TryPickT6(out T6? value, out OneOf remainder) +#endif { value = IsT6 ? AsT6 : default; remainder = _index switch @@ -875,12 +905,16 @@ public bool TryPickT6(out T6 value, out OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT6; } - public bool TryPickT7(out T7 value, out OneOf remainder) +#if NET + public bool TryPickT7([NotNullWhen(true)] out T7? value, out OneOf remainder) +#else + public bool TryPickT7(out T7? value, out OneOf remainder) +#endif { value = IsT7 ? AsT7 : default; remainder = _index switch @@ -917,12 +951,16 @@ public bool TryPickT7(out T7 value, out OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT7; } - public bool TryPickT8(out T8 value, out OneOf remainder) +#if NET + public bool TryPickT8([NotNullWhen(true)] out T8? value, out OneOf remainder) +#else + public bool TryPickT8(out T8? value, out OneOf remainder) +#endif { value = IsT8 ? AsT8 : default; remainder = _index switch @@ -959,12 +997,16 @@ public bool TryPickT8(out T8 value, out OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT8; } - public bool TryPickT9(out T9 value, out OneOf remainder) +#if NET + public bool TryPickT9([NotNullWhen(true)] out T9? value, out OneOf remainder) +#else + public bool TryPickT9(out T9? value, out OneOf remainder) +#endif { value = IsT9 ? AsT9 : default; remainder = _index switch @@ -1001,12 +1043,16 @@ public bool TryPickT9(out T9 value, out OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT9; } - public bool TryPickT10(out T10 value, out OneOf remainder) +#if NET + public bool TryPickT10([NotNullWhen(true)] out T10? value, out OneOf remainder) +#else + public bool TryPickT10(out T10? value, out OneOf remainder) +#endif { value = IsT10 ? AsT10 : default; remainder = _index switch @@ -1043,12 +1089,16 @@ public bool TryPickT10(out T10 value, out OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT10; } - public bool TryPickT11(out T11 value, out OneOf remainder) +#if NET + public bool TryPickT11([NotNullWhen(true)] out T11? value, out OneOf remainder) +#else + public bool TryPickT11(out T11? value, out OneOf remainder) +#endif { value = IsT11 ? AsT11 : default; remainder = _index switch @@ -1085,12 +1135,16 @@ public bool TryPickT11(out T11 value, out OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT11; } - public bool TryPickT12(out T12 value, out OneOf remainder) +#if NET + public bool TryPickT12([NotNullWhen(true)] out T12? value, out OneOf remainder) +#else + public bool TryPickT12(out T12? value, out OneOf remainder) +#endif { value = IsT12 ? AsT12 : default; remainder = _index switch @@ -1127,12 +1181,16 @@ public bool TryPickT12(out T12 value, out OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT12; } - public bool TryPickT13(out T13 value, out OneOf remainder) +#if NET + public bool TryPickT13([NotNullWhen(true)] out T13? value, out OneOf remainder) +#else + public bool TryPickT13(out T13? value, out OneOf remainder) +#endif { value = IsT13 ? AsT13 : default; remainder = _index switch @@ -1169,12 +1227,16 @@ public bool TryPickT13(out T13 value, out OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT13; } - public bool TryPickT14(out T14 value, out OneOf remainder) +#if NET + public bool TryPickT14([NotNullWhen(true)] out T14? value, out OneOf remainder) +#else + public bool TryPickT14(out T14? value, out OneOf remainder) +#endif { value = IsT14 ? AsT14 : default; remainder = _index switch @@ -1211,12 +1273,16 @@ public bool TryPickT14(out T14 value, out OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT14; } - public bool TryPickT15(out T15 value, out OneOf remainder) +#if NET + public bool TryPickT15([NotNullWhen(true)] out T15? value, out OneOf remainder) +#else + public bool TryPickT15(out T15? value, out OneOf remainder) +#endif { value = IsT15 ? AsT15 : default; remainder = _index switch @@ -1253,12 +1319,16 @@ public bool TryPickT15(out T15 value, out OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT15; } - public bool TryPickT16(out T16 value, out OneOf remainder) +#if NET + public bool TryPickT16([NotNullWhen(true)] out T16? value, out OneOf remainder) +#else + public bool TryPickT16(out T16? value, out OneOf remainder) +#endif { value = IsT16 ? AsT16 : default; remainder = _index switch @@ -1295,12 +1365,16 @@ public bool TryPickT16(out T16 value, out OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT16; } - public bool TryPickT17(out T17 value, out OneOf remainder) +#if NET + public bool TryPickT17([NotNullWhen(true)] out T17? value, out OneOf remainder) +#else + public bool TryPickT17(out T17? value, out OneOf remainder) +#endif { value = IsT17 ? AsT17 : default; remainder = _index switch @@ -1337,12 +1411,16 @@ public bool TryPickT17(out T17 value, out OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT17; } - public bool TryPickT18(out T18 value, out OneOf remainder) +#if NET + public bool TryPickT18([NotNullWhen(true)] out T18? value, out OneOf remainder) +#else + public bool TryPickT18(out T18? value, out OneOf remainder) +#endif { value = IsT18 ? AsT18 : default; remainder = _index switch @@ -1379,12 +1457,16 @@ public bool TryPickT18(out T18 value, out OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT18; } - public bool TryPickT19(out T19 value, out OneOf remainder) +#if NET + public bool TryPickT19([NotNullWhen(true)] out T19? value, out OneOf remainder) +#else + public bool TryPickT19(out T19? value, out OneOf remainder) +#endif { value = IsT19 ? AsT19 : default; remainder = _index switch @@ -1421,12 +1503,16 @@ public bool TryPickT19(out T19 value, out OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT19; } - public bool TryPickT20(out T20 value, out OneOf remainder) +#if NET + public bool TryPickT20([NotNullWhen(true)] out T20? value, out OneOf remainder) +#else + public bool TryPickT20(out T20? value, out OneOf remainder) +#endif { value = IsT20 ? AsT20 : default; remainder = _index switch @@ -1463,12 +1549,16 @@ public bool TryPickT20(out T20 value, out OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT20; } - public bool TryPickT21(out T21 value, out OneOf remainder) +#if NET + public bool TryPickT21([NotNullWhen(true)] out T21? value, out OneOf remainder) +#else + public bool TryPickT21(out T21? value, out OneOf remainder) +#endif { value = IsT21 ? AsT21 : default; remainder = _index switch @@ -1505,12 +1595,16 @@ public bool TryPickT21(out T21 value, out OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT21; } - public bool TryPickT22(out T22 value, out OneOf remainder) +#if NET + public bool TryPickT22([NotNullWhen(true)] out T22? value, out OneOf remainder) +#else + public bool TryPickT22(out T22? value, out OneOf remainder) +#endif { value = IsT22 ? AsT22 : default; remainder = _index switch @@ -1547,12 +1641,16 @@ public bool TryPickT22(out T22 value, out OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT22; } - public bool TryPickT23(out T23 value, out OneOf remainder) +#if NET + public bool TryPickT23([NotNullWhen(true)] out T23? value, out OneOf remainder) +#else + public bool TryPickT23(out T23? value, out OneOf remainder) +#endif { value = IsT23 ? AsT23 : default; remainder = _index switch @@ -1589,12 +1687,16 @@ public bool TryPickT23(out T23 value, out OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT23; } - public bool TryPickT24(out T24 value, out OneOf remainder) +#if NET + public bool TryPickT24([NotNullWhen(true)] out T24? value, out OneOf remainder) +#else + public bool TryPickT24(out T24? value, out OneOf remainder) +#endif { value = IsT24 ? AsT24 : default; remainder = _index switch @@ -1631,12 +1733,16 @@ public bool TryPickT24(out T24 value, out OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT24; } - public bool TryPickT25(out T25 value, out OneOf remainder) +#if NET + public bool TryPickT25([NotNullWhen(true)] out T25? value, out OneOf remainder) +#else + public bool TryPickT25(out T25? value, out OneOf remainder) +#endif { value = IsT25 ? AsT25 : default; remainder = _index switch @@ -1673,12 +1779,16 @@ public bool TryPickT25(out T25 value, out OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT25; } - public bool TryPickT26(out T26 value, out OneOf remainder) +#if NET + public bool TryPickT26([NotNullWhen(true)] out T26? value, out OneOf remainder) +#else + public bool TryPickT26(out T26? value, out OneOf remainder) +#endif { value = IsT26 ? AsT26 : default; remainder = _index switch @@ -1715,12 +1825,16 @@ public bool TryPickT26(out T26 value, out OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT26; } - public bool TryPickT27(out T27 value, out OneOf remainder) +#if NET + public bool TryPickT27([NotNullWhen(true)] out T27? value, out OneOf remainder) +#else + public bool TryPickT27(out T27? value, out OneOf remainder) +#endif { value = IsT27 ? AsT27 : default; remainder = _index switch @@ -1757,12 +1871,16 @@ public bool TryPickT27(out T27 value, out OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT27; } - public bool TryPickT28(out T28 value, out OneOf remainder) +#if NET + public bool TryPickT28([NotNullWhen(true)] out T28? value, out OneOf remainder) +#else + public bool TryPickT28(out T28? value, out OneOf remainder) +#endif { value = IsT28 ? AsT28 : default; remainder = _index switch @@ -1799,12 +1917,16 @@ public bool TryPickT28(out T28 value, out OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT28; } - public bool TryPickT29(out T29 value, out OneOf remainder) +#if NET + public bool TryPickT29([NotNullWhen(true)] out T29? value, out OneOf remainder) +#else + public bool TryPickT29(out T29? value, out OneOf remainder) +#endif { value = IsT29 ? AsT29 : default; remainder = _index switch @@ -1841,12 +1963,16 @@ public bool TryPickT29(out T29 value, out OneOf default, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT29; } - public bool TryPickT30(out T30 value, out OneOf remainder) +#if NET + public bool TryPickT30([NotNullWhen(true)] out T30? value, out OneOf remainder) +#else + public bool TryPickT30(out T30? value, out OneOf remainder) +#endif { value = IsT30 ? AsT30 : default; remainder = _index switch @@ -1883,12 +2009,16 @@ public bool TryPickT30(out T30 value, out OneOf AsT29, 30 => default, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT30; } - public bool TryPickT31(out T31 value, out OneOf remainder) +#if NET + public bool TryPickT31([NotNullWhen(true)] out T31? value, out OneOf remainder) +#else + public bool TryPickT31(out T31? value, out OneOf remainder) +#endif { value = IsT31 ? AsT31 : default; remainder = _index switch @@ -1925,7 +2055,7 @@ public bool TryPickT31(out T31 value, out OneOf AsT29, 30 => AsT30, 31 => default, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT31; } @@ -1969,7 +2099,7 @@ bool Equals(OneOfBase false }; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/OneOf.Extended/OneOfBaseT9.generated.cs b/OneOf.Extended/OneOfBaseT9.generated.cs index 9510257..258d867 100644 --- a/OneOf.Extended/OneOfBaseT9.generated.cs +++ b/OneOf.Extended/OneOfBaseT9.generated.cs @@ -1,20 +1,22 @@ +#nullable enable using System; +using System.Diagnostics.CodeAnalysis; using static OneOf.Functions; namespace OneOf { public class OneOfBase : IOneOf { - readonly T0 _value0; - readonly T1 _value1; - readonly T2 _value2; - readonly T3 _value3; - readonly T4 _value4; - readonly T5 _value5; - readonly T6 _value6; - readonly T7 _value7; - readonly T8 _value8; - readonly T9 _value9; + readonly T0 _value0 = default!; + readonly T1 _value1 = default!; + readonly T2 _value2 = default!; + readonly T3 _value3 = default!; + readonly T4 _value4 = default!; + readonly T5 _value5 = default!; + readonly T6 _value6 = default!; + readonly T7 _value7 = default!; + readonly T8 _value8 = default!; + readonly T9 _value9 = default!; readonly int _index; protected OneOfBase(OneOf input) @@ -32,11 +34,11 @@ protected OneOfBase(OneOf input) case 7: _value7 = input.AsT7; break; case 8: _value8 = input.AsT8; break; case 9: _value9 = input.AsT9; break; - default: throw new InvalidOperationException(); + default: throw InvalidIndexException(_index); } } - public object Value => + public object? Value => _index switch { 0 => _value0, @@ -49,7 +51,7 @@ protected OneOfBase(OneOf input) 7 => _value7, 8 => _value8, 9 => _value9, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; public int Index => _index; @@ -160,7 +162,7 @@ public void Switch(Action f0, Action f1, Action f2, Action f3, A f9(_value9); return; } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } public TResult Match(Func f0, Func f1, Func f2, Func f3, Func f4, Func f5, Func f6, Func f7, Func f8, Func f9) @@ -205,14 +207,18 @@ public TResult Match(Func f0, Func f1, Func remainder) +#if NET + public bool TryPickT0([NotNullWhen(true)] out T0? value, out OneOf remainder) +#else + public bool TryPickT0(out T0? value, out OneOf remainder) +#endif { value = IsT0 ? AsT0 : default; remainder = _index switch @@ -227,12 +233,16 @@ public bool TryPickT0(out T0 value, out OneOf AsT7, 8 => AsT8, 9 => AsT9, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT0; } - public bool TryPickT1(out T1 value, out OneOf remainder) +#if NET + public bool TryPickT1([NotNullWhen(true)] out T1? value, out OneOf remainder) +#else + public bool TryPickT1(out T1? value, out OneOf remainder) +#endif { value = IsT1 ? AsT1 : default; remainder = _index switch @@ -247,12 +257,16 @@ public bool TryPickT1(out T1 value, out OneOf AsT7, 8 => AsT8, 9 => AsT9, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT1; } - public bool TryPickT2(out T2 value, out OneOf remainder) +#if NET + public bool TryPickT2([NotNullWhen(true)] out T2? value, out OneOf remainder) +#else + public bool TryPickT2(out T2? value, out OneOf remainder) +#endif { value = IsT2 ? AsT2 : default; remainder = _index switch @@ -267,12 +281,16 @@ public bool TryPickT2(out T2 value, out OneOf AsT7, 8 => AsT8, 9 => AsT9, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT2; } - public bool TryPickT3(out T3 value, out OneOf remainder) +#if NET + public bool TryPickT3([NotNullWhen(true)] out T3? value, out OneOf remainder) +#else + public bool TryPickT3(out T3? value, out OneOf remainder) +#endif { value = IsT3 ? AsT3 : default; remainder = _index switch @@ -287,12 +305,16 @@ public bool TryPickT3(out T3 value, out OneOf AsT7, 8 => AsT8, 9 => AsT9, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT3; } - public bool TryPickT4(out T4 value, out OneOf remainder) +#if NET + public bool TryPickT4([NotNullWhen(true)] out T4? value, out OneOf remainder) +#else + public bool TryPickT4(out T4? value, out OneOf remainder) +#endif { value = IsT4 ? AsT4 : default; remainder = _index switch @@ -307,12 +329,16 @@ public bool TryPickT4(out T4 value, out OneOf AsT7, 8 => AsT8, 9 => AsT9, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT4; } - public bool TryPickT5(out T5 value, out OneOf remainder) +#if NET + public bool TryPickT5([NotNullWhen(true)] out T5? value, out OneOf remainder) +#else + public bool TryPickT5(out T5? value, out OneOf remainder) +#endif { value = IsT5 ? AsT5 : default; remainder = _index switch @@ -327,12 +353,16 @@ public bool TryPickT5(out T5 value, out OneOf AsT7, 8 => AsT8, 9 => AsT9, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT5; } - public bool TryPickT6(out T6 value, out OneOf remainder) +#if NET + public bool TryPickT6([NotNullWhen(true)] out T6? value, out OneOf remainder) +#else + public bool TryPickT6(out T6? value, out OneOf remainder) +#endif { value = IsT6 ? AsT6 : default; remainder = _index switch @@ -347,12 +377,16 @@ public bool TryPickT6(out T6 value, out OneOf AsT7, 8 => AsT8, 9 => AsT9, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT6; } - public bool TryPickT7(out T7 value, out OneOf remainder) +#if NET + public bool TryPickT7([NotNullWhen(true)] out T7? value, out OneOf remainder) +#else + public bool TryPickT7(out T7? value, out OneOf remainder) +#endif { value = IsT7 ? AsT7 : default; remainder = _index switch @@ -367,12 +401,16 @@ public bool TryPickT7(out T7 value, out OneOf default, 8 => AsT8, 9 => AsT9, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT7; } - public bool TryPickT8(out T8 value, out OneOf remainder) +#if NET + public bool TryPickT8([NotNullWhen(true)] out T8? value, out OneOf remainder) +#else + public bool TryPickT8(out T8? value, out OneOf remainder) +#endif { value = IsT8 ? AsT8 : default; remainder = _index switch @@ -387,12 +425,16 @@ public bool TryPickT8(out T8 value, out OneOf AsT7, 8 => default, 9 => AsT9, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT8; } - public bool TryPickT9(out T9 value, out OneOf remainder) +#if NET + public bool TryPickT9([NotNullWhen(true)] out T9? value, out OneOf remainder) +#else + public bool TryPickT9(out T9? value, out OneOf remainder) +#endif { value = IsT9 ? AsT9 : default; remainder = _index switch @@ -407,7 +449,7 @@ public bool TryPickT9(out T9 value, out OneOf AsT7, 8 => AsT8, 9 => default, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT9; } @@ -429,7 +471,7 @@ bool Equals(OneOfBase other) => _ => false }; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/OneOf.Extended/OneOfT10.generated.cs b/OneOf.Extended/OneOfT10.generated.cs index 1297e00..f32eed2 100644 --- a/OneOf.Extended/OneOfT10.generated.cs +++ b/OneOf.Extended/OneOfT10.generated.cs @@ -1,4 +1,6 @@ +#nullable enable using System; +using System.Diagnostics.CodeAnalysis; using static OneOf.Functions; namespace OneOf @@ -18,7 +20,7 @@ namespace OneOf readonly T10 _value10; readonly int _index; - OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default, T10 value10 = default) + OneOf(int index, T0 value0 = default!, T1 value1 = default!, T2 value2 = default!, T3 value3 = default!, T4 value4 = default!, T5 value5 = default!, T6 value6 = default!, T7 value7 = default!, T8 value8 = default!, T9 value9 = default!, T10 value10 = default!) { _index = index; _value0 = value0; @@ -34,7 +36,7 @@ namespace OneOf _value10 = value10; } - public object Value => + public object? Value => _index switch { 0 => _value0, @@ -48,7 +50,7 @@ namespace OneOf 8 => _value8, 9 => _value9, 10 => _value10, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; public int Index => _index; @@ -179,7 +181,7 @@ public void Switch(Action f0, Action f1, Action f2, Action f3, A f10(_value10); return; } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } public TResult Match(Func f0, Func f1, Func f2, Func f3, Func f4, Func f5, Func f6, Func f7, Func f8, Func f9, Func f10) @@ -228,7 +230,7 @@ public TResult Match(Func f0, Func f1, Func FromT0(T0 input) => input; @@ -263,7 +265,7 @@ public OneOf MapT0(Fu 8 => AsT8, 9 => AsT9, 10 => AsT10, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -286,7 +288,7 @@ public OneOf MapT1(Fu 8 => AsT8, 9 => AsT9, 10 => AsT10, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -309,7 +311,7 @@ public OneOf MapT2(Fu 8 => AsT8, 9 => AsT9, 10 => AsT10, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -332,7 +334,7 @@ public OneOf MapT3(Fu 8 => AsT8, 9 => AsT9, 10 => AsT10, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -355,7 +357,7 @@ public OneOf MapT4(Fu 8 => AsT8, 9 => AsT9, 10 => AsT10, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -378,7 +380,7 @@ public OneOf MapT5(Fu 8 => AsT8, 9 => AsT9, 10 => AsT10, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -401,7 +403,7 @@ public OneOf MapT6(Fu 8 => AsT8, 9 => AsT9, 10 => AsT10, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -424,7 +426,7 @@ public OneOf MapT7(Fu 8 => AsT8, 9 => AsT9, 10 => AsT10, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -447,7 +449,7 @@ public OneOf MapT8(Fu 8 => mapFunc(AsT8), 9 => AsT9, 10 => AsT10, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -470,7 +472,7 @@ public OneOf MapT9(Fu 8 => AsT8, 9 => mapFunc(AsT9), 10 => AsT10, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -493,11 +495,15 @@ public OneOf MapT10(Fu 8 => AsT8, 9 => AsT9, 10 => mapFunc(AsT10), - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } - public bool TryPickT0(out T0 value, out OneOf remainder) +#if NET + public bool TryPickT0([NotNullWhen(true)] out T0? value, out OneOf remainder) +#else + public bool TryPickT0(out T0? value, out OneOf remainder) +#endif { value = IsT0 ? AsT0 : default; remainder = _index switch @@ -513,12 +519,16 @@ public bool TryPickT0(out T0 value, out OneOf AsT8, 9 => AsT9, 10 => AsT10, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT0; } - public bool TryPickT1(out T1 value, out OneOf remainder) +#if NET + public bool TryPickT1([NotNullWhen(true)] out T1? value, out OneOf remainder) +#else + public bool TryPickT1(out T1? value, out OneOf remainder) +#endif { value = IsT1 ? AsT1 : default; remainder = _index switch @@ -534,12 +544,16 @@ public bool TryPickT1(out T1 value, out OneOf AsT8, 9 => AsT9, 10 => AsT10, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT1; } - public bool TryPickT2(out T2 value, out OneOf remainder) +#if NET + public bool TryPickT2([NotNullWhen(true)] out T2? value, out OneOf remainder) +#else + public bool TryPickT2(out T2? value, out OneOf remainder) +#endif { value = IsT2 ? AsT2 : default; remainder = _index switch @@ -555,12 +569,16 @@ public bool TryPickT2(out T2 value, out OneOf AsT8, 9 => AsT9, 10 => AsT10, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT2; } - public bool TryPickT3(out T3 value, out OneOf remainder) +#if NET + public bool TryPickT3([NotNullWhen(true)] out T3? value, out OneOf remainder) +#else + public bool TryPickT3(out T3? value, out OneOf remainder) +#endif { value = IsT3 ? AsT3 : default; remainder = _index switch @@ -576,12 +594,16 @@ public bool TryPickT3(out T3 value, out OneOf AsT8, 9 => AsT9, 10 => AsT10, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT3; } - public bool TryPickT4(out T4 value, out OneOf remainder) +#if NET + public bool TryPickT4([NotNullWhen(true)] out T4? value, out OneOf remainder) +#else + public bool TryPickT4(out T4? value, out OneOf remainder) +#endif { value = IsT4 ? AsT4 : default; remainder = _index switch @@ -597,12 +619,16 @@ public bool TryPickT4(out T4 value, out OneOf AsT8, 9 => AsT9, 10 => AsT10, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT4; } - public bool TryPickT5(out T5 value, out OneOf remainder) +#if NET + public bool TryPickT5([NotNullWhen(true)] out T5? value, out OneOf remainder) +#else + public bool TryPickT5(out T5? value, out OneOf remainder) +#endif { value = IsT5 ? AsT5 : default; remainder = _index switch @@ -618,12 +644,16 @@ public bool TryPickT5(out T5 value, out OneOf AsT8, 9 => AsT9, 10 => AsT10, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT5; } - public bool TryPickT6(out T6 value, out OneOf remainder) +#if NET + public bool TryPickT6([NotNullWhen(true)] out T6? value, out OneOf remainder) +#else + public bool TryPickT6(out T6? value, out OneOf remainder) +#endif { value = IsT6 ? AsT6 : default; remainder = _index switch @@ -639,12 +669,16 @@ public bool TryPickT6(out T6 value, out OneOf AsT8, 9 => AsT9, 10 => AsT10, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT6; } - public bool TryPickT7(out T7 value, out OneOf remainder) +#if NET + public bool TryPickT7([NotNullWhen(true)] out T7? value, out OneOf remainder) +#else + public bool TryPickT7(out T7? value, out OneOf remainder) +#endif { value = IsT7 ? AsT7 : default; remainder = _index switch @@ -660,12 +694,16 @@ public bool TryPickT7(out T7 value, out OneOf AsT8, 9 => AsT9, 10 => AsT10, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT7; } - public bool TryPickT8(out T8 value, out OneOf remainder) +#if NET + public bool TryPickT8([NotNullWhen(true)] out T8? value, out OneOf remainder) +#else + public bool TryPickT8(out T8? value, out OneOf remainder) +#endif { value = IsT8 ? AsT8 : default; remainder = _index switch @@ -681,12 +719,16 @@ public bool TryPickT8(out T8 value, out OneOf default, 9 => AsT9, 10 => AsT10, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT8; } - public bool TryPickT9(out T9 value, out OneOf remainder) +#if NET + public bool TryPickT9([NotNullWhen(true)] out T9? value, out OneOf remainder) +#else + public bool TryPickT9(out T9? value, out OneOf remainder) +#endif { value = IsT9 ? AsT9 : default; remainder = _index switch @@ -702,12 +744,16 @@ public bool TryPickT9(out T9 value, out OneOf AsT8, 9 => default, 10 => AsT10, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT9; } - public bool TryPickT10(out T10 value, out OneOf remainder) +#if NET + public bool TryPickT10([NotNullWhen(true)] out T10? value, out OneOf remainder) +#else + public bool TryPickT10(out T10? value, out OneOf remainder) +#endif { value = IsT10 ? AsT10 : default; remainder = _index switch @@ -723,7 +769,7 @@ public bool TryPickT10(out T10 value, out OneOf AsT8, 9 => AsT9, 10 => default, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT10; } @@ -746,7 +792,7 @@ bool Equals(OneOf other) => _ => false }; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/OneOf.Extended/OneOfT11.generated.cs b/OneOf.Extended/OneOfT11.generated.cs index 4b97d9f..b31a4f2 100644 --- a/OneOf.Extended/OneOfT11.generated.cs +++ b/OneOf.Extended/OneOfT11.generated.cs @@ -1,4 +1,6 @@ +#nullable enable using System; +using System.Diagnostics.CodeAnalysis; using static OneOf.Functions; namespace OneOf @@ -19,7 +21,7 @@ namespace OneOf readonly T11 _value11; readonly int _index; - OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default, T10 value10 = default, T11 value11 = default) + OneOf(int index, T0 value0 = default!, T1 value1 = default!, T2 value2 = default!, T3 value3 = default!, T4 value4 = default!, T5 value5 = default!, T6 value6 = default!, T7 value7 = default!, T8 value8 = default!, T9 value9 = default!, T10 value10 = default!, T11 value11 = default!) { _index = index; _value0 = value0; @@ -36,7 +38,7 @@ namespace OneOf _value11 = value11; } - public object Value => + public object? Value => _index switch { 0 => _value0, @@ -51,7 +53,7 @@ namespace OneOf 9 => _value9, 10 => _value10, 11 => _value11, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; public int Index => _index; @@ -193,7 +195,7 @@ public void Switch(Action f0, Action f1, Action f2, Action f3, A f11(_value11); return; } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } public TResult Match(Func f0, Func f1, Func f2, Func f3, Func f4, Func f5, Func f6, Func f7, Func f8, Func f9, Func f10, Func f11) @@ -246,7 +248,7 @@ public TResult Match(Func f0, Func f1, Func FromT0(T0 input) => input; @@ -283,7 +285,7 @@ public OneOf MapT0 AsT9, 10 => AsT10, 11 => AsT11, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -307,7 +309,7 @@ public OneOf MapT1 AsT9, 10 => AsT10, 11 => AsT11, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -331,7 +333,7 @@ public OneOf MapT2 AsT9, 10 => AsT10, 11 => AsT11, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -355,7 +357,7 @@ public OneOf MapT3 AsT9, 10 => AsT10, 11 => AsT11, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -379,7 +381,7 @@ public OneOf MapT4 AsT9, 10 => AsT10, 11 => AsT11, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -403,7 +405,7 @@ public OneOf MapT5 AsT9, 10 => AsT10, 11 => AsT11, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -427,7 +429,7 @@ public OneOf MapT6 AsT9, 10 => AsT10, 11 => AsT11, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -451,7 +453,7 @@ public OneOf MapT7 AsT9, 10 => AsT10, 11 => AsT11, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -475,7 +477,7 @@ public OneOf MapT8 AsT9, 10 => AsT10, 11 => AsT11, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -499,7 +501,7 @@ public OneOf MapT9 mapFunc(AsT9), 10 => AsT10, 11 => AsT11, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -523,7 +525,7 @@ public OneOf MapT10 AsT9, 10 => mapFunc(AsT10), 11 => AsT11, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -547,11 +549,15 @@ public OneOf MapT11 AsT9, 10 => AsT10, 11 => mapFunc(AsT11), - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } - public bool TryPickT0(out T0 value, out OneOf remainder) +#if NET + public bool TryPickT0([NotNullWhen(true)] out T0? value, out OneOf remainder) +#else + public bool TryPickT0(out T0? value, out OneOf remainder) +#endif { value = IsT0 ? AsT0 : default; remainder = _index switch @@ -568,12 +574,16 @@ public bool TryPickT0(out T0 value, out OneOf AsT9, 10 => AsT10, 11 => AsT11, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT0; } - public bool TryPickT1(out T1 value, out OneOf remainder) +#if NET + public bool TryPickT1([NotNullWhen(true)] out T1? value, out OneOf remainder) +#else + public bool TryPickT1(out T1? value, out OneOf remainder) +#endif { value = IsT1 ? AsT1 : default; remainder = _index switch @@ -590,12 +600,16 @@ public bool TryPickT1(out T1 value, out OneOf AsT9, 10 => AsT10, 11 => AsT11, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT1; } - public bool TryPickT2(out T2 value, out OneOf remainder) +#if NET + public bool TryPickT2([NotNullWhen(true)] out T2? value, out OneOf remainder) +#else + public bool TryPickT2(out T2? value, out OneOf remainder) +#endif { value = IsT2 ? AsT2 : default; remainder = _index switch @@ -612,12 +626,16 @@ public bool TryPickT2(out T2 value, out OneOf AsT9, 10 => AsT10, 11 => AsT11, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT2; } - public bool TryPickT3(out T3 value, out OneOf remainder) +#if NET + public bool TryPickT3([NotNullWhen(true)] out T3? value, out OneOf remainder) +#else + public bool TryPickT3(out T3? value, out OneOf remainder) +#endif { value = IsT3 ? AsT3 : default; remainder = _index switch @@ -634,12 +652,16 @@ public bool TryPickT3(out T3 value, out OneOf AsT9, 10 => AsT10, 11 => AsT11, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT3; } - public bool TryPickT4(out T4 value, out OneOf remainder) +#if NET + public bool TryPickT4([NotNullWhen(true)] out T4? value, out OneOf remainder) +#else + public bool TryPickT4(out T4? value, out OneOf remainder) +#endif { value = IsT4 ? AsT4 : default; remainder = _index switch @@ -656,12 +678,16 @@ public bool TryPickT4(out T4 value, out OneOf AsT9, 10 => AsT10, 11 => AsT11, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT4; } - public bool TryPickT5(out T5 value, out OneOf remainder) +#if NET + public bool TryPickT5([NotNullWhen(true)] out T5? value, out OneOf remainder) +#else + public bool TryPickT5(out T5? value, out OneOf remainder) +#endif { value = IsT5 ? AsT5 : default; remainder = _index switch @@ -678,12 +704,16 @@ public bool TryPickT5(out T5 value, out OneOf AsT9, 10 => AsT10, 11 => AsT11, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT5; } - public bool TryPickT6(out T6 value, out OneOf remainder) +#if NET + public bool TryPickT6([NotNullWhen(true)] out T6? value, out OneOf remainder) +#else + public bool TryPickT6(out T6? value, out OneOf remainder) +#endif { value = IsT6 ? AsT6 : default; remainder = _index switch @@ -700,12 +730,16 @@ public bool TryPickT6(out T6 value, out OneOf AsT9, 10 => AsT10, 11 => AsT11, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT6; } - public bool TryPickT7(out T7 value, out OneOf remainder) +#if NET + public bool TryPickT7([NotNullWhen(true)] out T7? value, out OneOf remainder) +#else + public bool TryPickT7(out T7? value, out OneOf remainder) +#endif { value = IsT7 ? AsT7 : default; remainder = _index switch @@ -722,12 +756,16 @@ public bool TryPickT7(out T7 value, out OneOf AsT9, 10 => AsT10, 11 => AsT11, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT7; } - public bool TryPickT8(out T8 value, out OneOf remainder) +#if NET + public bool TryPickT8([NotNullWhen(true)] out T8? value, out OneOf remainder) +#else + public bool TryPickT8(out T8? value, out OneOf remainder) +#endif { value = IsT8 ? AsT8 : default; remainder = _index switch @@ -744,12 +782,16 @@ public bool TryPickT8(out T8 value, out OneOf AsT9, 10 => AsT10, 11 => AsT11, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT8; } - public bool TryPickT9(out T9 value, out OneOf remainder) +#if NET + public bool TryPickT9([NotNullWhen(true)] out T9? value, out OneOf remainder) +#else + public bool TryPickT9(out T9? value, out OneOf remainder) +#endif { value = IsT9 ? AsT9 : default; remainder = _index switch @@ -766,12 +808,16 @@ public bool TryPickT9(out T9 value, out OneOf default, 10 => AsT10, 11 => AsT11, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT9; } - public bool TryPickT10(out T10 value, out OneOf remainder) +#if NET + public bool TryPickT10([NotNullWhen(true)] out T10? value, out OneOf remainder) +#else + public bool TryPickT10(out T10? value, out OneOf remainder) +#endif { value = IsT10 ? AsT10 : default; remainder = _index switch @@ -788,12 +834,16 @@ public bool TryPickT10(out T10 value, out OneOf AsT9, 10 => default, 11 => AsT11, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT10; } - public bool TryPickT11(out T11 value, out OneOf remainder) +#if NET + public bool TryPickT11([NotNullWhen(true)] out T11? value, out OneOf remainder) +#else + public bool TryPickT11(out T11? value, out OneOf remainder) +#endif { value = IsT11 ? AsT11 : default; remainder = _index switch @@ -810,7 +860,7 @@ public bool TryPickT11(out T11 value, out OneOf AsT9, 10 => AsT10, 11 => default, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT11; } @@ -834,7 +884,7 @@ bool Equals(OneOf other) => _ => false }; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/OneOf.Extended/OneOfT12.generated.cs b/OneOf.Extended/OneOfT12.generated.cs index 0801a8b..a4ad7f9 100644 --- a/OneOf.Extended/OneOfT12.generated.cs +++ b/OneOf.Extended/OneOfT12.generated.cs @@ -1,4 +1,6 @@ +#nullable enable using System; +using System.Diagnostics.CodeAnalysis; using static OneOf.Functions; namespace OneOf @@ -20,7 +22,7 @@ namespace OneOf readonly T12 _value12; readonly int _index; - OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default, T10 value10 = default, T11 value11 = default, T12 value12 = default) + OneOf(int index, T0 value0 = default!, T1 value1 = default!, T2 value2 = default!, T3 value3 = default!, T4 value4 = default!, T5 value5 = default!, T6 value6 = default!, T7 value7 = default!, T8 value8 = default!, T9 value9 = default!, T10 value10 = default!, T11 value11 = default!, T12 value12 = default!) { _index = index; _value0 = value0; @@ -38,7 +40,7 @@ namespace OneOf _value12 = value12; } - public object Value => + public object? Value => _index switch { 0 => _value0, @@ -54,7 +56,7 @@ namespace OneOf 10 => _value10, 11 => _value11, 12 => _value12, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; public int Index => _index; @@ -207,7 +209,7 @@ public void Switch(Action f0, Action f1, Action f2, Action f3, A f12(_value12); return; } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } public TResult Match(Func f0, Func f1, Func f2, Func f3, Func f4, Func f5, Func f6, Func f7, Func f8, Func f9, Func f10, Func f11, Func f12) @@ -264,7 +266,7 @@ public TResult Match(Func f0, Func f1, Func FromT0(T0 input) => input; @@ -303,7 +305,7 @@ public OneOf MapT0 AsT10, 11 => AsT11, 12 => AsT12, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -328,7 +330,7 @@ public OneOf MapT1 AsT10, 11 => AsT11, 12 => AsT12, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -353,7 +355,7 @@ public OneOf MapT2 AsT10, 11 => AsT11, 12 => AsT12, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -378,7 +380,7 @@ public OneOf MapT3 AsT10, 11 => AsT11, 12 => AsT12, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -403,7 +405,7 @@ public OneOf MapT4 AsT10, 11 => AsT11, 12 => AsT12, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -428,7 +430,7 @@ public OneOf MapT5 AsT10, 11 => AsT11, 12 => AsT12, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -453,7 +455,7 @@ public OneOf MapT6 AsT10, 11 => AsT11, 12 => AsT12, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -478,7 +480,7 @@ public OneOf MapT7 AsT10, 11 => AsT11, 12 => AsT12, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -503,7 +505,7 @@ public OneOf MapT8 AsT10, 11 => AsT11, 12 => AsT12, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -528,7 +530,7 @@ public OneOf MapT9 AsT10, 11 => AsT11, 12 => AsT12, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -553,7 +555,7 @@ public OneOf MapT10 mapFunc(AsT10), 11 => AsT11, 12 => AsT12, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -578,7 +580,7 @@ public OneOf MapT11 AsT10, 11 => mapFunc(AsT11), 12 => AsT12, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -603,11 +605,15 @@ public OneOf MapT12 AsT10, 11 => AsT11, 12 => mapFunc(AsT12), - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } - public bool TryPickT0(out T0 value, out OneOf remainder) +#if NET + public bool TryPickT0([NotNullWhen(true)] out T0? value, out OneOf remainder) +#else + public bool TryPickT0(out T0? value, out OneOf remainder) +#endif { value = IsT0 ? AsT0 : default; remainder = _index switch @@ -625,12 +631,16 @@ public bool TryPickT0(out T0 value, out OneOf AsT10, 11 => AsT11, 12 => AsT12, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT0; } - public bool TryPickT1(out T1 value, out OneOf remainder) +#if NET + public bool TryPickT1([NotNullWhen(true)] out T1? value, out OneOf remainder) +#else + public bool TryPickT1(out T1? value, out OneOf remainder) +#endif { value = IsT1 ? AsT1 : default; remainder = _index switch @@ -648,12 +658,16 @@ public bool TryPickT1(out T1 value, out OneOf AsT10, 11 => AsT11, 12 => AsT12, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT1; } - public bool TryPickT2(out T2 value, out OneOf remainder) +#if NET + public bool TryPickT2([NotNullWhen(true)] out T2? value, out OneOf remainder) +#else + public bool TryPickT2(out T2? value, out OneOf remainder) +#endif { value = IsT2 ? AsT2 : default; remainder = _index switch @@ -671,12 +685,16 @@ public bool TryPickT2(out T2 value, out OneOf AsT10, 11 => AsT11, 12 => AsT12, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT2; } - public bool TryPickT3(out T3 value, out OneOf remainder) +#if NET + public bool TryPickT3([NotNullWhen(true)] out T3? value, out OneOf remainder) +#else + public bool TryPickT3(out T3? value, out OneOf remainder) +#endif { value = IsT3 ? AsT3 : default; remainder = _index switch @@ -694,12 +712,16 @@ public bool TryPickT3(out T3 value, out OneOf AsT10, 11 => AsT11, 12 => AsT12, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT3; } - public bool TryPickT4(out T4 value, out OneOf remainder) +#if NET + public bool TryPickT4([NotNullWhen(true)] out T4? value, out OneOf remainder) +#else + public bool TryPickT4(out T4? value, out OneOf remainder) +#endif { value = IsT4 ? AsT4 : default; remainder = _index switch @@ -717,12 +739,16 @@ public bool TryPickT4(out T4 value, out OneOf AsT10, 11 => AsT11, 12 => AsT12, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT4; } - public bool TryPickT5(out T5 value, out OneOf remainder) +#if NET + public bool TryPickT5([NotNullWhen(true)] out T5? value, out OneOf remainder) +#else + public bool TryPickT5(out T5? value, out OneOf remainder) +#endif { value = IsT5 ? AsT5 : default; remainder = _index switch @@ -740,12 +766,16 @@ public bool TryPickT5(out T5 value, out OneOf AsT10, 11 => AsT11, 12 => AsT12, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT5; } - public bool TryPickT6(out T6 value, out OneOf remainder) +#if NET + public bool TryPickT6([NotNullWhen(true)] out T6? value, out OneOf remainder) +#else + public bool TryPickT6(out T6? value, out OneOf remainder) +#endif { value = IsT6 ? AsT6 : default; remainder = _index switch @@ -763,12 +793,16 @@ public bool TryPickT6(out T6 value, out OneOf AsT10, 11 => AsT11, 12 => AsT12, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT6; } - public bool TryPickT7(out T7 value, out OneOf remainder) +#if NET + public bool TryPickT7([NotNullWhen(true)] out T7? value, out OneOf remainder) +#else + public bool TryPickT7(out T7? value, out OneOf remainder) +#endif { value = IsT7 ? AsT7 : default; remainder = _index switch @@ -786,12 +820,16 @@ public bool TryPickT7(out T7 value, out OneOf AsT10, 11 => AsT11, 12 => AsT12, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT7; } - public bool TryPickT8(out T8 value, out OneOf remainder) +#if NET + public bool TryPickT8([NotNullWhen(true)] out T8? value, out OneOf remainder) +#else + public bool TryPickT8(out T8? value, out OneOf remainder) +#endif { value = IsT8 ? AsT8 : default; remainder = _index switch @@ -809,12 +847,16 @@ public bool TryPickT8(out T8 value, out OneOf AsT10, 11 => AsT11, 12 => AsT12, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT8; } - public bool TryPickT9(out T9 value, out OneOf remainder) +#if NET + public bool TryPickT9([NotNullWhen(true)] out T9? value, out OneOf remainder) +#else + public bool TryPickT9(out T9? value, out OneOf remainder) +#endif { value = IsT9 ? AsT9 : default; remainder = _index switch @@ -832,12 +874,16 @@ public bool TryPickT9(out T9 value, out OneOf AsT10, 11 => AsT11, 12 => AsT12, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT9; } - public bool TryPickT10(out T10 value, out OneOf remainder) +#if NET + public bool TryPickT10([NotNullWhen(true)] out T10? value, out OneOf remainder) +#else + public bool TryPickT10(out T10? value, out OneOf remainder) +#endif { value = IsT10 ? AsT10 : default; remainder = _index switch @@ -855,12 +901,16 @@ public bool TryPickT10(out T10 value, out OneOf default, 11 => AsT11, 12 => AsT12, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT10; } - public bool TryPickT11(out T11 value, out OneOf remainder) +#if NET + public bool TryPickT11([NotNullWhen(true)] out T11? value, out OneOf remainder) +#else + public bool TryPickT11(out T11? value, out OneOf remainder) +#endif { value = IsT11 ? AsT11 : default; remainder = _index switch @@ -878,12 +928,16 @@ public bool TryPickT11(out T11 value, out OneOf AsT10, 11 => default, 12 => AsT12, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT11; } - public bool TryPickT12(out T12 value, out OneOf remainder) +#if NET + public bool TryPickT12([NotNullWhen(true)] out T12? value, out OneOf remainder) +#else + public bool TryPickT12(out T12? value, out OneOf remainder) +#endif { value = IsT12 ? AsT12 : default; remainder = _index switch @@ -901,7 +955,7 @@ public bool TryPickT12(out T12 value, out OneOf AsT10, 11 => AsT11, 12 => default, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT12; } @@ -926,7 +980,7 @@ bool Equals(OneOf other) _ => false }; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/OneOf.Extended/OneOfT13.generated.cs b/OneOf.Extended/OneOfT13.generated.cs index c5d1ac5..41a2d25 100644 --- a/OneOf.Extended/OneOfT13.generated.cs +++ b/OneOf.Extended/OneOfT13.generated.cs @@ -1,4 +1,6 @@ +#nullable enable using System; +using System.Diagnostics.CodeAnalysis; using static OneOf.Functions; namespace OneOf @@ -21,7 +23,7 @@ namespace OneOf readonly T13 _value13; readonly int _index; - OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default, T10 value10 = default, T11 value11 = default, T12 value12 = default, T13 value13 = default) + OneOf(int index, T0 value0 = default!, T1 value1 = default!, T2 value2 = default!, T3 value3 = default!, T4 value4 = default!, T5 value5 = default!, T6 value6 = default!, T7 value7 = default!, T8 value8 = default!, T9 value9 = default!, T10 value10 = default!, T11 value11 = default!, T12 value12 = default!, T13 value13 = default!) { _index = index; _value0 = value0; @@ -40,7 +42,7 @@ namespace OneOf _value13 = value13; } - public object Value => + public object? Value => _index switch { 0 => _value0, @@ -57,7 +59,7 @@ namespace OneOf 11 => _value11, 12 => _value12, 13 => _value13, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; public int Index => _index; @@ -221,7 +223,7 @@ public void Switch(Action f0, Action f1, Action f2, Action f3, A f13(_value13); return; } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } public TResult Match(Func f0, Func f1, Func f2, Func f3, Func f4, Func f5, Func f6, Func f7, Func f8, Func f9, Func f10, Func f11, Func f12, Func f13) @@ -282,7 +284,7 @@ public TResult Match(Func f0, Func f1, Func FromT0(T0 input) => input; @@ -323,7 +325,7 @@ public OneOf Ma 11 => AsT11, 12 => AsT12, 13 => AsT13, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -349,7 +351,7 @@ public OneOf Ma 11 => AsT11, 12 => AsT12, 13 => AsT13, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -375,7 +377,7 @@ public OneOf Ma 11 => AsT11, 12 => AsT12, 13 => AsT13, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -401,7 +403,7 @@ public OneOf Ma 11 => AsT11, 12 => AsT12, 13 => AsT13, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -427,7 +429,7 @@ public OneOf Ma 11 => AsT11, 12 => AsT12, 13 => AsT13, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -453,7 +455,7 @@ public OneOf Ma 11 => AsT11, 12 => AsT12, 13 => AsT13, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -479,7 +481,7 @@ public OneOf Ma 11 => AsT11, 12 => AsT12, 13 => AsT13, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -505,7 +507,7 @@ public OneOf Ma 11 => AsT11, 12 => AsT12, 13 => AsT13, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -531,7 +533,7 @@ public OneOf Ma 11 => AsT11, 12 => AsT12, 13 => AsT13, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -557,7 +559,7 @@ public OneOf Ma 11 => AsT11, 12 => AsT12, 13 => AsT13, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -583,7 +585,7 @@ public OneOf Map 11 => AsT11, 12 => AsT12, 13 => AsT13, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -609,7 +611,7 @@ public OneOf Map 11 => mapFunc(AsT11), 12 => AsT12, 13 => AsT13, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -635,7 +637,7 @@ public OneOf Map 11 => AsT11, 12 => mapFunc(AsT12), 13 => AsT13, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -661,11 +663,15 @@ public OneOf Map 11 => AsT11, 12 => AsT12, 13 => mapFunc(AsT13), - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } - public bool TryPickT0(out T0 value, out OneOf remainder) +#if NET + public bool TryPickT0([NotNullWhen(true)] out T0? value, out OneOf remainder) +#else + public bool TryPickT0(out T0? value, out OneOf remainder) +#endif { value = IsT0 ? AsT0 : default; remainder = _index switch @@ -684,12 +690,16 @@ public bool TryPickT0(out T0 value, out OneOf AsT11, 12 => AsT12, 13 => AsT13, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT0; } - public bool TryPickT1(out T1 value, out OneOf remainder) +#if NET + public bool TryPickT1([NotNullWhen(true)] out T1? value, out OneOf remainder) +#else + public bool TryPickT1(out T1? value, out OneOf remainder) +#endif { value = IsT1 ? AsT1 : default; remainder = _index switch @@ -708,12 +718,16 @@ public bool TryPickT1(out T1 value, out OneOf AsT11, 12 => AsT12, 13 => AsT13, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT1; } - public bool TryPickT2(out T2 value, out OneOf remainder) +#if NET + public bool TryPickT2([NotNullWhen(true)] out T2? value, out OneOf remainder) +#else + public bool TryPickT2(out T2? value, out OneOf remainder) +#endif { value = IsT2 ? AsT2 : default; remainder = _index switch @@ -732,12 +746,16 @@ public bool TryPickT2(out T2 value, out OneOf AsT11, 12 => AsT12, 13 => AsT13, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT2; } - public bool TryPickT3(out T3 value, out OneOf remainder) +#if NET + public bool TryPickT3([NotNullWhen(true)] out T3? value, out OneOf remainder) +#else + public bool TryPickT3(out T3? value, out OneOf remainder) +#endif { value = IsT3 ? AsT3 : default; remainder = _index switch @@ -756,12 +774,16 @@ public bool TryPickT3(out T3 value, out OneOf AsT11, 12 => AsT12, 13 => AsT13, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT3; } - public bool TryPickT4(out T4 value, out OneOf remainder) +#if NET + public bool TryPickT4([NotNullWhen(true)] out T4? value, out OneOf remainder) +#else + public bool TryPickT4(out T4? value, out OneOf remainder) +#endif { value = IsT4 ? AsT4 : default; remainder = _index switch @@ -780,12 +802,16 @@ public bool TryPickT4(out T4 value, out OneOf AsT11, 12 => AsT12, 13 => AsT13, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT4; } - public bool TryPickT5(out T5 value, out OneOf remainder) +#if NET + public bool TryPickT5([NotNullWhen(true)] out T5? value, out OneOf remainder) +#else + public bool TryPickT5(out T5? value, out OneOf remainder) +#endif { value = IsT5 ? AsT5 : default; remainder = _index switch @@ -804,12 +830,16 @@ public bool TryPickT5(out T5 value, out OneOf AsT11, 12 => AsT12, 13 => AsT13, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT5; } - public bool TryPickT6(out T6 value, out OneOf remainder) +#if NET + public bool TryPickT6([NotNullWhen(true)] out T6? value, out OneOf remainder) +#else + public bool TryPickT6(out T6? value, out OneOf remainder) +#endif { value = IsT6 ? AsT6 : default; remainder = _index switch @@ -828,12 +858,16 @@ public bool TryPickT6(out T6 value, out OneOf AsT11, 12 => AsT12, 13 => AsT13, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT6; } - public bool TryPickT7(out T7 value, out OneOf remainder) +#if NET + public bool TryPickT7([NotNullWhen(true)] out T7? value, out OneOf remainder) +#else + public bool TryPickT7(out T7? value, out OneOf remainder) +#endif { value = IsT7 ? AsT7 : default; remainder = _index switch @@ -852,12 +886,16 @@ public bool TryPickT7(out T7 value, out OneOf AsT11, 12 => AsT12, 13 => AsT13, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT7; } - public bool TryPickT8(out T8 value, out OneOf remainder) +#if NET + public bool TryPickT8([NotNullWhen(true)] out T8? value, out OneOf remainder) +#else + public bool TryPickT8(out T8? value, out OneOf remainder) +#endif { value = IsT8 ? AsT8 : default; remainder = _index switch @@ -876,12 +914,16 @@ public bool TryPickT8(out T8 value, out OneOf AsT11, 12 => AsT12, 13 => AsT13, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT8; } - public bool TryPickT9(out T9 value, out OneOf remainder) +#if NET + public bool TryPickT9([NotNullWhen(true)] out T9? value, out OneOf remainder) +#else + public bool TryPickT9(out T9? value, out OneOf remainder) +#endif { value = IsT9 ? AsT9 : default; remainder = _index switch @@ -900,12 +942,16 @@ public bool TryPickT9(out T9 value, out OneOf AsT11, 12 => AsT12, 13 => AsT13, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT9; } - public bool TryPickT10(out T10 value, out OneOf remainder) +#if NET + public bool TryPickT10([NotNullWhen(true)] out T10? value, out OneOf remainder) +#else + public bool TryPickT10(out T10? value, out OneOf remainder) +#endif { value = IsT10 ? AsT10 : default; remainder = _index switch @@ -924,12 +970,16 @@ public bool TryPickT10(out T10 value, out OneOf AsT11, 12 => AsT12, 13 => AsT13, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT10; } - public bool TryPickT11(out T11 value, out OneOf remainder) +#if NET + public bool TryPickT11([NotNullWhen(true)] out T11? value, out OneOf remainder) +#else + public bool TryPickT11(out T11? value, out OneOf remainder) +#endif { value = IsT11 ? AsT11 : default; remainder = _index switch @@ -948,12 +998,16 @@ public bool TryPickT11(out T11 value, out OneOf default, 12 => AsT12, 13 => AsT13, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT11; } - public bool TryPickT12(out T12 value, out OneOf remainder) +#if NET + public bool TryPickT12([NotNullWhen(true)] out T12? value, out OneOf remainder) +#else + public bool TryPickT12(out T12? value, out OneOf remainder) +#endif { value = IsT12 ? AsT12 : default; remainder = _index switch @@ -972,12 +1026,16 @@ public bool TryPickT12(out T12 value, out OneOf AsT11, 12 => default, 13 => AsT13, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT12; } - public bool TryPickT13(out T13 value, out OneOf remainder) +#if NET + public bool TryPickT13([NotNullWhen(true)] out T13? value, out OneOf remainder) +#else + public bool TryPickT13(out T13? value, out OneOf remainder) +#endif { value = IsT13 ? AsT13 : default; remainder = _index switch @@ -996,7 +1054,7 @@ public bool TryPickT13(out T13 value, out OneOf AsT11, 12 => AsT12, 13 => default, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT13; } @@ -1022,7 +1080,7 @@ bool Equals(OneOf ot _ => false }; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/OneOf.Extended/OneOfT14.generated.cs b/OneOf.Extended/OneOfT14.generated.cs index e7e9578..817cbb8 100644 --- a/OneOf.Extended/OneOfT14.generated.cs +++ b/OneOf.Extended/OneOfT14.generated.cs @@ -1,4 +1,6 @@ +#nullable enable using System; +using System.Diagnostics.CodeAnalysis; using static OneOf.Functions; namespace OneOf @@ -22,7 +24,7 @@ namespace OneOf readonly T14 _value14; readonly int _index; - OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default, T10 value10 = default, T11 value11 = default, T12 value12 = default, T13 value13 = default, T14 value14 = default) + OneOf(int index, T0 value0 = default!, T1 value1 = default!, T2 value2 = default!, T3 value3 = default!, T4 value4 = default!, T5 value5 = default!, T6 value6 = default!, T7 value7 = default!, T8 value8 = default!, T9 value9 = default!, T10 value10 = default!, T11 value11 = default!, T12 value12 = default!, T13 value13 = default!, T14 value14 = default!) { _index = index; _value0 = value0; @@ -42,7 +44,7 @@ namespace OneOf _value14 = value14; } - public object Value => + public object? Value => _index switch { 0 => _value0, @@ -60,7 +62,7 @@ namespace OneOf 12 => _value12, 13 => _value13, 14 => _value14, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; public int Index => _index; @@ -235,7 +237,7 @@ public void Switch(Action f0, Action f1, Action f2, Action f3, A f14(_value14); return; } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } public TResult Match(Func f0, Func f1, Func f2, Func f3, Func f4, Func f5, Func f6, Func f7, Func f8, Func f9, Func f10, Func f11, Func f12, Func f13, Func f14) @@ -300,7 +302,7 @@ public TResult Match(Func f0, Func f1, Func FromT0(T0 input) => input; @@ -343,7 +345,7 @@ public OneOf AsT12, 13 => AsT13, 14 => AsT14, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -370,7 +372,7 @@ public OneOf AsT12, 13 => AsT13, 14 => AsT14, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -397,7 +399,7 @@ public OneOf AsT12, 13 => AsT13, 14 => AsT14, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -424,7 +426,7 @@ public OneOf AsT12, 13 => AsT13, 14 => AsT14, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -451,7 +453,7 @@ public OneOf AsT12, 13 => AsT13, 14 => AsT14, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -478,7 +480,7 @@ public OneOf AsT12, 13 => AsT13, 14 => AsT14, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -505,7 +507,7 @@ public OneOf AsT12, 13 => AsT13, 14 => AsT14, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -532,7 +534,7 @@ public OneOf AsT12, 13 => AsT13, 14 => AsT14, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -559,7 +561,7 @@ public OneOf AsT12, 13 => AsT13, 14 => AsT14, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -586,7 +588,7 @@ public OneOf AsT12, 13 => AsT13, 14 => AsT14, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -613,7 +615,7 @@ public OneOf AsT12, 13 => AsT13, 14 => AsT14, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -640,7 +642,7 @@ public OneOf AsT12, 13 => AsT13, 14 => AsT14, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -667,7 +669,7 @@ public OneOf mapFunc(AsT12), 13 => AsT13, 14 => AsT14, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -694,7 +696,7 @@ public OneOf AsT12, 13 => mapFunc(AsT13), 14 => AsT14, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -721,11 +723,15 @@ public OneOf AsT12, 13 => AsT13, 14 => mapFunc(AsT14), - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } - public bool TryPickT0(out T0 value, out OneOf remainder) +#if NET + public bool TryPickT0([NotNullWhen(true)] out T0? value, out OneOf remainder) +#else + public bool TryPickT0(out T0? value, out OneOf remainder) +#endif { value = IsT0 ? AsT0 : default; remainder = _index switch @@ -745,12 +751,16 @@ public bool TryPickT0(out T0 value, out OneOf AsT12, 13 => AsT13, 14 => AsT14, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT0; } - public bool TryPickT1(out T1 value, out OneOf remainder) +#if NET + public bool TryPickT1([NotNullWhen(true)] out T1? value, out OneOf remainder) +#else + public bool TryPickT1(out T1? value, out OneOf remainder) +#endif { value = IsT1 ? AsT1 : default; remainder = _index switch @@ -770,12 +780,16 @@ public bool TryPickT1(out T1 value, out OneOf AsT12, 13 => AsT13, 14 => AsT14, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT1; } - public bool TryPickT2(out T2 value, out OneOf remainder) +#if NET + public bool TryPickT2([NotNullWhen(true)] out T2? value, out OneOf remainder) +#else + public bool TryPickT2(out T2? value, out OneOf remainder) +#endif { value = IsT2 ? AsT2 : default; remainder = _index switch @@ -795,12 +809,16 @@ public bool TryPickT2(out T2 value, out OneOf AsT12, 13 => AsT13, 14 => AsT14, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT2; } - public bool TryPickT3(out T3 value, out OneOf remainder) +#if NET + public bool TryPickT3([NotNullWhen(true)] out T3? value, out OneOf remainder) +#else + public bool TryPickT3(out T3? value, out OneOf remainder) +#endif { value = IsT3 ? AsT3 : default; remainder = _index switch @@ -820,12 +838,16 @@ public bool TryPickT3(out T3 value, out OneOf AsT12, 13 => AsT13, 14 => AsT14, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT3; } - public bool TryPickT4(out T4 value, out OneOf remainder) +#if NET + public bool TryPickT4([NotNullWhen(true)] out T4? value, out OneOf remainder) +#else + public bool TryPickT4(out T4? value, out OneOf remainder) +#endif { value = IsT4 ? AsT4 : default; remainder = _index switch @@ -845,12 +867,16 @@ public bool TryPickT4(out T4 value, out OneOf AsT12, 13 => AsT13, 14 => AsT14, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT4; } - public bool TryPickT5(out T5 value, out OneOf remainder) +#if NET + public bool TryPickT5([NotNullWhen(true)] out T5? value, out OneOf remainder) +#else + public bool TryPickT5(out T5? value, out OneOf remainder) +#endif { value = IsT5 ? AsT5 : default; remainder = _index switch @@ -870,12 +896,16 @@ public bool TryPickT5(out T5 value, out OneOf AsT12, 13 => AsT13, 14 => AsT14, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT5; } - public bool TryPickT6(out T6 value, out OneOf remainder) +#if NET + public bool TryPickT6([NotNullWhen(true)] out T6? value, out OneOf remainder) +#else + public bool TryPickT6(out T6? value, out OneOf remainder) +#endif { value = IsT6 ? AsT6 : default; remainder = _index switch @@ -895,12 +925,16 @@ public bool TryPickT6(out T6 value, out OneOf AsT12, 13 => AsT13, 14 => AsT14, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT6; } - public bool TryPickT7(out T7 value, out OneOf remainder) +#if NET + public bool TryPickT7([NotNullWhen(true)] out T7? value, out OneOf remainder) +#else + public bool TryPickT7(out T7? value, out OneOf remainder) +#endif { value = IsT7 ? AsT7 : default; remainder = _index switch @@ -920,12 +954,16 @@ public bool TryPickT7(out T7 value, out OneOf AsT12, 13 => AsT13, 14 => AsT14, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT7; } - public bool TryPickT8(out T8 value, out OneOf remainder) +#if NET + public bool TryPickT8([NotNullWhen(true)] out T8? value, out OneOf remainder) +#else + public bool TryPickT8(out T8? value, out OneOf remainder) +#endif { value = IsT8 ? AsT8 : default; remainder = _index switch @@ -945,12 +983,16 @@ public bool TryPickT8(out T8 value, out OneOf AsT12, 13 => AsT13, 14 => AsT14, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT8; } - public bool TryPickT9(out T9 value, out OneOf remainder) +#if NET + public bool TryPickT9([NotNullWhen(true)] out T9? value, out OneOf remainder) +#else + public bool TryPickT9(out T9? value, out OneOf remainder) +#endif { value = IsT9 ? AsT9 : default; remainder = _index switch @@ -970,12 +1012,16 @@ public bool TryPickT9(out T9 value, out OneOf AsT12, 13 => AsT13, 14 => AsT14, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT9; } - public bool TryPickT10(out T10 value, out OneOf remainder) +#if NET + public bool TryPickT10([NotNullWhen(true)] out T10? value, out OneOf remainder) +#else + public bool TryPickT10(out T10? value, out OneOf remainder) +#endif { value = IsT10 ? AsT10 : default; remainder = _index switch @@ -995,12 +1041,16 @@ public bool TryPickT10(out T10 value, out OneOf AsT12, 13 => AsT13, 14 => AsT14, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT10; } - public bool TryPickT11(out T11 value, out OneOf remainder) +#if NET + public bool TryPickT11([NotNullWhen(true)] out T11? value, out OneOf remainder) +#else + public bool TryPickT11(out T11? value, out OneOf remainder) +#endif { value = IsT11 ? AsT11 : default; remainder = _index switch @@ -1020,12 +1070,16 @@ public bool TryPickT11(out T11 value, out OneOf AsT12, 13 => AsT13, 14 => AsT14, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT11; } - public bool TryPickT12(out T12 value, out OneOf remainder) +#if NET + public bool TryPickT12([NotNullWhen(true)] out T12? value, out OneOf remainder) +#else + public bool TryPickT12(out T12? value, out OneOf remainder) +#endif { value = IsT12 ? AsT12 : default; remainder = _index switch @@ -1045,12 +1099,16 @@ public bool TryPickT12(out T12 value, out OneOf default, 13 => AsT13, 14 => AsT14, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT12; } - public bool TryPickT13(out T13 value, out OneOf remainder) +#if NET + public bool TryPickT13([NotNullWhen(true)] out T13? value, out OneOf remainder) +#else + public bool TryPickT13(out T13? value, out OneOf remainder) +#endif { value = IsT13 ? AsT13 : default; remainder = _index switch @@ -1070,12 +1128,16 @@ public bool TryPickT13(out T13 value, out OneOf AsT12, 13 => default, 14 => AsT14, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT13; } - public bool TryPickT14(out T14 value, out OneOf remainder) +#if NET + public bool TryPickT14([NotNullWhen(true)] out T14? value, out OneOf remainder) +#else + public bool TryPickT14(out T14? value, out OneOf remainder) +#endif { value = IsT14 ? AsT14 : default; remainder = _index switch @@ -1095,7 +1157,7 @@ public bool TryPickT14(out T14 value, out OneOf AsT12, 13 => AsT13, 14 => default, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT14; } @@ -1122,7 +1184,7 @@ bool Equals(OneOf false }; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/OneOf.Extended/OneOfT15.generated.cs b/OneOf.Extended/OneOfT15.generated.cs index 8c3b91d..1336258 100644 --- a/OneOf.Extended/OneOfT15.generated.cs +++ b/OneOf.Extended/OneOfT15.generated.cs @@ -1,4 +1,6 @@ +#nullable enable using System; +using System.Diagnostics.CodeAnalysis; using static OneOf.Functions; namespace OneOf @@ -23,7 +25,7 @@ namespace OneOf readonly T15 _value15; readonly int _index; - OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default, T10 value10 = default, T11 value11 = default, T12 value12 = default, T13 value13 = default, T14 value14 = default, T15 value15 = default) + OneOf(int index, T0 value0 = default!, T1 value1 = default!, T2 value2 = default!, T3 value3 = default!, T4 value4 = default!, T5 value5 = default!, T6 value6 = default!, T7 value7 = default!, T8 value8 = default!, T9 value9 = default!, T10 value10 = default!, T11 value11 = default!, T12 value12 = default!, T13 value13 = default!, T14 value14 = default!, T15 value15 = default!) { _index = index; _value0 = value0; @@ -44,7 +46,7 @@ namespace OneOf _value15 = value15; } - public object Value => + public object? Value => _index switch { 0 => _value0, @@ -63,7 +65,7 @@ namespace OneOf 13 => _value13, 14 => _value14, 15 => _value15, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; public int Index => _index; @@ -249,7 +251,7 @@ public void Switch(Action f0, Action f1, Action f2, Action f3, A f15(_value15); return; } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } public TResult Match(Func f0, Func f1, Func f2, Func f3, Func f4, Func f5, Func f6, Func f7, Func f8, Func f9, Func f10, Func f11, Func f12, Func f13, Func f14, Func f15) @@ -318,7 +320,7 @@ public TResult Match(Func f0, Func f1, Func FromT0(T0 input) => input; @@ -363,7 +365,7 @@ public OneOf AsT13, 14 => AsT14, 15 => AsT15, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -391,7 +393,7 @@ public OneOf AsT13, 14 => AsT14, 15 => AsT15, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -419,7 +421,7 @@ public OneOf AsT13, 14 => AsT14, 15 => AsT15, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -447,7 +449,7 @@ public OneOf AsT13, 14 => AsT14, 15 => AsT15, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -475,7 +477,7 @@ public OneOf AsT13, 14 => AsT14, 15 => AsT15, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -503,7 +505,7 @@ public OneOf AsT13, 14 => AsT14, 15 => AsT15, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -531,7 +533,7 @@ public OneOf AsT13, 14 => AsT14, 15 => AsT15, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -559,7 +561,7 @@ public OneOf AsT13, 14 => AsT14, 15 => AsT15, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -587,7 +589,7 @@ public OneOf AsT13, 14 => AsT14, 15 => AsT15, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -615,7 +617,7 @@ public OneOf AsT13, 14 => AsT14, 15 => AsT15, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -643,7 +645,7 @@ public OneOf AsT13, 14 => AsT14, 15 => AsT15, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -671,7 +673,7 @@ public OneOf AsT13, 14 => AsT14, 15 => AsT15, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -699,7 +701,7 @@ public OneOf AsT13, 14 => AsT14, 15 => AsT15, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -727,7 +729,7 @@ public OneOf mapFunc(AsT13), 14 => AsT14, 15 => AsT15, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -755,7 +757,7 @@ public OneOf AsT13, 14 => mapFunc(AsT14), 15 => AsT15, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -783,11 +785,15 @@ public OneOf AsT13, 14 => AsT14, 15 => mapFunc(AsT15), - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } - public bool TryPickT0(out T0 value, out OneOf remainder) +#if NET + public bool TryPickT0([NotNullWhen(true)] out T0? value, out OneOf remainder) +#else + public bool TryPickT0(out T0? value, out OneOf remainder) +#endif { value = IsT0 ? AsT0 : default; remainder = _index switch @@ -808,12 +814,16 @@ public bool TryPickT0(out T0 value, out OneOf AsT13, 14 => AsT14, 15 => AsT15, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT0; } - public bool TryPickT1(out T1 value, out OneOf remainder) +#if NET + public bool TryPickT1([NotNullWhen(true)] out T1? value, out OneOf remainder) +#else + public bool TryPickT1(out T1? value, out OneOf remainder) +#endif { value = IsT1 ? AsT1 : default; remainder = _index switch @@ -834,12 +844,16 @@ public bool TryPickT1(out T1 value, out OneOf AsT13, 14 => AsT14, 15 => AsT15, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT1; } - public bool TryPickT2(out T2 value, out OneOf remainder) +#if NET + public bool TryPickT2([NotNullWhen(true)] out T2? value, out OneOf remainder) +#else + public bool TryPickT2(out T2? value, out OneOf remainder) +#endif { value = IsT2 ? AsT2 : default; remainder = _index switch @@ -860,12 +874,16 @@ public bool TryPickT2(out T2 value, out OneOf AsT13, 14 => AsT14, 15 => AsT15, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT2; } - public bool TryPickT3(out T3 value, out OneOf remainder) +#if NET + public bool TryPickT3([NotNullWhen(true)] out T3? value, out OneOf remainder) +#else + public bool TryPickT3(out T3? value, out OneOf remainder) +#endif { value = IsT3 ? AsT3 : default; remainder = _index switch @@ -886,12 +904,16 @@ public bool TryPickT3(out T3 value, out OneOf AsT13, 14 => AsT14, 15 => AsT15, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT3; } - public bool TryPickT4(out T4 value, out OneOf remainder) +#if NET + public bool TryPickT4([NotNullWhen(true)] out T4? value, out OneOf remainder) +#else + public bool TryPickT4(out T4? value, out OneOf remainder) +#endif { value = IsT4 ? AsT4 : default; remainder = _index switch @@ -912,12 +934,16 @@ public bool TryPickT4(out T4 value, out OneOf AsT13, 14 => AsT14, 15 => AsT15, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT4; } - public bool TryPickT5(out T5 value, out OneOf remainder) +#if NET + public bool TryPickT5([NotNullWhen(true)] out T5? value, out OneOf remainder) +#else + public bool TryPickT5(out T5? value, out OneOf remainder) +#endif { value = IsT5 ? AsT5 : default; remainder = _index switch @@ -938,12 +964,16 @@ public bool TryPickT5(out T5 value, out OneOf AsT13, 14 => AsT14, 15 => AsT15, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT5; } - public bool TryPickT6(out T6 value, out OneOf remainder) +#if NET + public bool TryPickT6([NotNullWhen(true)] out T6? value, out OneOf remainder) +#else + public bool TryPickT6(out T6? value, out OneOf remainder) +#endif { value = IsT6 ? AsT6 : default; remainder = _index switch @@ -964,12 +994,16 @@ public bool TryPickT6(out T6 value, out OneOf AsT13, 14 => AsT14, 15 => AsT15, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT6; } - public bool TryPickT7(out T7 value, out OneOf remainder) +#if NET + public bool TryPickT7([NotNullWhen(true)] out T7? value, out OneOf remainder) +#else + public bool TryPickT7(out T7? value, out OneOf remainder) +#endif { value = IsT7 ? AsT7 : default; remainder = _index switch @@ -990,12 +1024,16 @@ public bool TryPickT7(out T7 value, out OneOf AsT13, 14 => AsT14, 15 => AsT15, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT7; } - public bool TryPickT8(out T8 value, out OneOf remainder) +#if NET + public bool TryPickT8([NotNullWhen(true)] out T8? value, out OneOf remainder) +#else + public bool TryPickT8(out T8? value, out OneOf remainder) +#endif { value = IsT8 ? AsT8 : default; remainder = _index switch @@ -1016,12 +1054,16 @@ public bool TryPickT8(out T8 value, out OneOf AsT13, 14 => AsT14, 15 => AsT15, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT8; } - public bool TryPickT9(out T9 value, out OneOf remainder) +#if NET + public bool TryPickT9([NotNullWhen(true)] out T9? value, out OneOf remainder) +#else + public bool TryPickT9(out T9? value, out OneOf remainder) +#endif { value = IsT9 ? AsT9 : default; remainder = _index switch @@ -1042,12 +1084,16 @@ public bool TryPickT9(out T9 value, out OneOf AsT13, 14 => AsT14, 15 => AsT15, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT9; } - public bool TryPickT10(out T10 value, out OneOf remainder) +#if NET + public bool TryPickT10([NotNullWhen(true)] out T10? value, out OneOf remainder) +#else + public bool TryPickT10(out T10? value, out OneOf remainder) +#endif { value = IsT10 ? AsT10 : default; remainder = _index switch @@ -1068,12 +1114,16 @@ public bool TryPickT10(out T10 value, out OneOf AsT13, 14 => AsT14, 15 => AsT15, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT10; } - public bool TryPickT11(out T11 value, out OneOf remainder) +#if NET + public bool TryPickT11([NotNullWhen(true)] out T11? value, out OneOf remainder) +#else + public bool TryPickT11(out T11? value, out OneOf remainder) +#endif { value = IsT11 ? AsT11 : default; remainder = _index switch @@ -1094,12 +1144,16 @@ public bool TryPickT11(out T11 value, out OneOf AsT13, 14 => AsT14, 15 => AsT15, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT11; } - public bool TryPickT12(out T12 value, out OneOf remainder) +#if NET + public bool TryPickT12([NotNullWhen(true)] out T12? value, out OneOf remainder) +#else + public bool TryPickT12(out T12? value, out OneOf remainder) +#endif { value = IsT12 ? AsT12 : default; remainder = _index switch @@ -1120,12 +1174,16 @@ public bool TryPickT12(out T12 value, out OneOf AsT13, 14 => AsT14, 15 => AsT15, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT12; } - public bool TryPickT13(out T13 value, out OneOf remainder) +#if NET + public bool TryPickT13([NotNullWhen(true)] out T13? value, out OneOf remainder) +#else + public bool TryPickT13(out T13? value, out OneOf remainder) +#endif { value = IsT13 ? AsT13 : default; remainder = _index switch @@ -1146,12 +1204,16 @@ public bool TryPickT13(out T13 value, out OneOf default, 14 => AsT14, 15 => AsT15, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT13; } - public bool TryPickT14(out T14 value, out OneOf remainder) +#if NET + public bool TryPickT14([NotNullWhen(true)] out T14? value, out OneOf remainder) +#else + public bool TryPickT14(out T14? value, out OneOf remainder) +#endif { value = IsT14 ? AsT14 : default; remainder = _index switch @@ -1172,12 +1234,16 @@ public bool TryPickT14(out T14 value, out OneOf AsT13, 14 => default, 15 => AsT15, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT14; } - public bool TryPickT15(out T15 value, out OneOf remainder) +#if NET + public bool TryPickT15([NotNullWhen(true)] out T15? value, out OneOf remainder) +#else + public bool TryPickT15(out T15? value, out OneOf remainder) +#endif { value = IsT15 ? AsT15 : default; remainder = _index switch @@ -1198,7 +1264,7 @@ public bool TryPickT15(out T15 value, out OneOf AsT13, 14 => AsT14, 15 => default, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT15; } @@ -1226,7 +1292,7 @@ bool Equals(OneOf false }; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/OneOf.Extended/OneOfT16.generated.cs b/OneOf.Extended/OneOfT16.generated.cs index 51f8dc6..baf25a7 100644 --- a/OneOf.Extended/OneOfT16.generated.cs +++ b/OneOf.Extended/OneOfT16.generated.cs @@ -1,4 +1,6 @@ +#nullable enable using System; +using System.Diagnostics.CodeAnalysis; using static OneOf.Functions; namespace OneOf @@ -24,7 +26,7 @@ namespace OneOf readonly T16 _value16; readonly int _index; - OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default, T10 value10 = default, T11 value11 = default, T12 value12 = default, T13 value13 = default, T14 value14 = default, T15 value15 = default, T16 value16 = default) + OneOf(int index, T0 value0 = default!, T1 value1 = default!, T2 value2 = default!, T3 value3 = default!, T4 value4 = default!, T5 value5 = default!, T6 value6 = default!, T7 value7 = default!, T8 value8 = default!, T9 value9 = default!, T10 value10 = default!, T11 value11 = default!, T12 value12 = default!, T13 value13 = default!, T14 value14 = default!, T15 value15 = default!, T16 value16 = default!) { _index = index; _value0 = value0; @@ -46,7 +48,7 @@ namespace OneOf _value16 = value16; } - public object Value => + public object? Value => _index switch { 0 => _value0, @@ -66,7 +68,7 @@ namespace OneOf 14 => _value14, 15 => _value15, 16 => _value16, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; public int Index => _index; @@ -263,7 +265,7 @@ public void Switch(Action f0, Action f1, Action f2, Action f3, A f16(_value16); return; } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } public TResult Match(Func f0, Func f1, Func f2, Func f3, Func f4, Func f5, Func f6, Func f7, Func f8, Func f9, Func f10, Func f11, Func f12, Func f13, Func f14, Func f15, Func f16) @@ -336,7 +338,7 @@ public TResult Match(Func f0, Func f1, Func FromT0(T0 input) => input; @@ -383,7 +385,7 @@ public OneOf AsT14, 15 => AsT15, 16 => AsT16, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -412,7 +414,7 @@ public OneOf AsT14, 15 => AsT15, 16 => AsT16, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -441,7 +443,7 @@ public OneOf AsT14, 15 => AsT15, 16 => AsT16, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -470,7 +472,7 @@ public OneOf AsT14, 15 => AsT15, 16 => AsT16, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -499,7 +501,7 @@ public OneOf AsT14, 15 => AsT15, 16 => AsT16, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -528,7 +530,7 @@ public OneOf AsT14, 15 => AsT15, 16 => AsT16, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -557,7 +559,7 @@ public OneOf AsT14, 15 => AsT15, 16 => AsT16, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -586,7 +588,7 @@ public OneOf AsT14, 15 => AsT15, 16 => AsT16, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -615,7 +617,7 @@ public OneOf AsT14, 15 => AsT15, 16 => AsT16, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -644,7 +646,7 @@ public OneOf AsT14, 15 => AsT15, 16 => AsT16, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -673,7 +675,7 @@ public OneOf AsT14, 15 => AsT15, 16 => AsT16, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -702,7 +704,7 @@ public OneOf AsT14, 15 => AsT15, 16 => AsT16, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -731,7 +733,7 @@ public OneOf AsT14, 15 => AsT15, 16 => AsT16, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -760,7 +762,7 @@ public OneOf AsT14, 15 => AsT15, 16 => AsT16, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -789,7 +791,7 @@ public OneOf mapFunc(AsT14), 15 => AsT15, 16 => AsT16, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -818,7 +820,7 @@ public OneOf AsT14, 15 => mapFunc(AsT15), 16 => AsT16, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -847,11 +849,15 @@ public OneOf AsT14, 15 => AsT15, 16 => mapFunc(AsT16), - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } - public bool TryPickT0(out T0 value, out OneOf remainder) +#if NET + public bool TryPickT0([NotNullWhen(true)] out T0? value, out OneOf remainder) +#else + public bool TryPickT0(out T0? value, out OneOf remainder) +#endif { value = IsT0 ? AsT0 : default; remainder = _index switch @@ -873,12 +879,16 @@ public bool TryPickT0(out T0 value, out OneOf AsT14, 15 => AsT15, 16 => AsT16, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT0; } - public bool TryPickT1(out T1 value, out OneOf remainder) +#if NET + public bool TryPickT1([NotNullWhen(true)] out T1? value, out OneOf remainder) +#else + public bool TryPickT1(out T1? value, out OneOf remainder) +#endif { value = IsT1 ? AsT1 : default; remainder = _index switch @@ -900,12 +910,16 @@ public bool TryPickT1(out T1 value, out OneOf AsT14, 15 => AsT15, 16 => AsT16, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT1; } - public bool TryPickT2(out T2 value, out OneOf remainder) +#if NET + public bool TryPickT2([NotNullWhen(true)] out T2? value, out OneOf remainder) +#else + public bool TryPickT2(out T2? value, out OneOf remainder) +#endif { value = IsT2 ? AsT2 : default; remainder = _index switch @@ -927,12 +941,16 @@ public bool TryPickT2(out T2 value, out OneOf AsT14, 15 => AsT15, 16 => AsT16, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT2; } - public bool TryPickT3(out T3 value, out OneOf remainder) +#if NET + public bool TryPickT3([NotNullWhen(true)] out T3? value, out OneOf remainder) +#else + public bool TryPickT3(out T3? value, out OneOf remainder) +#endif { value = IsT3 ? AsT3 : default; remainder = _index switch @@ -954,12 +972,16 @@ public bool TryPickT3(out T3 value, out OneOf AsT14, 15 => AsT15, 16 => AsT16, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT3; } - public bool TryPickT4(out T4 value, out OneOf remainder) +#if NET + public bool TryPickT4([NotNullWhen(true)] out T4? value, out OneOf remainder) +#else + public bool TryPickT4(out T4? value, out OneOf remainder) +#endif { value = IsT4 ? AsT4 : default; remainder = _index switch @@ -981,12 +1003,16 @@ public bool TryPickT4(out T4 value, out OneOf AsT14, 15 => AsT15, 16 => AsT16, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT4; } - public bool TryPickT5(out T5 value, out OneOf remainder) +#if NET + public bool TryPickT5([NotNullWhen(true)] out T5? value, out OneOf remainder) +#else + public bool TryPickT5(out T5? value, out OneOf remainder) +#endif { value = IsT5 ? AsT5 : default; remainder = _index switch @@ -1008,12 +1034,16 @@ public bool TryPickT5(out T5 value, out OneOf AsT14, 15 => AsT15, 16 => AsT16, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT5; } - public bool TryPickT6(out T6 value, out OneOf remainder) +#if NET + public bool TryPickT6([NotNullWhen(true)] out T6? value, out OneOf remainder) +#else + public bool TryPickT6(out T6? value, out OneOf remainder) +#endif { value = IsT6 ? AsT6 : default; remainder = _index switch @@ -1035,12 +1065,16 @@ public bool TryPickT6(out T6 value, out OneOf AsT14, 15 => AsT15, 16 => AsT16, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT6; } - public bool TryPickT7(out T7 value, out OneOf remainder) +#if NET + public bool TryPickT7([NotNullWhen(true)] out T7? value, out OneOf remainder) +#else + public bool TryPickT7(out T7? value, out OneOf remainder) +#endif { value = IsT7 ? AsT7 : default; remainder = _index switch @@ -1062,12 +1096,16 @@ public bool TryPickT7(out T7 value, out OneOf AsT14, 15 => AsT15, 16 => AsT16, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT7; } - public bool TryPickT8(out T8 value, out OneOf remainder) +#if NET + public bool TryPickT8([NotNullWhen(true)] out T8? value, out OneOf remainder) +#else + public bool TryPickT8(out T8? value, out OneOf remainder) +#endif { value = IsT8 ? AsT8 : default; remainder = _index switch @@ -1089,12 +1127,16 @@ public bool TryPickT8(out T8 value, out OneOf AsT14, 15 => AsT15, 16 => AsT16, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT8; } - public bool TryPickT9(out T9 value, out OneOf remainder) +#if NET + public bool TryPickT9([NotNullWhen(true)] out T9? value, out OneOf remainder) +#else + public bool TryPickT9(out T9? value, out OneOf remainder) +#endif { value = IsT9 ? AsT9 : default; remainder = _index switch @@ -1116,12 +1158,16 @@ public bool TryPickT9(out T9 value, out OneOf AsT14, 15 => AsT15, 16 => AsT16, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT9; } - public bool TryPickT10(out T10 value, out OneOf remainder) +#if NET + public bool TryPickT10([NotNullWhen(true)] out T10? value, out OneOf remainder) +#else + public bool TryPickT10(out T10? value, out OneOf remainder) +#endif { value = IsT10 ? AsT10 : default; remainder = _index switch @@ -1143,12 +1189,16 @@ public bool TryPickT10(out T10 value, out OneOf AsT14, 15 => AsT15, 16 => AsT16, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT10; } - public bool TryPickT11(out T11 value, out OneOf remainder) +#if NET + public bool TryPickT11([NotNullWhen(true)] out T11? value, out OneOf remainder) +#else + public bool TryPickT11(out T11? value, out OneOf remainder) +#endif { value = IsT11 ? AsT11 : default; remainder = _index switch @@ -1170,12 +1220,16 @@ public bool TryPickT11(out T11 value, out OneOf AsT14, 15 => AsT15, 16 => AsT16, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT11; } - public bool TryPickT12(out T12 value, out OneOf remainder) +#if NET + public bool TryPickT12([NotNullWhen(true)] out T12? value, out OneOf remainder) +#else + public bool TryPickT12(out T12? value, out OneOf remainder) +#endif { value = IsT12 ? AsT12 : default; remainder = _index switch @@ -1197,12 +1251,16 @@ public bool TryPickT12(out T12 value, out OneOf AsT14, 15 => AsT15, 16 => AsT16, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT12; } - public bool TryPickT13(out T13 value, out OneOf remainder) +#if NET + public bool TryPickT13([NotNullWhen(true)] out T13? value, out OneOf remainder) +#else + public bool TryPickT13(out T13? value, out OneOf remainder) +#endif { value = IsT13 ? AsT13 : default; remainder = _index switch @@ -1224,12 +1282,16 @@ public bool TryPickT13(out T13 value, out OneOf AsT14, 15 => AsT15, 16 => AsT16, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT13; } - public bool TryPickT14(out T14 value, out OneOf remainder) +#if NET + public bool TryPickT14([NotNullWhen(true)] out T14? value, out OneOf remainder) +#else + public bool TryPickT14(out T14? value, out OneOf remainder) +#endif { value = IsT14 ? AsT14 : default; remainder = _index switch @@ -1251,12 +1313,16 @@ public bool TryPickT14(out T14 value, out OneOf default, 15 => AsT15, 16 => AsT16, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT14; } - public bool TryPickT15(out T15 value, out OneOf remainder) +#if NET + public bool TryPickT15([NotNullWhen(true)] out T15? value, out OneOf remainder) +#else + public bool TryPickT15(out T15? value, out OneOf remainder) +#endif { value = IsT15 ? AsT15 : default; remainder = _index switch @@ -1278,12 +1344,16 @@ public bool TryPickT15(out T15 value, out OneOf AsT14, 15 => default, 16 => AsT16, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT15; } - public bool TryPickT16(out T16 value, out OneOf remainder) +#if NET + public bool TryPickT16([NotNullWhen(true)] out T16? value, out OneOf remainder) +#else + public bool TryPickT16(out T16? value, out OneOf remainder) +#endif { value = IsT16 ? AsT16 : default; remainder = _index switch @@ -1305,7 +1375,7 @@ public bool TryPickT16(out T16 value, out OneOf AsT14, 15 => AsT15, 16 => default, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT16; } @@ -1334,7 +1404,7 @@ bool Equals(OneOf false }; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/OneOf.Extended/OneOfT17.generated.cs b/OneOf.Extended/OneOfT17.generated.cs index eefe75b..662ae09 100644 --- a/OneOf.Extended/OneOfT17.generated.cs +++ b/OneOf.Extended/OneOfT17.generated.cs @@ -1,4 +1,6 @@ +#nullable enable using System; +using System.Diagnostics.CodeAnalysis; using static OneOf.Functions; namespace OneOf @@ -25,7 +27,7 @@ namespace OneOf readonly T17 _value17; readonly int _index; - OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default, T10 value10 = default, T11 value11 = default, T12 value12 = default, T13 value13 = default, T14 value14 = default, T15 value15 = default, T16 value16 = default, T17 value17 = default) + OneOf(int index, T0 value0 = default!, T1 value1 = default!, T2 value2 = default!, T3 value3 = default!, T4 value4 = default!, T5 value5 = default!, T6 value6 = default!, T7 value7 = default!, T8 value8 = default!, T9 value9 = default!, T10 value10 = default!, T11 value11 = default!, T12 value12 = default!, T13 value13 = default!, T14 value14 = default!, T15 value15 = default!, T16 value16 = default!, T17 value17 = default!) { _index = index; _value0 = value0; @@ -48,7 +50,7 @@ namespace OneOf _value17 = value17; } - public object Value => + public object? Value => _index switch { 0 => _value0, @@ -69,7 +71,7 @@ namespace OneOf 15 => _value15, 16 => _value16, 17 => _value17, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; public int Index => _index; @@ -277,7 +279,7 @@ public void Switch(Action f0, Action f1, Action f2, Action f3, A f17(_value17); return; } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } public TResult Match(Func f0, Func f1, Func f2, Func f3, Func f4, Func f5, Func f6, Func f7, Func f8, Func f9, Func f10, Func f11, Func f12, Func f13, Func f14, Func f15, Func f16, Func f17) @@ -354,7 +356,7 @@ public TResult Match(Func f0, Func f1, Func FromT0(T0 input) => input; @@ -403,7 +405,7 @@ public OneOf AsT15, 16 => AsT16, 17 => AsT17, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -433,7 +435,7 @@ public OneOf AsT15, 16 => AsT16, 17 => AsT17, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -463,7 +465,7 @@ public OneOf AsT15, 16 => AsT16, 17 => AsT17, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -493,7 +495,7 @@ public OneOf AsT15, 16 => AsT16, 17 => AsT17, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -523,7 +525,7 @@ public OneOf AsT15, 16 => AsT16, 17 => AsT17, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -553,7 +555,7 @@ public OneOf AsT15, 16 => AsT16, 17 => AsT17, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -583,7 +585,7 @@ public OneOf AsT15, 16 => AsT16, 17 => AsT17, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -613,7 +615,7 @@ public OneOf AsT15, 16 => AsT16, 17 => AsT17, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -643,7 +645,7 @@ public OneOf AsT15, 16 => AsT16, 17 => AsT17, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -673,7 +675,7 @@ public OneOf AsT15, 16 => AsT16, 17 => AsT17, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -703,7 +705,7 @@ public OneOf AsT15, 16 => AsT16, 17 => AsT17, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -733,7 +735,7 @@ public OneOf AsT15, 16 => AsT16, 17 => AsT17, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -763,7 +765,7 @@ public OneOf AsT15, 16 => AsT16, 17 => AsT17, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -793,7 +795,7 @@ public OneOf AsT15, 16 => AsT16, 17 => AsT17, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -823,7 +825,7 @@ public OneOf AsT15, 16 => AsT16, 17 => AsT17, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -853,7 +855,7 @@ public OneOf mapFunc(AsT15), 16 => AsT16, 17 => AsT17, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -883,7 +885,7 @@ public OneOf AsT15, 16 => mapFunc(AsT16), 17 => AsT17, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -913,11 +915,15 @@ public OneOf AsT15, 16 => AsT16, 17 => mapFunc(AsT17), - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } - public bool TryPickT0(out T0 value, out OneOf remainder) +#if NET + public bool TryPickT0([NotNullWhen(true)] out T0? value, out OneOf remainder) +#else + public bool TryPickT0(out T0? value, out OneOf remainder) +#endif { value = IsT0 ? AsT0 : default; remainder = _index switch @@ -940,12 +946,16 @@ public bool TryPickT0(out T0 value, out OneOf AsT15, 16 => AsT16, 17 => AsT17, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT0; } - public bool TryPickT1(out T1 value, out OneOf remainder) +#if NET + public bool TryPickT1([NotNullWhen(true)] out T1? value, out OneOf remainder) +#else + public bool TryPickT1(out T1? value, out OneOf remainder) +#endif { value = IsT1 ? AsT1 : default; remainder = _index switch @@ -968,12 +978,16 @@ public bool TryPickT1(out T1 value, out OneOf AsT15, 16 => AsT16, 17 => AsT17, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT1; } - public bool TryPickT2(out T2 value, out OneOf remainder) +#if NET + public bool TryPickT2([NotNullWhen(true)] out T2? value, out OneOf remainder) +#else + public bool TryPickT2(out T2? value, out OneOf remainder) +#endif { value = IsT2 ? AsT2 : default; remainder = _index switch @@ -996,12 +1010,16 @@ public bool TryPickT2(out T2 value, out OneOf AsT15, 16 => AsT16, 17 => AsT17, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT2; } - public bool TryPickT3(out T3 value, out OneOf remainder) +#if NET + public bool TryPickT3([NotNullWhen(true)] out T3? value, out OneOf remainder) +#else + public bool TryPickT3(out T3? value, out OneOf remainder) +#endif { value = IsT3 ? AsT3 : default; remainder = _index switch @@ -1024,12 +1042,16 @@ public bool TryPickT3(out T3 value, out OneOf AsT15, 16 => AsT16, 17 => AsT17, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT3; } - public bool TryPickT4(out T4 value, out OneOf remainder) +#if NET + public bool TryPickT4([NotNullWhen(true)] out T4? value, out OneOf remainder) +#else + public bool TryPickT4(out T4? value, out OneOf remainder) +#endif { value = IsT4 ? AsT4 : default; remainder = _index switch @@ -1052,12 +1074,16 @@ public bool TryPickT4(out T4 value, out OneOf AsT15, 16 => AsT16, 17 => AsT17, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT4; } - public bool TryPickT5(out T5 value, out OneOf remainder) +#if NET + public bool TryPickT5([NotNullWhen(true)] out T5? value, out OneOf remainder) +#else + public bool TryPickT5(out T5? value, out OneOf remainder) +#endif { value = IsT5 ? AsT5 : default; remainder = _index switch @@ -1080,12 +1106,16 @@ public bool TryPickT5(out T5 value, out OneOf AsT15, 16 => AsT16, 17 => AsT17, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT5; } - public bool TryPickT6(out T6 value, out OneOf remainder) +#if NET + public bool TryPickT6([NotNullWhen(true)] out T6? value, out OneOf remainder) +#else + public bool TryPickT6(out T6? value, out OneOf remainder) +#endif { value = IsT6 ? AsT6 : default; remainder = _index switch @@ -1108,12 +1138,16 @@ public bool TryPickT6(out T6 value, out OneOf AsT15, 16 => AsT16, 17 => AsT17, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT6; } - public bool TryPickT7(out T7 value, out OneOf remainder) +#if NET + public bool TryPickT7([NotNullWhen(true)] out T7? value, out OneOf remainder) +#else + public bool TryPickT7(out T7? value, out OneOf remainder) +#endif { value = IsT7 ? AsT7 : default; remainder = _index switch @@ -1136,12 +1170,16 @@ public bool TryPickT7(out T7 value, out OneOf AsT15, 16 => AsT16, 17 => AsT17, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT7; } - public bool TryPickT8(out T8 value, out OneOf remainder) +#if NET + public bool TryPickT8([NotNullWhen(true)] out T8? value, out OneOf remainder) +#else + public bool TryPickT8(out T8? value, out OneOf remainder) +#endif { value = IsT8 ? AsT8 : default; remainder = _index switch @@ -1164,12 +1202,16 @@ public bool TryPickT8(out T8 value, out OneOf AsT15, 16 => AsT16, 17 => AsT17, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT8; } - public bool TryPickT9(out T9 value, out OneOf remainder) +#if NET + public bool TryPickT9([NotNullWhen(true)] out T9? value, out OneOf remainder) +#else + public bool TryPickT9(out T9? value, out OneOf remainder) +#endif { value = IsT9 ? AsT9 : default; remainder = _index switch @@ -1192,12 +1234,16 @@ public bool TryPickT9(out T9 value, out OneOf AsT15, 16 => AsT16, 17 => AsT17, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT9; } - public bool TryPickT10(out T10 value, out OneOf remainder) +#if NET + public bool TryPickT10([NotNullWhen(true)] out T10? value, out OneOf remainder) +#else + public bool TryPickT10(out T10? value, out OneOf remainder) +#endif { value = IsT10 ? AsT10 : default; remainder = _index switch @@ -1220,12 +1266,16 @@ public bool TryPickT10(out T10 value, out OneOf AsT15, 16 => AsT16, 17 => AsT17, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT10; } - public bool TryPickT11(out T11 value, out OneOf remainder) +#if NET + public bool TryPickT11([NotNullWhen(true)] out T11? value, out OneOf remainder) +#else + public bool TryPickT11(out T11? value, out OneOf remainder) +#endif { value = IsT11 ? AsT11 : default; remainder = _index switch @@ -1248,12 +1298,16 @@ public bool TryPickT11(out T11 value, out OneOf AsT15, 16 => AsT16, 17 => AsT17, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT11; } - public bool TryPickT12(out T12 value, out OneOf remainder) +#if NET + public bool TryPickT12([NotNullWhen(true)] out T12? value, out OneOf remainder) +#else + public bool TryPickT12(out T12? value, out OneOf remainder) +#endif { value = IsT12 ? AsT12 : default; remainder = _index switch @@ -1276,12 +1330,16 @@ public bool TryPickT12(out T12 value, out OneOf AsT15, 16 => AsT16, 17 => AsT17, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT12; } - public bool TryPickT13(out T13 value, out OneOf remainder) +#if NET + public bool TryPickT13([NotNullWhen(true)] out T13? value, out OneOf remainder) +#else + public bool TryPickT13(out T13? value, out OneOf remainder) +#endif { value = IsT13 ? AsT13 : default; remainder = _index switch @@ -1304,12 +1362,16 @@ public bool TryPickT13(out T13 value, out OneOf AsT15, 16 => AsT16, 17 => AsT17, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT13; } - public bool TryPickT14(out T14 value, out OneOf remainder) +#if NET + public bool TryPickT14([NotNullWhen(true)] out T14? value, out OneOf remainder) +#else + public bool TryPickT14(out T14? value, out OneOf remainder) +#endif { value = IsT14 ? AsT14 : default; remainder = _index switch @@ -1332,12 +1394,16 @@ public bool TryPickT14(out T14 value, out OneOf AsT15, 16 => AsT16, 17 => AsT17, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT14; } - public bool TryPickT15(out T15 value, out OneOf remainder) +#if NET + public bool TryPickT15([NotNullWhen(true)] out T15? value, out OneOf remainder) +#else + public bool TryPickT15(out T15? value, out OneOf remainder) +#endif { value = IsT15 ? AsT15 : default; remainder = _index switch @@ -1360,12 +1426,16 @@ public bool TryPickT15(out T15 value, out OneOf default, 16 => AsT16, 17 => AsT17, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT15; } - public bool TryPickT16(out T16 value, out OneOf remainder) +#if NET + public bool TryPickT16([NotNullWhen(true)] out T16? value, out OneOf remainder) +#else + public bool TryPickT16(out T16? value, out OneOf remainder) +#endif { value = IsT16 ? AsT16 : default; remainder = _index switch @@ -1388,12 +1458,16 @@ public bool TryPickT16(out T16 value, out OneOf AsT15, 16 => default, 17 => AsT17, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT16; } - public bool TryPickT17(out T17 value, out OneOf remainder) +#if NET + public bool TryPickT17([NotNullWhen(true)] out T17? value, out OneOf remainder) +#else + public bool TryPickT17(out T17? value, out OneOf remainder) +#endif { value = IsT17 ? AsT17 : default; remainder = _index switch @@ -1416,7 +1490,7 @@ public bool TryPickT17(out T17 value, out OneOf AsT15, 16 => AsT16, 17 => default, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT17; } @@ -1446,7 +1520,7 @@ bool Equals(OneOf false }; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/OneOf.Extended/OneOfT18.generated.cs b/OneOf.Extended/OneOfT18.generated.cs index ba17036..77b683b 100644 --- a/OneOf.Extended/OneOfT18.generated.cs +++ b/OneOf.Extended/OneOfT18.generated.cs @@ -1,4 +1,6 @@ +#nullable enable using System; +using System.Diagnostics.CodeAnalysis; using static OneOf.Functions; namespace OneOf @@ -26,7 +28,7 @@ namespace OneOf readonly T18 _value18; readonly int _index; - OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default, T10 value10 = default, T11 value11 = default, T12 value12 = default, T13 value13 = default, T14 value14 = default, T15 value15 = default, T16 value16 = default, T17 value17 = default, T18 value18 = default) + OneOf(int index, T0 value0 = default!, T1 value1 = default!, T2 value2 = default!, T3 value3 = default!, T4 value4 = default!, T5 value5 = default!, T6 value6 = default!, T7 value7 = default!, T8 value8 = default!, T9 value9 = default!, T10 value10 = default!, T11 value11 = default!, T12 value12 = default!, T13 value13 = default!, T14 value14 = default!, T15 value15 = default!, T16 value16 = default!, T17 value17 = default!, T18 value18 = default!) { _index = index; _value0 = value0; @@ -50,7 +52,7 @@ namespace OneOf _value18 = value18; } - public object Value => + public object? Value => _index switch { 0 => _value0, @@ -72,7 +74,7 @@ namespace OneOf 16 => _value16, 17 => _value17, 18 => _value18, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; public int Index => _index; @@ -291,7 +293,7 @@ public void Switch(Action f0, Action f1, Action f2, Action f3, A f18(_value18); return; } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } public TResult Match(Func f0, Func f1, Func f2, Func f3, Func f4, Func f5, Func f6, Func f7, Func f8, Func f9, Func f10, Func f11, Func f12, Func f13, Func f14, Func f15, Func f16, Func f17, Func f18) @@ -372,7 +374,7 @@ public TResult Match(Func f0, Func f1, Func FromT0(T0 input) => input; @@ -423,7 +425,7 @@ public OneOf AsT16, 17 => AsT17, 18 => AsT18, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -454,7 +456,7 @@ public OneOf AsT16, 17 => AsT17, 18 => AsT18, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -485,7 +487,7 @@ public OneOf AsT16, 17 => AsT17, 18 => AsT18, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -516,7 +518,7 @@ public OneOf AsT16, 17 => AsT17, 18 => AsT18, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -547,7 +549,7 @@ public OneOf AsT16, 17 => AsT17, 18 => AsT18, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -578,7 +580,7 @@ public OneOf AsT16, 17 => AsT17, 18 => AsT18, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -609,7 +611,7 @@ public OneOf AsT16, 17 => AsT17, 18 => AsT18, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -640,7 +642,7 @@ public OneOf AsT16, 17 => AsT17, 18 => AsT18, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -671,7 +673,7 @@ public OneOf AsT16, 17 => AsT17, 18 => AsT18, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -702,7 +704,7 @@ public OneOf AsT16, 17 => AsT17, 18 => AsT18, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -733,7 +735,7 @@ public OneOf AsT16, 17 => AsT17, 18 => AsT18, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -764,7 +766,7 @@ public OneOf AsT16, 17 => AsT17, 18 => AsT18, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -795,7 +797,7 @@ public OneOf AsT16, 17 => AsT17, 18 => AsT18, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -826,7 +828,7 @@ public OneOf AsT16, 17 => AsT17, 18 => AsT18, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -857,7 +859,7 @@ public OneOf AsT16, 17 => AsT17, 18 => AsT18, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -888,7 +890,7 @@ public OneOf AsT16, 17 => AsT17, 18 => AsT18, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -919,7 +921,7 @@ public OneOf mapFunc(AsT16), 17 => AsT17, 18 => AsT18, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -950,7 +952,7 @@ public OneOf AsT16, 17 => mapFunc(AsT17), 18 => AsT18, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -981,11 +983,15 @@ public OneOf AsT16, 17 => AsT17, 18 => mapFunc(AsT18), - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } - public bool TryPickT0(out T0 value, out OneOf remainder) +#if NET + public bool TryPickT0([NotNullWhen(true)] out T0? value, out OneOf remainder) +#else + public bool TryPickT0(out T0? value, out OneOf remainder) +#endif { value = IsT0 ? AsT0 : default; remainder = _index switch @@ -1009,12 +1015,16 @@ public bool TryPickT0(out T0 value, out OneOf AsT16, 17 => AsT17, 18 => AsT18, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT0; } - public bool TryPickT1(out T1 value, out OneOf remainder) +#if NET + public bool TryPickT1([NotNullWhen(true)] out T1? value, out OneOf remainder) +#else + public bool TryPickT1(out T1? value, out OneOf remainder) +#endif { value = IsT1 ? AsT1 : default; remainder = _index switch @@ -1038,12 +1048,16 @@ public bool TryPickT1(out T1 value, out OneOf AsT16, 17 => AsT17, 18 => AsT18, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT1; } - public bool TryPickT2(out T2 value, out OneOf remainder) +#if NET + public bool TryPickT2([NotNullWhen(true)] out T2? value, out OneOf remainder) +#else + public bool TryPickT2(out T2? value, out OneOf remainder) +#endif { value = IsT2 ? AsT2 : default; remainder = _index switch @@ -1067,12 +1081,16 @@ public bool TryPickT2(out T2 value, out OneOf AsT16, 17 => AsT17, 18 => AsT18, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT2; } - public bool TryPickT3(out T3 value, out OneOf remainder) +#if NET + public bool TryPickT3([NotNullWhen(true)] out T3? value, out OneOf remainder) +#else + public bool TryPickT3(out T3? value, out OneOf remainder) +#endif { value = IsT3 ? AsT3 : default; remainder = _index switch @@ -1096,12 +1114,16 @@ public bool TryPickT3(out T3 value, out OneOf AsT16, 17 => AsT17, 18 => AsT18, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT3; } - public bool TryPickT4(out T4 value, out OneOf remainder) +#if NET + public bool TryPickT4([NotNullWhen(true)] out T4? value, out OneOf remainder) +#else + public bool TryPickT4(out T4? value, out OneOf remainder) +#endif { value = IsT4 ? AsT4 : default; remainder = _index switch @@ -1125,12 +1147,16 @@ public bool TryPickT4(out T4 value, out OneOf AsT16, 17 => AsT17, 18 => AsT18, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT4; } - public bool TryPickT5(out T5 value, out OneOf remainder) +#if NET + public bool TryPickT5([NotNullWhen(true)] out T5? value, out OneOf remainder) +#else + public bool TryPickT5(out T5? value, out OneOf remainder) +#endif { value = IsT5 ? AsT5 : default; remainder = _index switch @@ -1154,12 +1180,16 @@ public bool TryPickT5(out T5 value, out OneOf AsT16, 17 => AsT17, 18 => AsT18, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT5; } - public bool TryPickT6(out T6 value, out OneOf remainder) +#if NET + public bool TryPickT6([NotNullWhen(true)] out T6? value, out OneOf remainder) +#else + public bool TryPickT6(out T6? value, out OneOf remainder) +#endif { value = IsT6 ? AsT6 : default; remainder = _index switch @@ -1183,12 +1213,16 @@ public bool TryPickT6(out T6 value, out OneOf AsT16, 17 => AsT17, 18 => AsT18, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT6; } - public bool TryPickT7(out T7 value, out OneOf remainder) +#if NET + public bool TryPickT7([NotNullWhen(true)] out T7? value, out OneOf remainder) +#else + public bool TryPickT7(out T7? value, out OneOf remainder) +#endif { value = IsT7 ? AsT7 : default; remainder = _index switch @@ -1212,12 +1246,16 @@ public bool TryPickT7(out T7 value, out OneOf AsT16, 17 => AsT17, 18 => AsT18, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT7; } - public bool TryPickT8(out T8 value, out OneOf remainder) +#if NET + public bool TryPickT8([NotNullWhen(true)] out T8? value, out OneOf remainder) +#else + public bool TryPickT8(out T8? value, out OneOf remainder) +#endif { value = IsT8 ? AsT8 : default; remainder = _index switch @@ -1241,12 +1279,16 @@ public bool TryPickT8(out T8 value, out OneOf AsT16, 17 => AsT17, 18 => AsT18, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT8; } - public bool TryPickT9(out T9 value, out OneOf remainder) +#if NET + public bool TryPickT9([NotNullWhen(true)] out T9? value, out OneOf remainder) +#else + public bool TryPickT9(out T9? value, out OneOf remainder) +#endif { value = IsT9 ? AsT9 : default; remainder = _index switch @@ -1270,12 +1312,16 @@ public bool TryPickT9(out T9 value, out OneOf AsT16, 17 => AsT17, 18 => AsT18, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT9; } - public bool TryPickT10(out T10 value, out OneOf remainder) +#if NET + public bool TryPickT10([NotNullWhen(true)] out T10? value, out OneOf remainder) +#else + public bool TryPickT10(out T10? value, out OneOf remainder) +#endif { value = IsT10 ? AsT10 : default; remainder = _index switch @@ -1299,12 +1345,16 @@ public bool TryPickT10(out T10 value, out OneOf AsT16, 17 => AsT17, 18 => AsT18, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT10; } - public bool TryPickT11(out T11 value, out OneOf remainder) +#if NET + public bool TryPickT11([NotNullWhen(true)] out T11? value, out OneOf remainder) +#else + public bool TryPickT11(out T11? value, out OneOf remainder) +#endif { value = IsT11 ? AsT11 : default; remainder = _index switch @@ -1328,12 +1378,16 @@ public bool TryPickT11(out T11 value, out OneOf AsT16, 17 => AsT17, 18 => AsT18, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT11; } - public bool TryPickT12(out T12 value, out OneOf remainder) +#if NET + public bool TryPickT12([NotNullWhen(true)] out T12? value, out OneOf remainder) +#else + public bool TryPickT12(out T12? value, out OneOf remainder) +#endif { value = IsT12 ? AsT12 : default; remainder = _index switch @@ -1357,12 +1411,16 @@ public bool TryPickT12(out T12 value, out OneOf AsT16, 17 => AsT17, 18 => AsT18, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT12; } - public bool TryPickT13(out T13 value, out OneOf remainder) +#if NET + public bool TryPickT13([NotNullWhen(true)] out T13? value, out OneOf remainder) +#else + public bool TryPickT13(out T13? value, out OneOf remainder) +#endif { value = IsT13 ? AsT13 : default; remainder = _index switch @@ -1386,12 +1444,16 @@ public bool TryPickT13(out T13 value, out OneOf AsT16, 17 => AsT17, 18 => AsT18, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT13; } - public bool TryPickT14(out T14 value, out OneOf remainder) +#if NET + public bool TryPickT14([NotNullWhen(true)] out T14? value, out OneOf remainder) +#else + public bool TryPickT14(out T14? value, out OneOf remainder) +#endif { value = IsT14 ? AsT14 : default; remainder = _index switch @@ -1415,12 +1477,16 @@ public bool TryPickT14(out T14 value, out OneOf AsT16, 17 => AsT17, 18 => AsT18, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT14; } - public bool TryPickT15(out T15 value, out OneOf remainder) +#if NET + public bool TryPickT15([NotNullWhen(true)] out T15? value, out OneOf remainder) +#else + public bool TryPickT15(out T15? value, out OneOf remainder) +#endif { value = IsT15 ? AsT15 : default; remainder = _index switch @@ -1444,12 +1510,16 @@ public bool TryPickT15(out T15 value, out OneOf AsT16, 17 => AsT17, 18 => AsT18, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT15; } - public bool TryPickT16(out T16 value, out OneOf remainder) +#if NET + public bool TryPickT16([NotNullWhen(true)] out T16? value, out OneOf remainder) +#else + public bool TryPickT16(out T16? value, out OneOf remainder) +#endif { value = IsT16 ? AsT16 : default; remainder = _index switch @@ -1473,12 +1543,16 @@ public bool TryPickT16(out T16 value, out OneOf default, 17 => AsT17, 18 => AsT18, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT16; } - public bool TryPickT17(out T17 value, out OneOf remainder) +#if NET + public bool TryPickT17([NotNullWhen(true)] out T17? value, out OneOf remainder) +#else + public bool TryPickT17(out T17? value, out OneOf remainder) +#endif { value = IsT17 ? AsT17 : default; remainder = _index switch @@ -1502,12 +1576,16 @@ public bool TryPickT17(out T17 value, out OneOf AsT16, 17 => default, 18 => AsT18, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT17; } - public bool TryPickT18(out T18 value, out OneOf remainder) +#if NET + public bool TryPickT18([NotNullWhen(true)] out T18? value, out OneOf remainder) +#else + public bool TryPickT18(out T18? value, out OneOf remainder) +#endif { value = IsT18 ? AsT18 : default; remainder = _index switch @@ -1531,7 +1609,7 @@ public bool TryPickT18(out T18 value, out OneOf AsT16, 17 => AsT17, 18 => default, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT18; } @@ -1562,7 +1640,7 @@ bool Equals(OneOf false }; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/OneOf.Extended/OneOfT19.generated.cs b/OneOf.Extended/OneOfT19.generated.cs index 3541ffe..ebb3b5a 100644 --- a/OneOf.Extended/OneOfT19.generated.cs +++ b/OneOf.Extended/OneOfT19.generated.cs @@ -1,4 +1,6 @@ +#nullable enable using System; +using System.Diagnostics.CodeAnalysis; using static OneOf.Functions; namespace OneOf @@ -27,7 +29,7 @@ namespace OneOf readonly T19 _value19; readonly int _index; - OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default, T10 value10 = default, T11 value11 = default, T12 value12 = default, T13 value13 = default, T14 value14 = default, T15 value15 = default, T16 value16 = default, T17 value17 = default, T18 value18 = default, T19 value19 = default) + OneOf(int index, T0 value0 = default!, T1 value1 = default!, T2 value2 = default!, T3 value3 = default!, T4 value4 = default!, T5 value5 = default!, T6 value6 = default!, T7 value7 = default!, T8 value8 = default!, T9 value9 = default!, T10 value10 = default!, T11 value11 = default!, T12 value12 = default!, T13 value13 = default!, T14 value14 = default!, T15 value15 = default!, T16 value16 = default!, T17 value17 = default!, T18 value18 = default!, T19 value19 = default!) { _index = index; _value0 = value0; @@ -52,7 +54,7 @@ namespace OneOf _value19 = value19; } - public object Value => + public object? Value => _index switch { 0 => _value0, @@ -75,7 +77,7 @@ namespace OneOf 17 => _value17, 18 => _value18, 19 => _value19, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; public int Index => _index; @@ -305,7 +307,7 @@ public void Switch(Action f0, Action f1, Action f2, Action f3, A f19(_value19); return; } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } public TResult Match(Func f0, Func f1, Func f2, Func f3, Func f4, Func f5, Func f6, Func f7, Func f8, Func f9, Func f10, Func f11, Func f12, Func f13, Func f14, Func f15, Func f16, Func f17, Func f18, Func f19) @@ -390,7 +392,7 @@ public TResult Match(Func f0, Func f1, Func FromT0(T0 input) => input; @@ -443,7 +445,7 @@ public OneOf AsT17, 18 => AsT18, 19 => AsT19, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -475,7 +477,7 @@ public OneOf AsT17, 18 => AsT18, 19 => AsT19, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -507,7 +509,7 @@ public OneOf AsT17, 18 => AsT18, 19 => AsT19, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -539,7 +541,7 @@ public OneOf AsT17, 18 => AsT18, 19 => AsT19, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -571,7 +573,7 @@ public OneOf AsT17, 18 => AsT18, 19 => AsT19, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -603,7 +605,7 @@ public OneOf AsT17, 18 => AsT18, 19 => AsT19, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -635,7 +637,7 @@ public OneOf AsT17, 18 => AsT18, 19 => AsT19, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -667,7 +669,7 @@ public OneOf AsT17, 18 => AsT18, 19 => AsT19, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -699,7 +701,7 @@ public OneOf AsT17, 18 => AsT18, 19 => AsT19, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -731,7 +733,7 @@ public OneOf AsT17, 18 => AsT18, 19 => AsT19, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -763,7 +765,7 @@ public OneOf AsT17, 18 => AsT18, 19 => AsT19, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -795,7 +797,7 @@ public OneOf AsT17, 18 => AsT18, 19 => AsT19, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -827,7 +829,7 @@ public OneOf AsT17, 18 => AsT18, 19 => AsT19, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -859,7 +861,7 @@ public OneOf AsT17, 18 => AsT18, 19 => AsT19, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -891,7 +893,7 @@ public OneOf AsT17, 18 => AsT18, 19 => AsT19, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -923,7 +925,7 @@ public OneOf AsT17, 18 => AsT18, 19 => AsT19, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -955,7 +957,7 @@ public OneOf AsT17, 18 => AsT18, 19 => AsT19, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -987,7 +989,7 @@ public OneOf mapFunc(AsT17), 18 => AsT18, 19 => AsT19, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1019,7 +1021,7 @@ public OneOf AsT17, 18 => mapFunc(AsT18), 19 => AsT19, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1051,11 +1053,15 @@ public OneOf AsT17, 18 => AsT18, 19 => mapFunc(AsT19), - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } - public bool TryPickT0(out T0 value, out OneOf remainder) +#if NET + public bool TryPickT0([NotNullWhen(true)] out T0? value, out OneOf remainder) +#else + public bool TryPickT0(out T0? value, out OneOf remainder) +#endif { value = IsT0 ? AsT0 : default; remainder = _index switch @@ -1080,12 +1086,16 @@ public bool TryPickT0(out T0 value, out OneOf AsT17, 18 => AsT18, 19 => AsT19, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT0; } - public bool TryPickT1(out T1 value, out OneOf remainder) +#if NET + public bool TryPickT1([NotNullWhen(true)] out T1? value, out OneOf remainder) +#else + public bool TryPickT1(out T1? value, out OneOf remainder) +#endif { value = IsT1 ? AsT1 : default; remainder = _index switch @@ -1110,12 +1120,16 @@ public bool TryPickT1(out T1 value, out OneOf AsT17, 18 => AsT18, 19 => AsT19, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT1; } - public bool TryPickT2(out T2 value, out OneOf remainder) +#if NET + public bool TryPickT2([NotNullWhen(true)] out T2? value, out OneOf remainder) +#else + public bool TryPickT2(out T2? value, out OneOf remainder) +#endif { value = IsT2 ? AsT2 : default; remainder = _index switch @@ -1140,12 +1154,16 @@ public bool TryPickT2(out T2 value, out OneOf AsT17, 18 => AsT18, 19 => AsT19, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT2; } - public bool TryPickT3(out T3 value, out OneOf remainder) +#if NET + public bool TryPickT3([NotNullWhen(true)] out T3? value, out OneOf remainder) +#else + public bool TryPickT3(out T3? value, out OneOf remainder) +#endif { value = IsT3 ? AsT3 : default; remainder = _index switch @@ -1170,12 +1188,16 @@ public bool TryPickT3(out T3 value, out OneOf AsT17, 18 => AsT18, 19 => AsT19, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT3; } - public bool TryPickT4(out T4 value, out OneOf remainder) +#if NET + public bool TryPickT4([NotNullWhen(true)] out T4? value, out OneOf remainder) +#else + public bool TryPickT4(out T4? value, out OneOf remainder) +#endif { value = IsT4 ? AsT4 : default; remainder = _index switch @@ -1200,12 +1222,16 @@ public bool TryPickT4(out T4 value, out OneOf AsT17, 18 => AsT18, 19 => AsT19, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT4; } - public bool TryPickT5(out T5 value, out OneOf remainder) +#if NET + public bool TryPickT5([NotNullWhen(true)] out T5? value, out OneOf remainder) +#else + public bool TryPickT5(out T5? value, out OneOf remainder) +#endif { value = IsT5 ? AsT5 : default; remainder = _index switch @@ -1230,12 +1256,16 @@ public bool TryPickT5(out T5 value, out OneOf AsT17, 18 => AsT18, 19 => AsT19, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT5; } - public bool TryPickT6(out T6 value, out OneOf remainder) +#if NET + public bool TryPickT6([NotNullWhen(true)] out T6? value, out OneOf remainder) +#else + public bool TryPickT6(out T6? value, out OneOf remainder) +#endif { value = IsT6 ? AsT6 : default; remainder = _index switch @@ -1260,12 +1290,16 @@ public bool TryPickT6(out T6 value, out OneOf AsT17, 18 => AsT18, 19 => AsT19, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT6; } - public bool TryPickT7(out T7 value, out OneOf remainder) +#if NET + public bool TryPickT7([NotNullWhen(true)] out T7? value, out OneOf remainder) +#else + public bool TryPickT7(out T7? value, out OneOf remainder) +#endif { value = IsT7 ? AsT7 : default; remainder = _index switch @@ -1290,12 +1324,16 @@ public bool TryPickT7(out T7 value, out OneOf AsT17, 18 => AsT18, 19 => AsT19, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT7; } - public bool TryPickT8(out T8 value, out OneOf remainder) +#if NET + public bool TryPickT8([NotNullWhen(true)] out T8? value, out OneOf remainder) +#else + public bool TryPickT8(out T8? value, out OneOf remainder) +#endif { value = IsT8 ? AsT8 : default; remainder = _index switch @@ -1320,12 +1358,16 @@ public bool TryPickT8(out T8 value, out OneOf AsT17, 18 => AsT18, 19 => AsT19, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT8; } - public bool TryPickT9(out T9 value, out OneOf remainder) +#if NET + public bool TryPickT9([NotNullWhen(true)] out T9? value, out OneOf remainder) +#else + public bool TryPickT9(out T9? value, out OneOf remainder) +#endif { value = IsT9 ? AsT9 : default; remainder = _index switch @@ -1350,12 +1392,16 @@ public bool TryPickT9(out T9 value, out OneOf AsT17, 18 => AsT18, 19 => AsT19, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT9; } - public bool TryPickT10(out T10 value, out OneOf remainder) +#if NET + public bool TryPickT10([NotNullWhen(true)] out T10? value, out OneOf remainder) +#else + public bool TryPickT10(out T10? value, out OneOf remainder) +#endif { value = IsT10 ? AsT10 : default; remainder = _index switch @@ -1380,12 +1426,16 @@ public bool TryPickT10(out T10 value, out OneOf AsT17, 18 => AsT18, 19 => AsT19, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT10; } - public bool TryPickT11(out T11 value, out OneOf remainder) +#if NET + public bool TryPickT11([NotNullWhen(true)] out T11? value, out OneOf remainder) +#else + public bool TryPickT11(out T11? value, out OneOf remainder) +#endif { value = IsT11 ? AsT11 : default; remainder = _index switch @@ -1410,12 +1460,16 @@ public bool TryPickT11(out T11 value, out OneOf AsT17, 18 => AsT18, 19 => AsT19, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT11; } - public bool TryPickT12(out T12 value, out OneOf remainder) +#if NET + public bool TryPickT12([NotNullWhen(true)] out T12? value, out OneOf remainder) +#else + public bool TryPickT12(out T12? value, out OneOf remainder) +#endif { value = IsT12 ? AsT12 : default; remainder = _index switch @@ -1440,12 +1494,16 @@ public bool TryPickT12(out T12 value, out OneOf AsT17, 18 => AsT18, 19 => AsT19, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT12; } - public bool TryPickT13(out T13 value, out OneOf remainder) +#if NET + public bool TryPickT13([NotNullWhen(true)] out T13? value, out OneOf remainder) +#else + public bool TryPickT13(out T13? value, out OneOf remainder) +#endif { value = IsT13 ? AsT13 : default; remainder = _index switch @@ -1470,12 +1528,16 @@ public bool TryPickT13(out T13 value, out OneOf AsT17, 18 => AsT18, 19 => AsT19, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT13; } - public bool TryPickT14(out T14 value, out OneOf remainder) +#if NET + public bool TryPickT14([NotNullWhen(true)] out T14? value, out OneOf remainder) +#else + public bool TryPickT14(out T14? value, out OneOf remainder) +#endif { value = IsT14 ? AsT14 : default; remainder = _index switch @@ -1500,12 +1562,16 @@ public bool TryPickT14(out T14 value, out OneOf AsT17, 18 => AsT18, 19 => AsT19, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT14; } - public bool TryPickT15(out T15 value, out OneOf remainder) +#if NET + public bool TryPickT15([NotNullWhen(true)] out T15? value, out OneOf remainder) +#else + public bool TryPickT15(out T15? value, out OneOf remainder) +#endif { value = IsT15 ? AsT15 : default; remainder = _index switch @@ -1530,12 +1596,16 @@ public bool TryPickT15(out T15 value, out OneOf AsT17, 18 => AsT18, 19 => AsT19, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT15; } - public bool TryPickT16(out T16 value, out OneOf remainder) +#if NET + public bool TryPickT16([NotNullWhen(true)] out T16? value, out OneOf remainder) +#else + public bool TryPickT16(out T16? value, out OneOf remainder) +#endif { value = IsT16 ? AsT16 : default; remainder = _index switch @@ -1560,12 +1630,16 @@ public bool TryPickT16(out T16 value, out OneOf AsT17, 18 => AsT18, 19 => AsT19, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT16; } - public bool TryPickT17(out T17 value, out OneOf remainder) +#if NET + public bool TryPickT17([NotNullWhen(true)] out T17? value, out OneOf remainder) +#else + public bool TryPickT17(out T17? value, out OneOf remainder) +#endif { value = IsT17 ? AsT17 : default; remainder = _index switch @@ -1590,12 +1664,16 @@ public bool TryPickT17(out T17 value, out OneOf default, 18 => AsT18, 19 => AsT19, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT17; } - public bool TryPickT18(out T18 value, out OneOf remainder) +#if NET + public bool TryPickT18([NotNullWhen(true)] out T18? value, out OneOf remainder) +#else + public bool TryPickT18(out T18? value, out OneOf remainder) +#endif { value = IsT18 ? AsT18 : default; remainder = _index switch @@ -1620,12 +1698,16 @@ public bool TryPickT18(out T18 value, out OneOf AsT17, 18 => default, 19 => AsT19, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT18; } - public bool TryPickT19(out T19 value, out OneOf remainder) +#if NET + public bool TryPickT19([NotNullWhen(true)] out T19? value, out OneOf remainder) +#else + public bool TryPickT19(out T19? value, out OneOf remainder) +#endif { value = IsT19 ? AsT19 : default; remainder = _index switch @@ -1650,7 +1732,7 @@ public bool TryPickT19(out T19 value, out OneOf AsT17, 18 => AsT18, 19 => default, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT19; } @@ -1682,7 +1764,7 @@ bool Equals(OneOf false }; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/OneOf.Extended/OneOfT20.generated.cs b/OneOf.Extended/OneOfT20.generated.cs index c03bd8b..5d94493 100644 --- a/OneOf.Extended/OneOfT20.generated.cs +++ b/OneOf.Extended/OneOfT20.generated.cs @@ -1,4 +1,6 @@ +#nullable enable using System; +using System.Diagnostics.CodeAnalysis; using static OneOf.Functions; namespace OneOf @@ -28,7 +30,7 @@ namespace OneOf readonly T20 _value20; readonly int _index; - OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default, T10 value10 = default, T11 value11 = default, T12 value12 = default, T13 value13 = default, T14 value14 = default, T15 value15 = default, T16 value16 = default, T17 value17 = default, T18 value18 = default, T19 value19 = default, T20 value20 = default) + OneOf(int index, T0 value0 = default!, T1 value1 = default!, T2 value2 = default!, T3 value3 = default!, T4 value4 = default!, T5 value5 = default!, T6 value6 = default!, T7 value7 = default!, T8 value8 = default!, T9 value9 = default!, T10 value10 = default!, T11 value11 = default!, T12 value12 = default!, T13 value13 = default!, T14 value14 = default!, T15 value15 = default!, T16 value16 = default!, T17 value17 = default!, T18 value18 = default!, T19 value19 = default!, T20 value20 = default!) { _index = index; _value0 = value0; @@ -54,7 +56,7 @@ namespace OneOf _value20 = value20; } - public object Value => + public object? Value => _index switch { 0 => _value0, @@ -78,7 +80,7 @@ namespace OneOf 18 => _value18, 19 => _value19, 20 => _value20, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; public int Index => _index; @@ -319,7 +321,7 @@ public void Switch(Action f0, Action f1, Action f2, Action f3, A f20(_value20); return; } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } public TResult Match(Func f0, Func f1, Func f2, Func f3, Func f4, Func f5, Func f6, Func f7, Func f8, Func f9, Func f10, Func f11, Func f12, Func f13, Func f14, Func f15, Func f16, Func f17, Func f18, Func f19, Func f20) @@ -408,7 +410,7 @@ public TResult Match(Func f0, Func f1, Func FromT0(T0 input) => input; @@ -463,7 +465,7 @@ public OneOf AsT18, 19 => AsT19, 20 => AsT20, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -496,7 +498,7 @@ public OneOf AsT18, 19 => AsT19, 20 => AsT20, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -529,7 +531,7 @@ public OneOf AsT18, 19 => AsT19, 20 => AsT20, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -562,7 +564,7 @@ public OneOf AsT18, 19 => AsT19, 20 => AsT20, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -595,7 +597,7 @@ public OneOf AsT18, 19 => AsT19, 20 => AsT20, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -628,7 +630,7 @@ public OneOf AsT18, 19 => AsT19, 20 => AsT20, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -661,7 +663,7 @@ public OneOf AsT18, 19 => AsT19, 20 => AsT20, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -694,7 +696,7 @@ public OneOf AsT18, 19 => AsT19, 20 => AsT20, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -727,7 +729,7 @@ public OneOf AsT18, 19 => AsT19, 20 => AsT20, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -760,7 +762,7 @@ public OneOf AsT18, 19 => AsT19, 20 => AsT20, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -793,7 +795,7 @@ public OneOf AsT18, 19 => AsT19, 20 => AsT20, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -826,7 +828,7 @@ public OneOf AsT18, 19 => AsT19, 20 => AsT20, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -859,7 +861,7 @@ public OneOf AsT18, 19 => AsT19, 20 => AsT20, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -892,7 +894,7 @@ public OneOf AsT18, 19 => AsT19, 20 => AsT20, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -925,7 +927,7 @@ public OneOf AsT18, 19 => AsT19, 20 => AsT20, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -958,7 +960,7 @@ public OneOf AsT18, 19 => AsT19, 20 => AsT20, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -991,7 +993,7 @@ public OneOf AsT18, 19 => AsT19, 20 => AsT20, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1024,7 +1026,7 @@ public OneOf AsT18, 19 => AsT19, 20 => AsT20, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1057,7 +1059,7 @@ public OneOf mapFunc(AsT18), 19 => AsT19, 20 => AsT20, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1090,7 +1092,7 @@ public OneOf AsT18, 19 => mapFunc(AsT19), 20 => AsT20, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1123,11 +1125,15 @@ public OneOf AsT18, 19 => AsT19, 20 => mapFunc(AsT20), - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } - public bool TryPickT0(out T0 value, out OneOf remainder) +#if NET + public bool TryPickT0([NotNullWhen(true)] out T0? value, out OneOf remainder) +#else + public bool TryPickT0(out T0? value, out OneOf remainder) +#endif { value = IsT0 ? AsT0 : default; remainder = _index switch @@ -1153,12 +1159,16 @@ public bool TryPickT0(out T0 value, out OneOf AsT18, 19 => AsT19, 20 => AsT20, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT0; } - public bool TryPickT1(out T1 value, out OneOf remainder) +#if NET + public bool TryPickT1([NotNullWhen(true)] out T1? value, out OneOf remainder) +#else + public bool TryPickT1(out T1? value, out OneOf remainder) +#endif { value = IsT1 ? AsT1 : default; remainder = _index switch @@ -1184,12 +1194,16 @@ public bool TryPickT1(out T1 value, out OneOf AsT18, 19 => AsT19, 20 => AsT20, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT1; } - public bool TryPickT2(out T2 value, out OneOf remainder) +#if NET + public bool TryPickT2([NotNullWhen(true)] out T2? value, out OneOf remainder) +#else + public bool TryPickT2(out T2? value, out OneOf remainder) +#endif { value = IsT2 ? AsT2 : default; remainder = _index switch @@ -1215,12 +1229,16 @@ public bool TryPickT2(out T2 value, out OneOf AsT18, 19 => AsT19, 20 => AsT20, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT2; } - public bool TryPickT3(out T3 value, out OneOf remainder) +#if NET + public bool TryPickT3([NotNullWhen(true)] out T3? value, out OneOf remainder) +#else + public bool TryPickT3(out T3? value, out OneOf remainder) +#endif { value = IsT3 ? AsT3 : default; remainder = _index switch @@ -1246,12 +1264,16 @@ public bool TryPickT3(out T3 value, out OneOf AsT18, 19 => AsT19, 20 => AsT20, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT3; } - public bool TryPickT4(out T4 value, out OneOf remainder) +#if NET + public bool TryPickT4([NotNullWhen(true)] out T4? value, out OneOf remainder) +#else + public bool TryPickT4(out T4? value, out OneOf remainder) +#endif { value = IsT4 ? AsT4 : default; remainder = _index switch @@ -1277,12 +1299,16 @@ public bool TryPickT4(out T4 value, out OneOf AsT18, 19 => AsT19, 20 => AsT20, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT4; } - public bool TryPickT5(out T5 value, out OneOf remainder) +#if NET + public bool TryPickT5([NotNullWhen(true)] out T5? value, out OneOf remainder) +#else + public bool TryPickT5(out T5? value, out OneOf remainder) +#endif { value = IsT5 ? AsT5 : default; remainder = _index switch @@ -1308,12 +1334,16 @@ public bool TryPickT5(out T5 value, out OneOf AsT18, 19 => AsT19, 20 => AsT20, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT5; } - public bool TryPickT6(out T6 value, out OneOf remainder) +#if NET + public bool TryPickT6([NotNullWhen(true)] out T6? value, out OneOf remainder) +#else + public bool TryPickT6(out T6? value, out OneOf remainder) +#endif { value = IsT6 ? AsT6 : default; remainder = _index switch @@ -1339,12 +1369,16 @@ public bool TryPickT6(out T6 value, out OneOf AsT18, 19 => AsT19, 20 => AsT20, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT6; } - public bool TryPickT7(out T7 value, out OneOf remainder) +#if NET + public bool TryPickT7([NotNullWhen(true)] out T7? value, out OneOf remainder) +#else + public bool TryPickT7(out T7? value, out OneOf remainder) +#endif { value = IsT7 ? AsT7 : default; remainder = _index switch @@ -1370,12 +1404,16 @@ public bool TryPickT7(out T7 value, out OneOf AsT18, 19 => AsT19, 20 => AsT20, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT7; } - public bool TryPickT8(out T8 value, out OneOf remainder) +#if NET + public bool TryPickT8([NotNullWhen(true)] out T8? value, out OneOf remainder) +#else + public bool TryPickT8(out T8? value, out OneOf remainder) +#endif { value = IsT8 ? AsT8 : default; remainder = _index switch @@ -1401,12 +1439,16 @@ public bool TryPickT8(out T8 value, out OneOf AsT18, 19 => AsT19, 20 => AsT20, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT8; } - public bool TryPickT9(out T9 value, out OneOf remainder) +#if NET + public bool TryPickT9([NotNullWhen(true)] out T9? value, out OneOf remainder) +#else + public bool TryPickT9(out T9? value, out OneOf remainder) +#endif { value = IsT9 ? AsT9 : default; remainder = _index switch @@ -1432,12 +1474,16 @@ public bool TryPickT9(out T9 value, out OneOf AsT18, 19 => AsT19, 20 => AsT20, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT9; } - public bool TryPickT10(out T10 value, out OneOf remainder) +#if NET + public bool TryPickT10([NotNullWhen(true)] out T10? value, out OneOf remainder) +#else + public bool TryPickT10(out T10? value, out OneOf remainder) +#endif { value = IsT10 ? AsT10 : default; remainder = _index switch @@ -1463,12 +1509,16 @@ public bool TryPickT10(out T10 value, out OneOf AsT18, 19 => AsT19, 20 => AsT20, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT10; } - public bool TryPickT11(out T11 value, out OneOf remainder) +#if NET + public bool TryPickT11([NotNullWhen(true)] out T11? value, out OneOf remainder) +#else + public bool TryPickT11(out T11? value, out OneOf remainder) +#endif { value = IsT11 ? AsT11 : default; remainder = _index switch @@ -1494,12 +1544,16 @@ public bool TryPickT11(out T11 value, out OneOf AsT18, 19 => AsT19, 20 => AsT20, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT11; } - public bool TryPickT12(out T12 value, out OneOf remainder) +#if NET + public bool TryPickT12([NotNullWhen(true)] out T12? value, out OneOf remainder) +#else + public bool TryPickT12(out T12? value, out OneOf remainder) +#endif { value = IsT12 ? AsT12 : default; remainder = _index switch @@ -1525,12 +1579,16 @@ public bool TryPickT12(out T12 value, out OneOf AsT18, 19 => AsT19, 20 => AsT20, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT12; } - public bool TryPickT13(out T13 value, out OneOf remainder) +#if NET + public bool TryPickT13([NotNullWhen(true)] out T13? value, out OneOf remainder) +#else + public bool TryPickT13(out T13? value, out OneOf remainder) +#endif { value = IsT13 ? AsT13 : default; remainder = _index switch @@ -1556,12 +1614,16 @@ public bool TryPickT13(out T13 value, out OneOf AsT18, 19 => AsT19, 20 => AsT20, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT13; } - public bool TryPickT14(out T14 value, out OneOf remainder) +#if NET + public bool TryPickT14([NotNullWhen(true)] out T14? value, out OneOf remainder) +#else + public bool TryPickT14(out T14? value, out OneOf remainder) +#endif { value = IsT14 ? AsT14 : default; remainder = _index switch @@ -1587,12 +1649,16 @@ public bool TryPickT14(out T14 value, out OneOf AsT18, 19 => AsT19, 20 => AsT20, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT14; } - public bool TryPickT15(out T15 value, out OneOf remainder) +#if NET + public bool TryPickT15([NotNullWhen(true)] out T15? value, out OneOf remainder) +#else + public bool TryPickT15(out T15? value, out OneOf remainder) +#endif { value = IsT15 ? AsT15 : default; remainder = _index switch @@ -1618,12 +1684,16 @@ public bool TryPickT15(out T15 value, out OneOf AsT18, 19 => AsT19, 20 => AsT20, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT15; } - public bool TryPickT16(out T16 value, out OneOf remainder) +#if NET + public bool TryPickT16([NotNullWhen(true)] out T16? value, out OneOf remainder) +#else + public bool TryPickT16(out T16? value, out OneOf remainder) +#endif { value = IsT16 ? AsT16 : default; remainder = _index switch @@ -1649,12 +1719,16 @@ public bool TryPickT16(out T16 value, out OneOf AsT18, 19 => AsT19, 20 => AsT20, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT16; } - public bool TryPickT17(out T17 value, out OneOf remainder) +#if NET + public bool TryPickT17([NotNullWhen(true)] out T17? value, out OneOf remainder) +#else + public bool TryPickT17(out T17? value, out OneOf remainder) +#endif { value = IsT17 ? AsT17 : default; remainder = _index switch @@ -1680,12 +1754,16 @@ public bool TryPickT17(out T17 value, out OneOf AsT18, 19 => AsT19, 20 => AsT20, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT17; } - public bool TryPickT18(out T18 value, out OneOf remainder) +#if NET + public bool TryPickT18([NotNullWhen(true)] out T18? value, out OneOf remainder) +#else + public bool TryPickT18(out T18? value, out OneOf remainder) +#endif { value = IsT18 ? AsT18 : default; remainder = _index switch @@ -1711,12 +1789,16 @@ public bool TryPickT18(out T18 value, out OneOf default, 19 => AsT19, 20 => AsT20, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT18; } - public bool TryPickT19(out T19 value, out OneOf remainder) +#if NET + public bool TryPickT19([NotNullWhen(true)] out T19? value, out OneOf remainder) +#else + public bool TryPickT19(out T19? value, out OneOf remainder) +#endif { value = IsT19 ? AsT19 : default; remainder = _index switch @@ -1742,12 +1824,16 @@ public bool TryPickT19(out T19 value, out OneOf AsT18, 19 => default, 20 => AsT20, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT19; } - public bool TryPickT20(out T20 value, out OneOf remainder) +#if NET + public bool TryPickT20([NotNullWhen(true)] out T20? value, out OneOf remainder) +#else + public bool TryPickT20(out T20? value, out OneOf remainder) +#endif { value = IsT20 ? AsT20 : default; remainder = _index switch @@ -1773,7 +1859,7 @@ public bool TryPickT20(out T20 value, out OneOf AsT18, 19 => AsT19, 20 => default, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT20; } @@ -1806,7 +1892,7 @@ bool Equals(OneOf false }; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/OneOf.Extended/OneOfT21.generated.cs b/OneOf.Extended/OneOfT21.generated.cs index 1d89b7b..bd58a39 100644 --- a/OneOf.Extended/OneOfT21.generated.cs +++ b/OneOf.Extended/OneOfT21.generated.cs @@ -1,4 +1,6 @@ +#nullable enable using System; +using System.Diagnostics.CodeAnalysis; using static OneOf.Functions; namespace OneOf @@ -29,7 +31,7 @@ namespace OneOf readonly T21 _value21; readonly int _index; - OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default, T10 value10 = default, T11 value11 = default, T12 value12 = default, T13 value13 = default, T14 value14 = default, T15 value15 = default, T16 value16 = default, T17 value17 = default, T18 value18 = default, T19 value19 = default, T20 value20 = default, T21 value21 = default) + OneOf(int index, T0 value0 = default!, T1 value1 = default!, T2 value2 = default!, T3 value3 = default!, T4 value4 = default!, T5 value5 = default!, T6 value6 = default!, T7 value7 = default!, T8 value8 = default!, T9 value9 = default!, T10 value10 = default!, T11 value11 = default!, T12 value12 = default!, T13 value13 = default!, T14 value14 = default!, T15 value15 = default!, T16 value16 = default!, T17 value17 = default!, T18 value18 = default!, T19 value19 = default!, T20 value20 = default!, T21 value21 = default!) { _index = index; _value0 = value0; @@ -56,7 +58,7 @@ namespace OneOf _value21 = value21; } - public object Value => + public object? Value => _index switch { 0 => _value0, @@ -81,7 +83,7 @@ namespace OneOf 19 => _value19, 20 => _value20, 21 => _value21, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; public int Index => _index; @@ -333,7 +335,7 @@ public void Switch(Action f0, Action f1, Action f2, Action f3, A f21(_value21); return; } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } public TResult Match(Func f0, Func f1, Func f2, Func f3, Func f4, Func f5, Func f6, Func f7, Func f8, Func f9, Func f10, Func f11, Func f12, Func f13, Func f14, Func f15, Func f16, Func f17, Func f18, Func f19, Func f20, Func f21) @@ -426,7 +428,7 @@ public TResult Match(Func f0, Func f1, Func FromT0(T0 input) => input; @@ -483,7 +485,7 @@ public OneOf AsT19, 20 => AsT20, 21 => AsT21, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -517,7 +519,7 @@ public OneOf AsT19, 20 => AsT20, 21 => AsT21, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -551,7 +553,7 @@ public OneOf AsT19, 20 => AsT20, 21 => AsT21, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -585,7 +587,7 @@ public OneOf AsT19, 20 => AsT20, 21 => AsT21, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -619,7 +621,7 @@ public OneOf AsT19, 20 => AsT20, 21 => AsT21, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -653,7 +655,7 @@ public OneOf AsT19, 20 => AsT20, 21 => AsT21, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -687,7 +689,7 @@ public OneOf AsT19, 20 => AsT20, 21 => AsT21, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -721,7 +723,7 @@ public OneOf AsT19, 20 => AsT20, 21 => AsT21, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -755,7 +757,7 @@ public OneOf AsT19, 20 => AsT20, 21 => AsT21, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -789,7 +791,7 @@ public OneOf AsT19, 20 => AsT20, 21 => AsT21, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -823,7 +825,7 @@ public OneOf AsT19, 20 => AsT20, 21 => AsT21, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -857,7 +859,7 @@ public OneOf AsT19, 20 => AsT20, 21 => AsT21, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -891,7 +893,7 @@ public OneOf AsT19, 20 => AsT20, 21 => AsT21, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -925,7 +927,7 @@ public OneOf AsT19, 20 => AsT20, 21 => AsT21, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -959,7 +961,7 @@ public OneOf AsT19, 20 => AsT20, 21 => AsT21, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -993,7 +995,7 @@ public OneOf AsT19, 20 => AsT20, 21 => AsT21, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1027,7 +1029,7 @@ public OneOf AsT19, 20 => AsT20, 21 => AsT21, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1061,7 +1063,7 @@ public OneOf AsT19, 20 => AsT20, 21 => AsT21, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1095,7 +1097,7 @@ public OneOf AsT19, 20 => AsT20, 21 => AsT21, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1129,7 +1131,7 @@ public OneOf mapFunc(AsT19), 20 => AsT20, 21 => AsT21, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1163,7 +1165,7 @@ public OneOf AsT19, 20 => mapFunc(AsT20), 21 => AsT21, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1197,11 +1199,15 @@ public OneOf AsT19, 20 => AsT20, 21 => mapFunc(AsT21), - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } - public bool TryPickT0(out T0 value, out OneOf remainder) +#if NET + public bool TryPickT0([NotNullWhen(true)] out T0? value, out OneOf remainder) +#else + public bool TryPickT0(out T0? value, out OneOf remainder) +#endif { value = IsT0 ? AsT0 : default; remainder = _index switch @@ -1228,12 +1234,16 @@ public bool TryPickT0(out T0 value, out OneOf AsT19, 20 => AsT20, 21 => AsT21, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT0; } - public bool TryPickT1(out T1 value, out OneOf remainder) +#if NET + public bool TryPickT1([NotNullWhen(true)] out T1? value, out OneOf remainder) +#else + public bool TryPickT1(out T1? value, out OneOf remainder) +#endif { value = IsT1 ? AsT1 : default; remainder = _index switch @@ -1260,12 +1270,16 @@ public bool TryPickT1(out T1 value, out OneOf AsT19, 20 => AsT20, 21 => AsT21, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT1; } - public bool TryPickT2(out T2 value, out OneOf remainder) +#if NET + public bool TryPickT2([NotNullWhen(true)] out T2? value, out OneOf remainder) +#else + public bool TryPickT2(out T2? value, out OneOf remainder) +#endif { value = IsT2 ? AsT2 : default; remainder = _index switch @@ -1292,12 +1306,16 @@ public bool TryPickT2(out T2 value, out OneOf AsT19, 20 => AsT20, 21 => AsT21, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT2; } - public bool TryPickT3(out T3 value, out OneOf remainder) +#if NET + public bool TryPickT3([NotNullWhen(true)] out T3? value, out OneOf remainder) +#else + public bool TryPickT3(out T3? value, out OneOf remainder) +#endif { value = IsT3 ? AsT3 : default; remainder = _index switch @@ -1324,12 +1342,16 @@ public bool TryPickT3(out T3 value, out OneOf AsT19, 20 => AsT20, 21 => AsT21, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT3; } - public bool TryPickT4(out T4 value, out OneOf remainder) +#if NET + public bool TryPickT4([NotNullWhen(true)] out T4? value, out OneOf remainder) +#else + public bool TryPickT4(out T4? value, out OneOf remainder) +#endif { value = IsT4 ? AsT4 : default; remainder = _index switch @@ -1356,12 +1378,16 @@ public bool TryPickT4(out T4 value, out OneOf AsT19, 20 => AsT20, 21 => AsT21, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT4; } - public bool TryPickT5(out T5 value, out OneOf remainder) +#if NET + public bool TryPickT5([NotNullWhen(true)] out T5? value, out OneOf remainder) +#else + public bool TryPickT5(out T5? value, out OneOf remainder) +#endif { value = IsT5 ? AsT5 : default; remainder = _index switch @@ -1388,12 +1414,16 @@ public bool TryPickT5(out T5 value, out OneOf AsT19, 20 => AsT20, 21 => AsT21, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT5; } - public bool TryPickT6(out T6 value, out OneOf remainder) +#if NET + public bool TryPickT6([NotNullWhen(true)] out T6? value, out OneOf remainder) +#else + public bool TryPickT6(out T6? value, out OneOf remainder) +#endif { value = IsT6 ? AsT6 : default; remainder = _index switch @@ -1420,12 +1450,16 @@ public bool TryPickT6(out T6 value, out OneOf AsT19, 20 => AsT20, 21 => AsT21, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT6; } - public bool TryPickT7(out T7 value, out OneOf remainder) +#if NET + public bool TryPickT7([NotNullWhen(true)] out T7? value, out OneOf remainder) +#else + public bool TryPickT7(out T7? value, out OneOf remainder) +#endif { value = IsT7 ? AsT7 : default; remainder = _index switch @@ -1452,12 +1486,16 @@ public bool TryPickT7(out T7 value, out OneOf AsT19, 20 => AsT20, 21 => AsT21, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT7; } - public bool TryPickT8(out T8 value, out OneOf remainder) +#if NET + public bool TryPickT8([NotNullWhen(true)] out T8? value, out OneOf remainder) +#else + public bool TryPickT8(out T8? value, out OneOf remainder) +#endif { value = IsT8 ? AsT8 : default; remainder = _index switch @@ -1484,12 +1522,16 @@ public bool TryPickT8(out T8 value, out OneOf AsT19, 20 => AsT20, 21 => AsT21, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT8; } - public bool TryPickT9(out T9 value, out OneOf remainder) +#if NET + public bool TryPickT9([NotNullWhen(true)] out T9? value, out OneOf remainder) +#else + public bool TryPickT9(out T9? value, out OneOf remainder) +#endif { value = IsT9 ? AsT9 : default; remainder = _index switch @@ -1516,12 +1558,16 @@ public bool TryPickT9(out T9 value, out OneOf AsT19, 20 => AsT20, 21 => AsT21, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT9; } - public bool TryPickT10(out T10 value, out OneOf remainder) +#if NET + public bool TryPickT10([NotNullWhen(true)] out T10? value, out OneOf remainder) +#else + public bool TryPickT10(out T10? value, out OneOf remainder) +#endif { value = IsT10 ? AsT10 : default; remainder = _index switch @@ -1548,12 +1594,16 @@ public bool TryPickT10(out T10 value, out OneOf AsT19, 20 => AsT20, 21 => AsT21, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT10; } - public bool TryPickT11(out T11 value, out OneOf remainder) +#if NET + public bool TryPickT11([NotNullWhen(true)] out T11? value, out OneOf remainder) +#else + public bool TryPickT11(out T11? value, out OneOf remainder) +#endif { value = IsT11 ? AsT11 : default; remainder = _index switch @@ -1580,12 +1630,16 @@ public bool TryPickT11(out T11 value, out OneOf AsT19, 20 => AsT20, 21 => AsT21, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT11; } - public bool TryPickT12(out T12 value, out OneOf remainder) +#if NET + public bool TryPickT12([NotNullWhen(true)] out T12? value, out OneOf remainder) +#else + public bool TryPickT12(out T12? value, out OneOf remainder) +#endif { value = IsT12 ? AsT12 : default; remainder = _index switch @@ -1612,12 +1666,16 @@ public bool TryPickT12(out T12 value, out OneOf AsT19, 20 => AsT20, 21 => AsT21, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT12; } - public bool TryPickT13(out T13 value, out OneOf remainder) +#if NET + public bool TryPickT13([NotNullWhen(true)] out T13? value, out OneOf remainder) +#else + public bool TryPickT13(out T13? value, out OneOf remainder) +#endif { value = IsT13 ? AsT13 : default; remainder = _index switch @@ -1644,12 +1702,16 @@ public bool TryPickT13(out T13 value, out OneOf AsT19, 20 => AsT20, 21 => AsT21, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT13; } - public bool TryPickT14(out T14 value, out OneOf remainder) +#if NET + public bool TryPickT14([NotNullWhen(true)] out T14? value, out OneOf remainder) +#else + public bool TryPickT14(out T14? value, out OneOf remainder) +#endif { value = IsT14 ? AsT14 : default; remainder = _index switch @@ -1676,12 +1738,16 @@ public bool TryPickT14(out T14 value, out OneOf AsT19, 20 => AsT20, 21 => AsT21, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT14; } - public bool TryPickT15(out T15 value, out OneOf remainder) +#if NET + public bool TryPickT15([NotNullWhen(true)] out T15? value, out OneOf remainder) +#else + public bool TryPickT15(out T15? value, out OneOf remainder) +#endif { value = IsT15 ? AsT15 : default; remainder = _index switch @@ -1708,12 +1774,16 @@ public bool TryPickT15(out T15 value, out OneOf AsT19, 20 => AsT20, 21 => AsT21, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT15; } - public bool TryPickT16(out T16 value, out OneOf remainder) +#if NET + public bool TryPickT16([NotNullWhen(true)] out T16? value, out OneOf remainder) +#else + public bool TryPickT16(out T16? value, out OneOf remainder) +#endif { value = IsT16 ? AsT16 : default; remainder = _index switch @@ -1740,12 +1810,16 @@ public bool TryPickT16(out T16 value, out OneOf AsT19, 20 => AsT20, 21 => AsT21, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT16; } - public bool TryPickT17(out T17 value, out OneOf remainder) +#if NET + public bool TryPickT17([NotNullWhen(true)] out T17? value, out OneOf remainder) +#else + public bool TryPickT17(out T17? value, out OneOf remainder) +#endif { value = IsT17 ? AsT17 : default; remainder = _index switch @@ -1772,12 +1846,16 @@ public bool TryPickT17(out T17 value, out OneOf AsT19, 20 => AsT20, 21 => AsT21, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT17; } - public bool TryPickT18(out T18 value, out OneOf remainder) +#if NET + public bool TryPickT18([NotNullWhen(true)] out T18? value, out OneOf remainder) +#else + public bool TryPickT18(out T18? value, out OneOf remainder) +#endif { value = IsT18 ? AsT18 : default; remainder = _index switch @@ -1804,12 +1882,16 @@ public bool TryPickT18(out T18 value, out OneOf AsT19, 20 => AsT20, 21 => AsT21, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT18; } - public bool TryPickT19(out T19 value, out OneOf remainder) +#if NET + public bool TryPickT19([NotNullWhen(true)] out T19? value, out OneOf remainder) +#else + public bool TryPickT19(out T19? value, out OneOf remainder) +#endif { value = IsT19 ? AsT19 : default; remainder = _index switch @@ -1836,12 +1918,16 @@ public bool TryPickT19(out T19 value, out OneOf default, 20 => AsT20, 21 => AsT21, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT19; } - public bool TryPickT20(out T20 value, out OneOf remainder) +#if NET + public bool TryPickT20([NotNullWhen(true)] out T20? value, out OneOf remainder) +#else + public bool TryPickT20(out T20? value, out OneOf remainder) +#endif { value = IsT20 ? AsT20 : default; remainder = _index switch @@ -1868,12 +1954,16 @@ public bool TryPickT20(out T20 value, out OneOf AsT19, 20 => default, 21 => AsT21, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT20; } - public bool TryPickT21(out T21 value, out OneOf remainder) +#if NET + public bool TryPickT21([NotNullWhen(true)] out T21? value, out OneOf remainder) +#else + public bool TryPickT21(out T21? value, out OneOf remainder) +#endif { value = IsT21 ? AsT21 : default; remainder = _index switch @@ -1900,7 +1990,7 @@ public bool TryPickT21(out T21 value, out OneOf AsT19, 20 => AsT20, 21 => default, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT21; } @@ -1934,7 +2024,7 @@ bool Equals(OneOf false }; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/OneOf.Extended/OneOfT22.generated.cs b/OneOf.Extended/OneOfT22.generated.cs index 58f9f5d..f1817b3 100644 --- a/OneOf.Extended/OneOfT22.generated.cs +++ b/OneOf.Extended/OneOfT22.generated.cs @@ -1,4 +1,6 @@ +#nullable enable using System; +using System.Diagnostics.CodeAnalysis; using static OneOf.Functions; namespace OneOf @@ -30,7 +32,7 @@ namespace OneOf readonly T22 _value22; readonly int _index; - OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default, T10 value10 = default, T11 value11 = default, T12 value12 = default, T13 value13 = default, T14 value14 = default, T15 value15 = default, T16 value16 = default, T17 value17 = default, T18 value18 = default, T19 value19 = default, T20 value20 = default, T21 value21 = default, T22 value22 = default) + OneOf(int index, T0 value0 = default!, T1 value1 = default!, T2 value2 = default!, T3 value3 = default!, T4 value4 = default!, T5 value5 = default!, T6 value6 = default!, T7 value7 = default!, T8 value8 = default!, T9 value9 = default!, T10 value10 = default!, T11 value11 = default!, T12 value12 = default!, T13 value13 = default!, T14 value14 = default!, T15 value15 = default!, T16 value16 = default!, T17 value17 = default!, T18 value18 = default!, T19 value19 = default!, T20 value20 = default!, T21 value21 = default!, T22 value22 = default!) { _index = index; _value0 = value0; @@ -58,7 +60,7 @@ namespace OneOf _value22 = value22; } - public object Value => + public object? Value => _index switch { 0 => _value0, @@ -84,7 +86,7 @@ namespace OneOf 20 => _value20, 21 => _value21, 22 => _value22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; public int Index => _index; @@ -347,7 +349,7 @@ public void Switch(Action f0, Action f1, Action f2, Action f3, A f22(_value22); return; } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } public TResult Match(Func f0, Func f1, Func f2, Func f3, Func f4, Func f5, Func f6, Func f7, Func f8, Func f9, Func f10, Func f11, Func f12, Func f13, Func f14, Func f15, Func f16, Func f17, Func f18, Func f19, Func f20, Func f21, Func f22) @@ -444,7 +446,7 @@ public TResult Match(Func f0, Func f1, Func FromT0(T0 input) => input; @@ -503,7 +505,7 @@ public OneOf AsT20, 21 => AsT21, 22 => AsT22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -538,7 +540,7 @@ public OneOf AsT20, 21 => AsT21, 22 => AsT22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -573,7 +575,7 @@ public OneOf AsT20, 21 => AsT21, 22 => AsT22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -608,7 +610,7 @@ public OneOf AsT20, 21 => AsT21, 22 => AsT22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -643,7 +645,7 @@ public OneOf AsT20, 21 => AsT21, 22 => AsT22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -678,7 +680,7 @@ public OneOf AsT20, 21 => AsT21, 22 => AsT22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -713,7 +715,7 @@ public OneOf AsT20, 21 => AsT21, 22 => AsT22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -748,7 +750,7 @@ public OneOf AsT20, 21 => AsT21, 22 => AsT22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -783,7 +785,7 @@ public OneOf AsT20, 21 => AsT21, 22 => AsT22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -818,7 +820,7 @@ public OneOf AsT20, 21 => AsT21, 22 => AsT22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -853,7 +855,7 @@ public OneOf AsT20, 21 => AsT21, 22 => AsT22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -888,7 +890,7 @@ public OneOf AsT20, 21 => AsT21, 22 => AsT22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -923,7 +925,7 @@ public OneOf AsT20, 21 => AsT21, 22 => AsT22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -958,7 +960,7 @@ public OneOf AsT20, 21 => AsT21, 22 => AsT22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -993,7 +995,7 @@ public OneOf AsT20, 21 => AsT21, 22 => AsT22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1028,7 +1030,7 @@ public OneOf AsT20, 21 => AsT21, 22 => AsT22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1063,7 +1065,7 @@ public OneOf AsT20, 21 => AsT21, 22 => AsT22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1098,7 +1100,7 @@ public OneOf AsT20, 21 => AsT21, 22 => AsT22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1133,7 +1135,7 @@ public OneOf AsT20, 21 => AsT21, 22 => AsT22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1168,7 +1170,7 @@ public OneOf AsT20, 21 => AsT21, 22 => AsT22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1203,7 +1205,7 @@ public OneOf mapFunc(AsT20), 21 => AsT21, 22 => AsT22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1238,7 +1240,7 @@ public OneOf AsT20, 21 => mapFunc(AsT21), 22 => AsT22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1273,11 +1275,15 @@ public OneOf AsT20, 21 => AsT21, 22 => mapFunc(AsT22), - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } - public bool TryPickT0(out T0 value, out OneOf remainder) +#if NET + public bool TryPickT0([NotNullWhen(true)] out T0? value, out OneOf remainder) +#else + public bool TryPickT0(out T0? value, out OneOf remainder) +#endif { value = IsT0 ? AsT0 : default; remainder = _index switch @@ -1305,12 +1311,16 @@ public bool TryPickT0(out T0 value, out OneOf AsT20, 21 => AsT21, 22 => AsT22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT0; } - public bool TryPickT1(out T1 value, out OneOf remainder) +#if NET + public bool TryPickT1([NotNullWhen(true)] out T1? value, out OneOf remainder) +#else + public bool TryPickT1(out T1? value, out OneOf remainder) +#endif { value = IsT1 ? AsT1 : default; remainder = _index switch @@ -1338,12 +1348,16 @@ public bool TryPickT1(out T1 value, out OneOf AsT20, 21 => AsT21, 22 => AsT22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT1; } - public bool TryPickT2(out T2 value, out OneOf remainder) +#if NET + public bool TryPickT2([NotNullWhen(true)] out T2? value, out OneOf remainder) +#else + public bool TryPickT2(out T2? value, out OneOf remainder) +#endif { value = IsT2 ? AsT2 : default; remainder = _index switch @@ -1371,12 +1385,16 @@ public bool TryPickT2(out T2 value, out OneOf AsT20, 21 => AsT21, 22 => AsT22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT2; } - public bool TryPickT3(out T3 value, out OneOf remainder) +#if NET + public bool TryPickT3([NotNullWhen(true)] out T3? value, out OneOf remainder) +#else + public bool TryPickT3(out T3? value, out OneOf remainder) +#endif { value = IsT3 ? AsT3 : default; remainder = _index switch @@ -1404,12 +1422,16 @@ public bool TryPickT3(out T3 value, out OneOf AsT20, 21 => AsT21, 22 => AsT22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT3; } - public bool TryPickT4(out T4 value, out OneOf remainder) +#if NET + public bool TryPickT4([NotNullWhen(true)] out T4? value, out OneOf remainder) +#else + public bool TryPickT4(out T4? value, out OneOf remainder) +#endif { value = IsT4 ? AsT4 : default; remainder = _index switch @@ -1437,12 +1459,16 @@ public bool TryPickT4(out T4 value, out OneOf AsT20, 21 => AsT21, 22 => AsT22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT4; } - public bool TryPickT5(out T5 value, out OneOf remainder) +#if NET + public bool TryPickT5([NotNullWhen(true)] out T5? value, out OneOf remainder) +#else + public bool TryPickT5(out T5? value, out OneOf remainder) +#endif { value = IsT5 ? AsT5 : default; remainder = _index switch @@ -1470,12 +1496,16 @@ public bool TryPickT5(out T5 value, out OneOf AsT20, 21 => AsT21, 22 => AsT22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT5; } - public bool TryPickT6(out T6 value, out OneOf remainder) +#if NET + public bool TryPickT6([NotNullWhen(true)] out T6? value, out OneOf remainder) +#else + public bool TryPickT6(out T6? value, out OneOf remainder) +#endif { value = IsT6 ? AsT6 : default; remainder = _index switch @@ -1503,12 +1533,16 @@ public bool TryPickT6(out T6 value, out OneOf AsT20, 21 => AsT21, 22 => AsT22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT6; } - public bool TryPickT7(out T7 value, out OneOf remainder) +#if NET + public bool TryPickT7([NotNullWhen(true)] out T7? value, out OneOf remainder) +#else + public bool TryPickT7(out T7? value, out OneOf remainder) +#endif { value = IsT7 ? AsT7 : default; remainder = _index switch @@ -1536,12 +1570,16 @@ public bool TryPickT7(out T7 value, out OneOf AsT20, 21 => AsT21, 22 => AsT22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT7; } - public bool TryPickT8(out T8 value, out OneOf remainder) +#if NET + public bool TryPickT8([NotNullWhen(true)] out T8? value, out OneOf remainder) +#else + public bool TryPickT8(out T8? value, out OneOf remainder) +#endif { value = IsT8 ? AsT8 : default; remainder = _index switch @@ -1569,12 +1607,16 @@ public bool TryPickT8(out T8 value, out OneOf AsT20, 21 => AsT21, 22 => AsT22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT8; } - public bool TryPickT9(out T9 value, out OneOf remainder) +#if NET + public bool TryPickT9([NotNullWhen(true)] out T9? value, out OneOf remainder) +#else + public bool TryPickT9(out T9? value, out OneOf remainder) +#endif { value = IsT9 ? AsT9 : default; remainder = _index switch @@ -1602,12 +1644,16 @@ public bool TryPickT9(out T9 value, out OneOf AsT20, 21 => AsT21, 22 => AsT22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT9; } - public bool TryPickT10(out T10 value, out OneOf remainder) +#if NET + public bool TryPickT10([NotNullWhen(true)] out T10? value, out OneOf remainder) +#else + public bool TryPickT10(out T10? value, out OneOf remainder) +#endif { value = IsT10 ? AsT10 : default; remainder = _index switch @@ -1635,12 +1681,16 @@ public bool TryPickT10(out T10 value, out OneOf AsT20, 21 => AsT21, 22 => AsT22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT10; } - public bool TryPickT11(out T11 value, out OneOf remainder) +#if NET + public bool TryPickT11([NotNullWhen(true)] out T11? value, out OneOf remainder) +#else + public bool TryPickT11(out T11? value, out OneOf remainder) +#endif { value = IsT11 ? AsT11 : default; remainder = _index switch @@ -1668,12 +1718,16 @@ public bool TryPickT11(out T11 value, out OneOf AsT20, 21 => AsT21, 22 => AsT22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT11; } - public bool TryPickT12(out T12 value, out OneOf remainder) +#if NET + public bool TryPickT12([NotNullWhen(true)] out T12? value, out OneOf remainder) +#else + public bool TryPickT12(out T12? value, out OneOf remainder) +#endif { value = IsT12 ? AsT12 : default; remainder = _index switch @@ -1701,12 +1755,16 @@ public bool TryPickT12(out T12 value, out OneOf AsT20, 21 => AsT21, 22 => AsT22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT12; } - public bool TryPickT13(out T13 value, out OneOf remainder) +#if NET + public bool TryPickT13([NotNullWhen(true)] out T13? value, out OneOf remainder) +#else + public bool TryPickT13(out T13? value, out OneOf remainder) +#endif { value = IsT13 ? AsT13 : default; remainder = _index switch @@ -1734,12 +1792,16 @@ public bool TryPickT13(out T13 value, out OneOf AsT20, 21 => AsT21, 22 => AsT22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT13; } - public bool TryPickT14(out T14 value, out OneOf remainder) +#if NET + public bool TryPickT14([NotNullWhen(true)] out T14? value, out OneOf remainder) +#else + public bool TryPickT14(out T14? value, out OneOf remainder) +#endif { value = IsT14 ? AsT14 : default; remainder = _index switch @@ -1767,12 +1829,16 @@ public bool TryPickT14(out T14 value, out OneOf AsT20, 21 => AsT21, 22 => AsT22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT14; } - public bool TryPickT15(out T15 value, out OneOf remainder) +#if NET + public bool TryPickT15([NotNullWhen(true)] out T15? value, out OneOf remainder) +#else + public bool TryPickT15(out T15? value, out OneOf remainder) +#endif { value = IsT15 ? AsT15 : default; remainder = _index switch @@ -1800,12 +1866,16 @@ public bool TryPickT15(out T15 value, out OneOf AsT20, 21 => AsT21, 22 => AsT22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT15; } - public bool TryPickT16(out T16 value, out OneOf remainder) +#if NET + public bool TryPickT16([NotNullWhen(true)] out T16? value, out OneOf remainder) +#else + public bool TryPickT16(out T16? value, out OneOf remainder) +#endif { value = IsT16 ? AsT16 : default; remainder = _index switch @@ -1833,12 +1903,16 @@ public bool TryPickT16(out T16 value, out OneOf AsT20, 21 => AsT21, 22 => AsT22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT16; } - public bool TryPickT17(out T17 value, out OneOf remainder) +#if NET + public bool TryPickT17([NotNullWhen(true)] out T17? value, out OneOf remainder) +#else + public bool TryPickT17(out T17? value, out OneOf remainder) +#endif { value = IsT17 ? AsT17 : default; remainder = _index switch @@ -1866,12 +1940,16 @@ public bool TryPickT17(out T17 value, out OneOf AsT20, 21 => AsT21, 22 => AsT22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT17; } - public bool TryPickT18(out T18 value, out OneOf remainder) +#if NET + public bool TryPickT18([NotNullWhen(true)] out T18? value, out OneOf remainder) +#else + public bool TryPickT18(out T18? value, out OneOf remainder) +#endif { value = IsT18 ? AsT18 : default; remainder = _index switch @@ -1899,12 +1977,16 @@ public bool TryPickT18(out T18 value, out OneOf AsT20, 21 => AsT21, 22 => AsT22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT18; } - public bool TryPickT19(out T19 value, out OneOf remainder) +#if NET + public bool TryPickT19([NotNullWhen(true)] out T19? value, out OneOf remainder) +#else + public bool TryPickT19(out T19? value, out OneOf remainder) +#endif { value = IsT19 ? AsT19 : default; remainder = _index switch @@ -1932,12 +2014,16 @@ public bool TryPickT19(out T19 value, out OneOf AsT20, 21 => AsT21, 22 => AsT22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT19; } - public bool TryPickT20(out T20 value, out OneOf remainder) +#if NET + public bool TryPickT20([NotNullWhen(true)] out T20? value, out OneOf remainder) +#else + public bool TryPickT20(out T20? value, out OneOf remainder) +#endif { value = IsT20 ? AsT20 : default; remainder = _index switch @@ -1965,12 +2051,16 @@ public bool TryPickT20(out T20 value, out OneOf default, 21 => AsT21, 22 => AsT22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT20; } - public bool TryPickT21(out T21 value, out OneOf remainder) +#if NET + public bool TryPickT21([NotNullWhen(true)] out T21? value, out OneOf remainder) +#else + public bool TryPickT21(out T21? value, out OneOf remainder) +#endif { value = IsT21 ? AsT21 : default; remainder = _index switch @@ -1998,12 +2088,16 @@ public bool TryPickT21(out T21 value, out OneOf AsT20, 21 => default, 22 => AsT22, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT21; } - public bool TryPickT22(out T22 value, out OneOf remainder) +#if NET + public bool TryPickT22([NotNullWhen(true)] out T22? value, out OneOf remainder) +#else + public bool TryPickT22(out T22? value, out OneOf remainder) +#endif { value = IsT22 ? AsT22 : default; remainder = _index switch @@ -2031,7 +2125,7 @@ public bool TryPickT22(out T22 value, out OneOf AsT20, 21 => AsT21, 22 => default, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT22; } @@ -2066,7 +2160,7 @@ bool Equals(OneOf false }; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/OneOf.Extended/OneOfT23.generated.cs b/OneOf.Extended/OneOfT23.generated.cs index aa8881c..6e9f038 100644 --- a/OneOf.Extended/OneOfT23.generated.cs +++ b/OneOf.Extended/OneOfT23.generated.cs @@ -1,4 +1,6 @@ +#nullable enable using System; +using System.Diagnostics.CodeAnalysis; using static OneOf.Functions; namespace OneOf @@ -31,7 +33,7 @@ namespace OneOf readonly T23 _value23; readonly int _index; - OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default, T10 value10 = default, T11 value11 = default, T12 value12 = default, T13 value13 = default, T14 value14 = default, T15 value15 = default, T16 value16 = default, T17 value17 = default, T18 value18 = default, T19 value19 = default, T20 value20 = default, T21 value21 = default, T22 value22 = default, T23 value23 = default) + OneOf(int index, T0 value0 = default!, T1 value1 = default!, T2 value2 = default!, T3 value3 = default!, T4 value4 = default!, T5 value5 = default!, T6 value6 = default!, T7 value7 = default!, T8 value8 = default!, T9 value9 = default!, T10 value10 = default!, T11 value11 = default!, T12 value12 = default!, T13 value13 = default!, T14 value14 = default!, T15 value15 = default!, T16 value16 = default!, T17 value17 = default!, T18 value18 = default!, T19 value19 = default!, T20 value20 = default!, T21 value21 = default!, T22 value22 = default!, T23 value23 = default!) { _index = index; _value0 = value0; @@ -60,7 +62,7 @@ namespace OneOf _value23 = value23; } - public object Value => + public object? Value => _index switch { 0 => _value0, @@ -87,7 +89,7 @@ namespace OneOf 21 => _value21, 22 => _value22, 23 => _value23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; public int Index => _index; @@ -361,7 +363,7 @@ public void Switch(Action f0, Action f1, Action f2, Action f3, A f23(_value23); return; } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } public TResult Match(Func f0, Func f1, Func f2, Func f3, Func f4, Func f5, Func f6, Func f7, Func f8, Func f9, Func f10, Func f11, Func f12, Func f13, Func f14, Func f15, Func f16, Func f17, Func f18, Func f19, Func f20, Func f21, Func f22, Func f23) @@ -462,7 +464,7 @@ public TResult Match(Func f0, Func f1, Func FromT0(T0 input) => input; @@ -523,7 +525,7 @@ public OneOf AsT21, 22 => AsT22, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -559,7 +561,7 @@ public OneOf AsT21, 22 => AsT22, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -595,7 +597,7 @@ public OneOf AsT21, 22 => AsT22, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -631,7 +633,7 @@ public OneOf AsT21, 22 => AsT22, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -667,7 +669,7 @@ public OneOf AsT21, 22 => AsT22, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -703,7 +705,7 @@ public OneOf AsT21, 22 => AsT22, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -739,7 +741,7 @@ public OneOf AsT21, 22 => AsT22, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -775,7 +777,7 @@ public OneOf AsT21, 22 => AsT22, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -811,7 +813,7 @@ public OneOf AsT21, 22 => AsT22, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -847,7 +849,7 @@ public OneOf AsT21, 22 => AsT22, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -883,7 +885,7 @@ public OneOf AsT21, 22 => AsT22, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -919,7 +921,7 @@ public OneOf AsT21, 22 => AsT22, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -955,7 +957,7 @@ public OneOf AsT21, 22 => AsT22, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -991,7 +993,7 @@ public OneOf AsT21, 22 => AsT22, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1027,7 +1029,7 @@ public OneOf AsT21, 22 => AsT22, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1063,7 +1065,7 @@ public OneOf AsT21, 22 => AsT22, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1099,7 +1101,7 @@ public OneOf AsT21, 22 => AsT22, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1135,7 +1137,7 @@ public OneOf AsT21, 22 => AsT22, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1171,7 +1173,7 @@ public OneOf AsT21, 22 => AsT22, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1207,7 +1209,7 @@ public OneOf AsT21, 22 => AsT22, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1243,7 +1245,7 @@ public OneOf AsT21, 22 => AsT22, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1279,7 +1281,7 @@ public OneOf mapFunc(AsT21), 22 => AsT22, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1315,7 +1317,7 @@ public OneOf AsT21, 22 => mapFunc(AsT22), 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1351,11 +1353,15 @@ public OneOf AsT21, 22 => AsT22, 23 => mapFunc(AsT23), - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } - public bool TryPickT0(out T0 value, out OneOf remainder) +#if NET + public bool TryPickT0([NotNullWhen(true)] out T0? value, out OneOf remainder) +#else + public bool TryPickT0(out T0? value, out OneOf remainder) +#endif { value = IsT0 ? AsT0 : default; remainder = _index switch @@ -1384,12 +1390,16 @@ public bool TryPickT0(out T0 value, out OneOf AsT21, 22 => AsT22, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT0; } - public bool TryPickT1(out T1 value, out OneOf remainder) +#if NET + public bool TryPickT1([NotNullWhen(true)] out T1? value, out OneOf remainder) +#else + public bool TryPickT1(out T1? value, out OneOf remainder) +#endif { value = IsT1 ? AsT1 : default; remainder = _index switch @@ -1418,12 +1428,16 @@ public bool TryPickT1(out T1 value, out OneOf AsT21, 22 => AsT22, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT1; } - public bool TryPickT2(out T2 value, out OneOf remainder) +#if NET + public bool TryPickT2([NotNullWhen(true)] out T2? value, out OneOf remainder) +#else + public bool TryPickT2(out T2? value, out OneOf remainder) +#endif { value = IsT2 ? AsT2 : default; remainder = _index switch @@ -1452,12 +1466,16 @@ public bool TryPickT2(out T2 value, out OneOf AsT21, 22 => AsT22, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT2; } - public bool TryPickT3(out T3 value, out OneOf remainder) +#if NET + public bool TryPickT3([NotNullWhen(true)] out T3? value, out OneOf remainder) +#else + public bool TryPickT3(out T3? value, out OneOf remainder) +#endif { value = IsT3 ? AsT3 : default; remainder = _index switch @@ -1486,12 +1504,16 @@ public bool TryPickT3(out T3 value, out OneOf AsT21, 22 => AsT22, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT3; } - public bool TryPickT4(out T4 value, out OneOf remainder) +#if NET + public bool TryPickT4([NotNullWhen(true)] out T4? value, out OneOf remainder) +#else + public bool TryPickT4(out T4? value, out OneOf remainder) +#endif { value = IsT4 ? AsT4 : default; remainder = _index switch @@ -1520,12 +1542,16 @@ public bool TryPickT4(out T4 value, out OneOf AsT21, 22 => AsT22, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT4; } - public bool TryPickT5(out T5 value, out OneOf remainder) +#if NET + public bool TryPickT5([NotNullWhen(true)] out T5? value, out OneOf remainder) +#else + public bool TryPickT5(out T5? value, out OneOf remainder) +#endif { value = IsT5 ? AsT5 : default; remainder = _index switch @@ -1554,12 +1580,16 @@ public bool TryPickT5(out T5 value, out OneOf AsT21, 22 => AsT22, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT5; } - public bool TryPickT6(out T6 value, out OneOf remainder) +#if NET + public bool TryPickT6([NotNullWhen(true)] out T6? value, out OneOf remainder) +#else + public bool TryPickT6(out T6? value, out OneOf remainder) +#endif { value = IsT6 ? AsT6 : default; remainder = _index switch @@ -1588,12 +1618,16 @@ public bool TryPickT6(out T6 value, out OneOf AsT21, 22 => AsT22, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT6; } - public bool TryPickT7(out T7 value, out OneOf remainder) +#if NET + public bool TryPickT7([NotNullWhen(true)] out T7? value, out OneOf remainder) +#else + public bool TryPickT7(out T7? value, out OneOf remainder) +#endif { value = IsT7 ? AsT7 : default; remainder = _index switch @@ -1622,12 +1656,16 @@ public bool TryPickT7(out T7 value, out OneOf AsT21, 22 => AsT22, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT7; } - public bool TryPickT8(out T8 value, out OneOf remainder) +#if NET + public bool TryPickT8([NotNullWhen(true)] out T8? value, out OneOf remainder) +#else + public bool TryPickT8(out T8? value, out OneOf remainder) +#endif { value = IsT8 ? AsT8 : default; remainder = _index switch @@ -1656,12 +1694,16 @@ public bool TryPickT8(out T8 value, out OneOf AsT21, 22 => AsT22, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT8; } - public bool TryPickT9(out T9 value, out OneOf remainder) +#if NET + public bool TryPickT9([NotNullWhen(true)] out T9? value, out OneOf remainder) +#else + public bool TryPickT9(out T9? value, out OneOf remainder) +#endif { value = IsT9 ? AsT9 : default; remainder = _index switch @@ -1690,12 +1732,16 @@ public bool TryPickT9(out T9 value, out OneOf AsT21, 22 => AsT22, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT9; } - public bool TryPickT10(out T10 value, out OneOf remainder) +#if NET + public bool TryPickT10([NotNullWhen(true)] out T10? value, out OneOf remainder) +#else + public bool TryPickT10(out T10? value, out OneOf remainder) +#endif { value = IsT10 ? AsT10 : default; remainder = _index switch @@ -1724,12 +1770,16 @@ public bool TryPickT10(out T10 value, out OneOf AsT21, 22 => AsT22, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT10; } - public bool TryPickT11(out T11 value, out OneOf remainder) +#if NET + public bool TryPickT11([NotNullWhen(true)] out T11? value, out OneOf remainder) +#else + public bool TryPickT11(out T11? value, out OneOf remainder) +#endif { value = IsT11 ? AsT11 : default; remainder = _index switch @@ -1758,12 +1808,16 @@ public bool TryPickT11(out T11 value, out OneOf AsT21, 22 => AsT22, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT11; } - public bool TryPickT12(out T12 value, out OneOf remainder) +#if NET + public bool TryPickT12([NotNullWhen(true)] out T12? value, out OneOf remainder) +#else + public bool TryPickT12(out T12? value, out OneOf remainder) +#endif { value = IsT12 ? AsT12 : default; remainder = _index switch @@ -1792,12 +1846,16 @@ public bool TryPickT12(out T12 value, out OneOf AsT21, 22 => AsT22, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT12; } - public bool TryPickT13(out T13 value, out OneOf remainder) +#if NET + public bool TryPickT13([NotNullWhen(true)] out T13? value, out OneOf remainder) +#else + public bool TryPickT13(out T13? value, out OneOf remainder) +#endif { value = IsT13 ? AsT13 : default; remainder = _index switch @@ -1826,12 +1884,16 @@ public bool TryPickT13(out T13 value, out OneOf AsT21, 22 => AsT22, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT13; } - public bool TryPickT14(out T14 value, out OneOf remainder) +#if NET + public bool TryPickT14([NotNullWhen(true)] out T14? value, out OneOf remainder) +#else + public bool TryPickT14(out T14? value, out OneOf remainder) +#endif { value = IsT14 ? AsT14 : default; remainder = _index switch @@ -1860,12 +1922,16 @@ public bool TryPickT14(out T14 value, out OneOf AsT21, 22 => AsT22, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT14; } - public bool TryPickT15(out T15 value, out OneOf remainder) +#if NET + public bool TryPickT15([NotNullWhen(true)] out T15? value, out OneOf remainder) +#else + public bool TryPickT15(out T15? value, out OneOf remainder) +#endif { value = IsT15 ? AsT15 : default; remainder = _index switch @@ -1894,12 +1960,16 @@ public bool TryPickT15(out T15 value, out OneOf AsT21, 22 => AsT22, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT15; } - public bool TryPickT16(out T16 value, out OneOf remainder) +#if NET + public bool TryPickT16([NotNullWhen(true)] out T16? value, out OneOf remainder) +#else + public bool TryPickT16(out T16? value, out OneOf remainder) +#endif { value = IsT16 ? AsT16 : default; remainder = _index switch @@ -1928,12 +1998,16 @@ public bool TryPickT16(out T16 value, out OneOf AsT21, 22 => AsT22, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT16; } - public bool TryPickT17(out T17 value, out OneOf remainder) +#if NET + public bool TryPickT17([NotNullWhen(true)] out T17? value, out OneOf remainder) +#else + public bool TryPickT17(out T17? value, out OneOf remainder) +#endif { value = IsT17 ? AsT17 : default; remainder = _index switch @@ -1962,12 +2036,16 @@ public bool TryPickT17(out T17 value, out OneOf AsT21, 22 => AsT22, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT17; } - public bool TryPickT18(out T18 value, out OneOf remainder) +#if NET + public bool TryPickT18([NotNullWhen(true)] out T18? value, out OneOf remainder) +#else + public bool TryPickT18(out T18? value, out OneOf remainder) +#endif { value = IsT18 ? AsT18 : default; remainder = _index switch @@ -1996,12 +2074,16 @@ public bool TryPickT18(out T18 value, out OneOf AsT21, 22 => AsT22, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT18; } - public bool TryPickT19(out T19 value, out OneOf remainder) +#if NET + public bool TryPickT19([NotNullWhen(true)] out T19? value, out OneOf remainder) +#else + public bool TryPickT19(out T19? value, out OneOf remainder) +#endif { value = IsT19 ? AsT19 : default; remainder = _index switch @@ -2030,12 +2112,16 @@ public bool TryPickT19(out T19 value, out OneOf AsT21, 22 => AsT22, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT19; } - public bool TryPickT20(out T20 value, out OneOf remainder) +#if NET + public bool TryPickT20([NotNullWhen(true)] out T20? value, out OneOf remainder) +#else + public bool TryPickT20(out T20? value, out OneOf remainder) +#endif { value = IsT20 ? AsT20 : default; remainder = _index switch @@ -2064,12 +2150,16 @@ public bool TryPickT20(out T20 value, out OneOf AsT21, 22 => AsT22, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT20; } - public bool TryPickT21(out T21 value, out OneOf remainder) +#if NET + public bool TryPickT21([NotNullWhen(true)] out T21? value, out OneOf remainder) +#else + public bool TryPickT21(out T21? value, out OneOf remainder) +#endif { value = IsT21 ? AsT21 : default; remainder = _index switch @@ -2098,12 +2188,16 @@ public bool TryPickT21(out T21 value, out OneOf default, 22 => AsT22, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT21; } - public bool TryPickT22(out T22 value, out OneOf remainder) +#if NET + public bool TryPickT22([NotNullWhen(true)] out T22? value, out OneOf remainder) +#else + public bool TryPickT22(out T22? value, out OneOf remainder) +#endif { value = IsT22 ? AsT22 : default; remainder = _index switch @@ -2132,12 +2226,16 @@ public bool TryPickT22(out T22 value, out OneOf AsT21, 22 => default, 23 => AsT23, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT22; } - public bool TryPickT23(out T23 value, out OneOf remainder) +#if NET + public bool TryPickT23([NotNullWhen(true)] out T23? value, out OneOf remainder) +#else + public bool TryPickT23(out T23? value, out OneOf remainder) +#endif { value = IsT23 ? AsT23 : default; remainder = _index switch @@ -2166,7 +2264,7 @@ public bool TryPickT23(out T23 value, out OneOf AsT21, 22 => AsT22, 23 => default, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT23; } @@ -2202,7 +2300,7 @@ bool Equals(OneOf false }; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/OneOf.Extended/OneOfT24.generated.cs b/OneOf.Extended/OneOfT24.generated.cs index 87854ed..5dd9418 100644 --- a/OneOf.Extended/OneOfT24.generated.cs +++ b/OneOf.Extended/OneOfT24.generated.cs @@ -1,4 +1,6 @@ +#nullable enable using System; +using System.Diagnostics.CodeAnalysis; using static OneOf.Functions; namespace OneOf @@ -32,7 +34,7 @@ namespace OneOf readonly T24 _value24; readonly int _index; - OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default, T10 value10 = default, T11 value11 = default, T12 value12 = default, T13 value13 = default, T14 value14 = default, T15 value15 = default, T16 value16 = default, T17 value17 = default, T18 value18 = default, T19 value19 = default, T20 value20 = default, T21 value21 = default, T22 value22 = default, T23 value23 = default, T24 value24 = default) + OneOf(int index, T0 value0 = default!, T1 value1 = default!, T2 value2 = default!, T3 value3 = default!, T4 value4 = default!, T5 value5 = default!, T6 value6 = default!, T7 value7 = default!, T8 value8 = default!, T9 value9 = default!, T10 value10 = default!, T11 value11 = default!, T12 value12 = default!, T13 value13 = default!, T14 value14 = default!, T15 value15 = default!, T16 value16 = default!, T17 value17 = default!, T18 value18 = default!, T19 value19 = default!, T20 value20 = default!, T21 value21 = default!, T22 value22 = default!, T23 value23 = default!, T24 value24 = default!) { _index = index; _value0 = value0; @@ -62,7 +64,7 @@ namespace OneOf _value24 = value24; } - public object Value => + public object? Value => _index switch { 0 => _value0, @@ -90,7 +92,7 @@ namespace OneOf 22 => _value22, 23 => _value23, 24 => _value24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; public int Index => _index; @@ -375,7 +377,7 @@ public void Switch(Action f0, Action f1, Action f2, Action f3, A f24(_value24); return; } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } public TResult Match(Func f0, Func f1, Func f2, Func f3, Func f4, Func f5, Func f6, Func f7, Func f8, Func f9, Func f10, Func f11, Func f12, Func f13, Func f14, Func f15, Func f16, Func f17, Func f18, Func f19, Func f20, Func f21, Func f22, Func f23, Func f24) @@ -480,7 +482,7 @@ public TResult Match(Func f0, Func f1, Func FromT0(T0 input) => input; @@ -543,7 +545,7 @@ public OneOf AsT22, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -580,7 +582,7 @@ public OneOf AsT22, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -617,7 +619,7 @@ public OneOf AsT22, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -654,7 +656,7 @@ public OneOf AsT22, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -691,7 +693,7 @@ public OneOf AsT22, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -728,7 +730,7 @@ public OneOf AsT22, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -765,7 +767,7 @@ public OneOf AsT22, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -802,7 +804,7 @@ public OneOf AsT22, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -839,7 +841,7 @@ public OneOf AsT22, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -876,7 +878,7 @@ public OneOf AsT22, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -913,7 +915,7 @@ public OneOf AsT22, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -950,7 +952,7 @@ public OneOf AsT22, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -987,7 +989,7 @@ public OneOf AsT22, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1024,7 +1026,7 @@ public OneOf AsT22, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1061,7 +1063,7 @@ public OneOf AsT22, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1098,7 +1100,7 @@ public OneOf AsT22, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1135,7 +1137,7 @@ public OneOf AsT22, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1172,7 +1174,7 @@ public OneOf AsT22, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1209,7 +1211,7 @@ public OneOf AsT22, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1246,7 +1248,7 @@ public OneOf AsT22, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1283,7 +1285,7 @@ public OneOf AsT22, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1320,7 +1322,7 @@ public OneOf AsT22, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1357,7 +1359,7 @@ public OneOf mapFunc(AsT22), 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1394,7 +1396,7 @@ public OneOf AsT22, 23 => mapFunc(AsT23), 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1431,11 +1433,15 @@ public OneOf AsT22, 23 => AsT23, 24 => mapFunc(AsT24), - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } - public bool TryPickT0(out T0 value, out OneOf remainder) +#if NET + public bool TryPickT0([NotNullWhen(true)] out T0? value, out OneOf remainder) +#else + public bool TryPickT0(out T0? value, out OneOf remainder) +#endif { value = IsT0 ? AsT0 : default; remainder = _index switch @@ -1465,12 +1471,16 @@ public bool TryPickT0(out T0 value, out OneOf AsT22, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT0; } - public bool TryPickT1(out T1 value, out OneOf remainder) +#if NET + public bool TryPickT1([NotNullWhen(true)] out T1? value, out OneOf remainder) +#else + public bool TryPickT1(out T1? value, out OneOf remainder) +#endif { value = IsT1 ? AsT1 : default; remainder = _index switch @@ -1500,12 +1510,16 @@ public bool TryPickT1(out T1 value, out OneOf AsT22, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT1; } - public bool TryPickT2(out T2 value, out OneOf remainder) +#if NET + public bool TryPickT2([NotNullWhen(true)] out T2? value, out OneOf remainder) +#else + public bool TryPickT2(out T2? value, out OneOf remainder) +#endif { value = IsT2 ? AsT2 : default; remainder = _index switch @@ -1535,12 +1549,16 @@ public bool TryPickT2(out T2 value, out OneOf AsT22, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT2; } - public bool TryPickT3(out T3 value, out OneOf remainder) +#if NET + public bool TryPickT3([NotNullWhen(true)] out T3? value, out OneOf remainder) +#else + public bool TryPickT3(out T3? value, out OneOf remainder) +#endif { value = IsT3 ? AsT3 : default; remainder = _index switch @@ -1570,12 +1588,16 @@ public bool TryPickT3(out T3 value, out OneOf AsT22, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT3; } - public bool TryPickT4(out T4 value, out OneOf remainder) +#if NET + public bool TryPickT4([NotNullWhen(true)] out T4? value, out OneOf remainder) +#else + public bool TryPickT4(out T4? value, out OneOf remainder) +#endif { value = IsT4 ? AsT4 : default; remainder = _index switch @@ -1605,12 +1627,16 @@ public bool TryPickT4(out T4 value, out OneOf AsT22, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT4; } - public bool TryPickT5(out T5 value, out OneOf remainder) +#if NET + public bool TryPickT5([NotNullWhen(true)] out T5? value, out OneOf remainder) +#else + public bool TryPickT5(out T5? value, out OneOf remainder) +#endif { value = IsT5 ? AsT5 : default; remainder = _index switch @@ -1640,12 +1666,16 @@ public bool TryPickT5(out T5 value, out OneOf AsT22, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT5; } - public bool TryPickT6(out T6 value, out OneOf remainder) +#if NET + public bool TryPickT6([NotNullWhen(true)] out T6? value, out OneOf remainder) +#else + public bool TryPickT6(out T6? value, out OneOf remainder) +#endif { value = IsT6 ? AsT6 : default; remainder = _index switch @@ -1675,12 +1705,16 @@ public bool TryPickT6(out T6 value, out OneOf AsT22, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT6; } - public bool TryPickT7(out T7 value, out OneOf remainder) +#if NET + public bool TryPickT7([NotNullWhen(true)] out T7? value, out OneOf remainder) +#else + public bool TryPickT7(out T7? value, out OneOf remainder) +#endif { value = IsT7 ? AsT7 : default; remainder = _index switch @@ -1710,12 +1744,16 @@ public bool TryPickT7(out T7 value, out OneOf AsT22, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT7; } - public bool TryPickT8(out T8 value, out OneOf remainder) +#if NET + public bool TryPickT8([NotNullWhen(true)] out T8? value, out OneOf remainder) +#else + public bool TryPickT8(out T8? value, out OneOf remainder) +#endif { value = IsT8 ? AsT8 : default; remainder = _index switch @@ -1745,12 +1783,16 @@ public bool TryPickT8(out T8 value, out OneOf AsT22, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT8; } - public bool TryPickT9(out T9 value, out OneOf remainder) +#if NET + public bool TryPickT9([NotNullWhen(true)] out T9? value, out OneOf remainder) +#else + public bool TryPickT9(out T9? value, out OneOf remainder) +#endif { value = IsT9 ? AsT9 : default; remainder = _index switch @@ -1780,12 +1822,16 @@ public bool TryPickT9(out T9 value, out OneOf AsT22, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT9; } - public bool TryPickT10(out T10 value, out OneOf remainder) +#if NET + public bool TryPickT10([NotNullWhen(true)] out T10? value, out OneOf remainder) +#else + public bool TryPickT10(out T10? value, out OneOf remainder) +#endif { value = IsT10 ? AsT10 : default; remainder = _index switch @@ -1815,12 +1861,16 @@ public bool TryPickT10(out T10 value, out OneOf AsT22, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT10; } - public bool TryPickT11(out T11 value, out OneOf remainder) +#if NET + public bool TryPickT11([NotNullWhen(true)] out T11? value, out OneOf remainder) +#else + public bool TryPickT11(out T11? value, out OneOf remainder) +#endif { value = IsT11 ? AsT11 : default; remainder = _index switch @@ -1850,12 +1900,16 @@ public bool TryPickT11(out T11 value, out OneOf AsT22, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT11; } - public bool TryPickT12(out T12 value, out OneOf remainder) +#if NET + public bool TryPickT12([NotNullWhen(true)] out T12? value, out OneOf remainder) +#else + public bool TryPickT12(out T12? value, out OneOf remainder) +#endif { value = IsT12 ? AsT12 : default; remainder = _index switch @@ -1885,12 +1939,16 @@ public bool TryPickT12(out T12 value, out OneOf AsT22, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT12; } - public bool TryPickT13(out T13 value, out OneOf remainder) +#if NET + public bool TryPickT13([NotNullWhen(true)] out T13? value, out OneOf remainder) +#else + public bool TryPickT13(out T13? value, out OneOf remainder) +#endif { value = IsT13 ? AsT13 : default; remainder = _index switch @@ -1920,12 +1978,16 @@ public bool TryPickT13(out T13 value, out OneOf AsT22, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT13; } - public bool TryPickT14(out T14 value, out OneOf remainder) +#if NET + public bool TryPickT14([NotNullWhen(true)] out T14? value, out OneOf remainder) +#else + public bool TryPickT14(out T14? value, out OneOf remainder) +#endif { value = IsT14 ? AsT14 : default; remainder = _index switch @@ -1955,12 +2017,16 @@ public bool TryPickT14(out T14 value, out OneOf AsT22, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT14; } - public bool TryPickT15(out T15 value, out OneOf remainder) +#if NET + public bool TryPickT15([NotNullWhen(true)] out T15? value, out OneOf remainder) +#else + public bool TryPickT15(out T15? value, out OneOf remainder) +#endif { value = IsT15 ? AsT15 : default; remainder = _index switch @@ -1990,12 +2056,16 @@ public bool TryPickT15(out T15 value, out OneOf AsT22, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT15; } - public bool TryPickT16(out T16 value, out OneOf remainder) +#if NET + public bool TryPickT16([NotNullWhen(true)] out T16? value, out OneOf remainder) +#else + public bool TryPickT16(out T16? value, out OneOf remainder) +#endif { value = IsT16 ? AsT16 : default; remainder = _index switch @@ -2025,12 +2095,16 @@ public bool TryPickT16(out T16 value, out OneOf AsT22, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT16; } - public bool TryPickT17(out T17 value, out OneOf remainder) +#if NET + public bool TryPickT17([NotNullWhen(true)] out T17? value, out OneOf remainder) +#else + public bool TryPickT17(out T17? value, out OneOf remainder) +#endif { value = IsT17 ? AsT17 : default; remainder = _index switch @@ -2060,12 +2134,16 @@ public bool TryPickT17(out T17 value, out OneOf AsT22, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT17; } - public bool TryPickT18(out T18 value, out OneOf remainder) +#if NET + public bool TryPickT18([NotNullWhen(true)] out T18? value, out OneOf remainder) +#else + public bool TryPickT18(out T18? value, out OneOf remainder) +#endif { value = IsT18 ? AsT18 : default; remainder = _index switch @@ -2095,12 +2173,16 @@ public bool TryPickT18(out T18 value, out OneOf AsT22, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT18; } - public bool TryPickT19(out T19 value, out OneOf remainder) +#if NET + public bool TryPickT19([NotNullWhen(true)] out T19? value, out OneOf remainder) +#else + public bool TryPickT19(out T19? value, out OneOf remainder) +#endif { value = IsT19 ? AsT19 : default; remainder = _index switch @@ -2130,12 +2212,16 @@ public bool TryPickT19(out T19 value, out OneOf AsT22, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT19; } - public bool TryPickT20(out T20 value, out OneOf remainder) +#if NET + public bool TryPickT20([NotNullWhen(true)] out T20? value, out OneOf remainder) +#else + public bool TryPickT20(out T20? value, out OneOf remainder) +#endif { value = IsT20 ? AsT20 : default; remainder = _index switch @@ -2165,12 +2251,16 @@ public bool TryPickT20(out T20 value, out OneOf AsT22, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT20; } - public bool TryPickT21(out T21 value, out OneOf remainder) +#if NET + public bool TryPickT21([NotNullWhen(true)] out T21? value, out OneOf remainder) +#else + public bool TryPickT21(out T21? value, out OneOf remainder) +#endif { value = IsT21 ? AsT21 : default; remainder = _index switch @@ -2200,12 +2290,16 @@ public bool TryPickT21(out T21 value, out OneOf AsT22, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT21; } - public bool TryPickT22(out T22 value, out OneOf remainder) +#if NET + public bool TryPickT22([NotNullWhen(true)] out T22? value, out OneOf remainder) +#else + public bool TryPickT22(out T22? value, out OneOf remainder) +#endif { value = IsT22 ? AsT22 : default; remainder = _index switch @@ -2235,12 +2329,16 @@ public bool TryPickT22(out T22 value, out OneOf default, 23 => AsT23, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT22; } - public bool TryPickT23(out T23 value, out OneOf remainder) +#if NET + public bool TryPickT23([NotNullWhen(true)] out T23? value, out OneOf remainder) +#else + public bool TryPickT23(out T23? value, out OneOf remainder) +#endif { value = IsT23 ? AsT23 : default; remainder = _index switch @@ -2270,12 +2368,16 @@ public bool TryPickT23(out T23 value, out OneOf AsT22, 23 => default, 24 => AsT24, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT23; } - public bool TryPickT24(out T24 value, out OneOf remainder) +#if NET + public bool TryPickT24([NotNullWhen(true)] out T24? value, out OneOf remainder) +#else + public bool TryPickT24(out T24? value, out OneOf remainder) +#endif { value = IsT24 ? AsT24 : default; remainder = _index switch @@ -2305,7 +2407,7 @@ public bool TryPickT24(out T24 value, out OneOf AsT22, 23 => AsT23, 24 => default, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT24; } @@ -2342,7 +2444,7 @@ bool Equals(OneOf false }; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/OneOf.Extended/OneOfT25.generated.cs b/OneOf.Extended/OneOfT25.generated.cs index dcc509c..279f7c5 100644 --- a/OneOf.Extended/OneOfT25.generated.cs +++ b/OneOf.Extended/OneOfT25.generated.cs @@ -1,4 +1,6 @@ +#nullable enable using System; +using System.Diagnostics.CodeAnalysis; using static OneOf.Functions; namespace OneOf @@ -33,7 +35,7 @@ namespace OneOf readonly T25 _value25; readonly int _index; - OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default, T10 value10 = default, T11 value11 = default, T12 value12 = default, T13 value13 = default, T14 value14 = default, T15 value15 = default, T16 value16 = default, T17 value17 = default, T18 value18 = default, T19 value19 = default, T20 value20 = default, T21 value21 = default, T22 value22 = default, T23 value23 = default, T24 value24 = default, T25 value25 = default) + OneOf(int index, T0 value0 = default!, T1 value1 = default!, T2 value2 = default!, T3 value3 = default!, T4 value4 = default!, T5 value5 = default!, T6 value6 = default!, T7 value7 = default!, T8 value8 = default!, T9 value9 = default!, T10 value10 = default!, T11 value11 = default!, T12 value12 = default!, T13 value13 = default!, T14 value14 = default!, T15 value15 = default!, T16 value16 = default!, T17 value17 = default!, T18 value18 = default!, T19 value19 = default!, T20 value20 = default!, T21 value21 = default!, T22 value22 = default!, T23 value23 = default!, T24 value24 = default!, T25 value25 = default!) { _index = index; _value0 = value0; @@ -64,7 +66,7 @@ namespace OneOf _value25 = value25; } - public object Value => + public object? Value => _index switch { 0 => _value0, @@ -93,7 +95,7 @@ namespace OneOf 23 => _value23, 24 => _value24, 25 => _value25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; public int Index => _index; @@ -389,7 +391,7 @@ public void Switch(Action f0, Action f1, Action f2, Action f3, A f25(_value25); return; } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } public TResult Match(Func f0, Func f1, Func f2, Func f3, Func f4, Func f5, Func f6, Func f7, Func f8, Func f9, Func f10, Func f11, Func f12, Func f13, Func f14, Func f15, Func f16, Func f17, Func f18, Func f19, Func f20, Func f21, Func f22, Func f23, Func f24, Func f25) @@ -498,7 +500,7 @@ public TResult Match(Func f0, Func f1, Func FromT0(T0 input) => input; @@ -563,7 +565,7 @@ public OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -601,7 +603,7 @@ public OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -639,7 +641,7 @@ public OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -677,7 +679,7 @@ public OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -715,7 +717,7 @@ public OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -753,7 +755,7 @@ public OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -791,7 +793,7 @@ public OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -829,7 +831,7 @@ public OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -867,7 +869,7 @@ public OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -905,7 +907,7 @@ public OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -943,7 +945,7 @@ public OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -981,7 +983,7 @@ public OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1019,7 +1021,7 @@ public OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1057,7 +1059,7 @@ public OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1095,7 +1097,7 @@ public OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1133,7 +1135,7 @@ public OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1171,7 +1173,7 @@ public OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1209,7 +1211,7 @@ public OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1247,7 +1249,7 @@ public OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1285,7 +1287,7 @@ public OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1323,7 +1325,7 @@ public OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1361,7 +1363,7 @@ public OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1399,7 +1401,7 @@ public OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1437,7 +1439,7 @@ public OneOf mapFunc(AsT23), 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1475,7 +1477,7 @@ public OneOf AsT23, 24 => mapFunc(AsT24), 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1513,11 +1515,15 @@ public OneOf AsT23, 24 => AsT24, 25 => mapFunc(AsT25), - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } - public bool TryPickT0(out T0 value, out OneOf remainder) +#if NET + public bool TryPickT0([NotNullWhen(true)] out T0? value, out OneOf remainder) +#else + public bool TryPickT0(out T0? value, out OneOf remainder) +#endif { value = IsT0 ? AsT0 : default; remainder = _index switch @@ -1548,12 +1554,16 @@ public bool TryPickT0(out T0 value, out OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT0; } - public bool TryPickT1(out T1 value, out OneOf remainder) +#if NET + public bool TryPickT1([NotNullWhen(true)] out T1? value, out OneOf remainder) +#else + public bool TryPickT1(out T1? value, out OneOf remainder) +#endif { value = IsT1 ? AsT1 : default; remainder = _index switch @@ -1584,12 +1594,16 @@ public bool TryPickT1(out T1 value, out OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT1; } - public bool TryPickT2(out T2 value, out OneOf remainder) +#if NET + public bool TryPickT2([NotNullWhen(true)] out T2? value, out OneOf remainder) +#else + public bool TryPickT2(out T2? value, out OneOf remainder) +#endif { value = IsT2 ? AsT2 : default; remainder = _index switch @@ -1620,12 +1634,16 @@ public bool TryPickT2(out T2 value, out OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT2; } - public bool TryPickT3(out T3 value, out OneOf remainder) +#if NET + public bool TryPickT3([NotNullWhen(true)] out T3? value, out OneOf remainder) +#else + public bool TryPickT3(out T3? value, out OneOf remainder) +#endif { value = IsT3 ? AsT3 : default; remainder = _index switch @@ -1656,12 +1674,16 @@ public bool TryPickT3(out T3 value, out OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT3; } - public bool TryPickT4(out T4 value, out OneOf remainder) +#if NET + public bool TryPickT4([NotNullWhen(true)] out T4? value, out OneOf remainder) +#else + public bool TryPickT4(out T4? value, out OneOf remainder) +#endif { value = IsT4 ? AsT4 : default; remainder = _index switch @@ -1692,12 +1714,16 @@ public bool TryPickT4(out T4 value, out OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT4; } - public bool TryPickT5(out T5 value, out OneOf remainder) +#if NET + public bool TryPickT5([NotNullWhen(true)] out T5? value, out OneOf remainder) +#else + public bool TryPickT5(out T5? value, out OneOf remainder) +#endif { value = IsT5 ? AsT5 : default; remainder = _index switch @@ -1728,12 +1754,16 @@ public bool TryPickT5(out T5 value, out OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT5; } - public bool TryPickT6(out T6 value, out OneOf remainder) +#if NET + public bool TryPickT6([NotNullWhen(true)] out T6? value, out OneOf remainder) +#else + public bool TryPickT6(out T6? value, out OneOf remainder) +#endif { value = IsT6 ? AsT6 : default; remainder = _index switch @@ -1764,12 +1794,16 @@ public bool TryPickT6(out T6 value, out OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT6; } - public bool TryPickT7(out T7 value, out OneOf remainder) +#if NET + public bool TryPickT7([NotNullWhen(true)] out T7? value, out OneOf remainder) +#else + public bool TryPickT7(out T7? value, out OneOf remainder) +#endif { value = IsT7 ? AsT7 : default; remainder = _index switch @@ -1800,12 +1834,16 @@ public bool TryPickT7(out T7 value, out OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT7; } - public bool TryPickT8(out T8 value, out OneOf remainder) +#if NET + public bool TryPickT8([NotNullWhen(true)] out T8? value, out OneOf remainder) +#else + public bool TryPickT8(out T8? value, out OneOf remainder) +#endif { value = IsT8 ? AsT8 : default; remainder = _index switch @@ -1836,12 +1874,16 @@ public bool TryPickT8(out T8 value, out OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT8; } - public bool TryPickT9(out T9 value, out OneOf remainder) +#if NET + public bool TryPickT9([NotNullWhen(true)] out T9? value, out OneOf remainder) +#else + public bool TryPickT9(out T9? value, out OneOf remainder) +#endif { value = IsT9 ? AsT9 : default; remainder = _index switch @@ -1872,12 +1914,16 @@ public bool TryPickT9(out T9 value, out OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT9; } - public bool TryPickT10(out T10 value, out OneOf remainder) +#if NET + public bool TryPickT10([NotNullWhen(true)] out T10? value, out OneOf remainder) +#else + public bool TryPickT10(out T10? value, out OneOf remainder) +#endif { value = IsT10 ? AsT10 : default; remainder = _index switch @@ -1908,12 +1954,16 @@ public bool TryPickT10(out T10 value, out OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT10; } - public bool TryPickT11(out T11 value, out OneOf remainder) +#if NET + public bool TryPickT11([NotNullWhen(true)] out T11? value, out OneOf remainder) +#else + public bool TryPickT11(out T11? value, out OneOf remainder) +#endif { value = IsT11 ? AsT11 : default; remainder = _index switch @@ -1944,12 +1994,16 @@ public bool TryPickT11(out T11 value, out OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT11; } - public bool TryPickT12(out T12 value, out OneOf remainder) +#if NET + public bool TryPickT12([NotNullWhen(true)] out T12? value, out OneOf remainder) +#else + public bool TryPickT12(out T12? value, out OneOf remainder) +#endif { value = IsT12 ? AsT12 : default; remainder = _index switch @@ -1980,12 +2034,16 @@ public bool TryPickT12(out T12 value, out OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT12; } - public bool TryPickT13(out T13 value, out OneOf remainder) +#if NET + public bool TryPickT13([NotNullWhen(true)] out T13? value, out OneOf remainder) +#else + public bool TryPickT13(out T13? value, out OneOf remainder) +#endif { value = IsT13 ? AsT13 : default; remainder = _index switch @@ -2016,12 +2074,16 @@ public bool TryPickT13(out T13 value, out OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT13; } - public bool TryPickT14(out T14 value, out OneOf remainder) +#if NET + public bool TryPickT14([NotNullWhen(true)] out T14? value, out OneOf remainder) +#else + public bool TryPickT14(out T14? value, out OneOf remainder) +#endif { value = IsT14 ? AsT14 : default; remainder = _index switch @@ -2052,12 +2114,16 @@ public bool TryPickT14(out T14 value, out OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT14; } - public bool TryPickT15(out T15 value, out OneOf remainder) +#if NET + public bool TryPickT15([NotNullWhen(true)] out T15? value, out OneOf remainder) +#else + public bool TryPickT15(out T15? value, out OneOf remainder) +#endif { value = IsT15 ? AsT15 : default; remainder = _index switch @@ -2088,12 +2154,16 @@ public bool TryPickT15(out T15 value, out OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT15; } - public bool TryPickT16(out T16 value, out OneOf remainder) +#if NET + public bool TryPickT16([NotNullWhen(true)] out T16? value, out OneOf remainder) +#else + public bool TryPickT16(out T16? value, out OneOf remainder) +#endif { value = IsT16 ? AsT16 : default; remainder = _index switch @@ -2124,12 +2194,16 @@ public bool TryPickT16(out T16 value, out OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT16; } - public bool TryPickT17(out T17 value, out OneOf remainder) +#if NET + public bool TryPickT17([NotNullWhen(true)] out T17? value, out OneOf remainder) +#else + public bool TryPickT17(out T17? value, out OneOf remainder) +#endif { value = IsT17 ? AsT17 : default; remainder = _index switch @@ -2160,12 +2234,16 @@ public bool TryPickT17(out T17 value, out OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT17; } - public bool TryPickT18(out T18 value, out OneOf remainder) +#if NET + public bool TryPickT18([NotNullWhen(true)] out T18? value, out OneOf remainder) +#else + public bool TryPickT18(out T18? value, out OneOf remainder) +#endif { value = IsT18 ? AsT18 : default; remainder = _index switch @@ -2196,12 +2274,16 @@ public bool TryPickT18(out T18 value, out OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT18; } - public bool TryPickT19(out T19 value, out OneOf remainder) +#if NET + public bool TryPickT19([NotNullWhen(true)] out T19? value, out OneOf remainder) +#else + public bool TryPickT19(out T19? value, out OneOf remainder) +#endif { value = IsT19 ? AsT19 : default; remainder = _index switch @@ -2232,12 +2314,16 @@ public bool TryPickT19(out T19 value, out OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT19; } - public bool TryPickT20(out T20 value, out OneOf remainder) +#if NET + public bool TryPickT20([NotNullWhen(true)] out T20? value, out OneOf remainder) +#else + public bool TryPickT20(out T20? value, out OneOf remainder) +#endif { value = IsT20 ? AsT20 : default; remainder = _index switch @@ -2268,12 +2354,16 @@ public bool TryPickT20(out T20 value, out OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT20; } - public bool TryPickT21(out T21 value, out OneOf remainder) +#if NET + public bool TryPickT21([NotNullWhen(true)] out T21? value, out OneOf remainder) +#else + public bool TryPickT21(out T21? value, out OneOf remainder) +#endif { value = IsT21 ? AsT21 : default; remainder = _index switch @@ -2304,12 +2394,16 @@ public bool TryPickT21(out T21 value, out OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT21; } - public bool TryPickT22(out T22 value, out OneOf remainder) +#if NET + public bool TryPickT22([NotNullWhen(true)] out T22? value, out OneOf remainder) +#else + public bool TryPickT22(out T22? value, out OneOf remainder) +#endif { value = IsT22 ? AsT22 : default; remainder = _index switch @@ -2340,12 +2434,16 @@ public bool TryPickT22(out T22 value, out OneOf AsT23, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT22; } - public bool TryPickT23(out T23 value, out OneOf remainder) +#if NET + public bool TryPickT23([NotNullWhen(true)] out T23? value, out OneOf remainder) +#else + public bool TryPickT23(out T23? value, out OneOf remainder) +#endif { value = IsT23 ? AsT23 : default; remainder = _index switch @@ -2376,12 +2474,16 @@ public bool TryPickT23(out T23 value, out OneOf default, 24 => AsT24, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT23; } - public bool TryPickT24(out T24 value, out OneOf remainder) +#if NET + public bool TryPickT24([NotNullWhen(true)] out T24? value, out OneOf remainder) +#else + public bool TryPickT24(out T24? value, out OneOf remainder) +#endif { value = IsT24 ? AsT24 : default; remainder = _index switch @@ -2412,12 +2514,16 @@ public bool TryPickT24(out T24 value, out OneOf AsT23, 24 => default, 25 => AsT25, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT24; } - public bool TryPickT25(out T25 value, out OneOf remainder) +#if NET + public bool TryPickT25([NotNullWhen(true)] out T25? value, out OneOf remainder) +#else + public bool TryPickT25(out T25? value, out OneOf remainder) +#endif { value = IsT25 ? AsT25 : default; remainder = _index switch @@ -2448,7 +2554,7 @@ public bool TryPickT25(out T25 value, out OneOf AsT23, 24 => AsT24, 25 => default, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT25; } @@ -2486,7 +2592,7 @@ bool Equals(OneOf false }; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/OneOf.Extended/OneOfT26.generated.cs b/OneOf.Extended/OneOfT26.generated.cs index a70fda0..06bfbc4 100644 --- a/OneOf.Extended/OneOfT26.generated.cs +++ b/OneOf.Extended/OneOfT26.generated.cs @@ -1,4 +1,6 @@ +#nullable enable using System; +using System.Diagnostics.CodeAnalysis; using static OneOf.Functions; namespace OneOf @@ -34,7 +36,7 @@ namespace OneOf readonly T26 _value26; readonly int _index; - OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default, T10 value10 = default, T11 value11 = default, T12 value12 = default, T13 value13 = default, T14 value14 = default, T15 value15 = default, T16 value16 = default, T17 value17 = default, T18 value18 = default, T19 value19 = default, T20 value20 = default, T21 value21 = default, T22 value22 = default, T23 value23 = default, T24 value24 = default, T25 value25 = default, T26 value26 = default) + OneOf(int index, T0 value0 = default!, T1 value1 = default!, T2 value2 = default!, T3 value3 = default!, T4 value4 = default!, T5 value5 = default!, T6 value6 = default!, T7 value7 = default!, T8 value8 = default!, T9 value9 = default!, T10 value10 = default!, T11 value11 = default!, T12 value12 = default!, T13 value13 = default!, T14 value14 = default!, T15 value15 = default!, T16 value16 = default!, T17 value17 = default!, T18 value18 = default!, T19 value19 = default!, T20 value20 = default!, T21 value21 = default!, T22 value22 = default!, T23 value23 = default!, T24 value24 = default!, T25 value25 = default!, T26 value26 = default!) { _index = index; _value0 = value0; @@ -66,7 +68,7 @@ namespace OneOf _value26 = value26; } - public object Value => + public object? Value => _index switch { 0 => _value0, @@ -96,7 +98,7 @@ namespace OneOf 24 => _value24, 25 => _value25, 26 => _value26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; public int Index => _index; @@ -403,7 +405,7 @@ public void Switch(Action f0, Action f1, Action f2, Action f3, A f26(_value26); return; } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } public TResult Match(Func f0, Func f1, Func f2, Func f3, Func f4, Func f5, Func f6, Func f7, Func f8, Func f9, Func f10, Func f11, Func f12, Func f13, Func f14, Func f15, Func f16, Func f17, Func f18, Func f19, Func f20, Func f21, Func f22, Func f23, Func f24, Func f25, Func f26) @@ -516,7 +518,7 @@ public TResult Match(Func f0, Func f1, Func FromT0(T0 input) => input; @@ -583,7 +585,7 @@ public OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -622,7 +624,7 @@ public OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -661,7 +663,7 @@ public OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -700,7 +702,7 @@ public OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -739,7 +741,7 @@ public OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -778,7 +780,7 @@ public OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -817,7 +819,7 @@ public OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -856,7 +858,7 @@ public OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -895,7 +897,7 @@ public OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -934,7 +936,7 @@ public OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -973,7 +975,7 @@ public OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1012,7 +1014,7 @@ public OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1051,7 +1053,7 @@ public OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1090,7 +1092,7 @@ public OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1129,7 +1131,7 @@ public OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1168,7 +1170,7 @@ public OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1207,7 +1209,7 @@ public OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1246,7 +1248,7 @@ public OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1285,7 +1287,7 @@ public OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1324,7 +1326,7 @@ public OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1363,7 +1365,7 @@ public OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1402,7 +1404,7 @@ public OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1441,7 +1443,7 @@ public OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1480,7 +1482,7 @@ public OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1519,7 +1521,7 @@ public OneOf mapFunc(AsT24), 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1558,7 +1560,7 @@ public OneOf AsT24, 25 => mapFunc(AsT25), 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1597,11 +1599,15 @@ public OneOf AsT24, 25 => AsT25, 26 => mapFunc(AsT26), - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } - public bool TryPickT0(out T0 value, out OneOf remainder) +#if NET + public bool TryPickT0([NotNullWhen(true)] out T0? value, out OneOf remainder) +#else + public bool TryPickT0(out T0? value, out OneOf remainder) +#endif { value = IsT0 ? AsT0 : default; remainder = _index switch @@ -1633,12 +1639,16 @@ public bool TryPickT0(out T0 value, out OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT0; } - public bool TryPickT1(out T1 value, out OneOf remainder) +#if NET + public bool TryPickT1([NotNullWhen(true)] out T1? value, out OneOf remainder) +#else + public bool TryPickT1(out T1? value, out OneOf remainder) +#endif { value = IsT1 ? AsT1 : default; remainder = _index switch @@ -1670,12 +1680,16 @@ public bool TryPickT1(out T1 value, out OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT1; } - public bool TryPickT2(out T2 value, out OneOf remainder) +#if NET + public bool TryPickT2([NotNullWhen(true)] out T2? value, out OneOf remainder) +#else + public bool TryPickT2(out T2? value, out OneOf remainder) +#endif { value = IsT2 ? AsT2 : default; remainder = _index switch @@ -1707,12 +1721,16 @@ public bool TryPickT2(out T2 value, out OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT2; } - public bool TryPickT3(out T3 value, out OneOf remainder) +#if NET + public bool TryPickT3([NotNullWhen(true)] out T3? value, out OneOf remainder) +#else + public bool TryPickT3(out T3? value, out OneOf remainder) +#endif { value = IsT3 ? AsT3 : default; remainder = _index switch @@ -1744,12 +1762,16 @@ public bool TryPickT3(out T3 value, out OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT3; } - public bool TryPickT4(out T4 value, out OneOf remainder) +#if NET + public bool TryPickT4([NotNullWhen(true)] out T4? value, out OneOf remainder) +#else + public bool TryPickT4(out T4? value, out OneOf remainder) +#endif { value = IsT4 ? AsT4 : default; remainder = _index switch @@ -1781,12 +1803,16 @@ public bool TryPickT4(out T4 value, out OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT4; } - public bool TryPickT5(out T5 value, out OneOf remainder) +#if NET + public bool TryPickT5([NotNullWhen(true)] out T5? value, out OneOf remainder) +#else + public bool TryPickT5(out T5? value, out OneOf remainder) +#endif { value = IsT5 ? AsT5 : default; remainder = _index switch @@ -1818,12 +1844,16 @@ public bool TryPickT5(out T5 value, out OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT5; } - public bool TryPickT6(out T6 value, out OneOf remainder) +#if NET + public bool TryPickT6([NotNullWhen(true)] out T6? value, out OneOf remainder) +#else + public bool TryPickT6(out T6? value, out OneOf remainder) +#endif { value = IsT6 ? AsT6 : default; remainder = _index switch @@ -1855,12 +1885,16 @@ public bool TryPickT6(out T6 value, out OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT6; } - public bool TryPickT7(out T7 value, out OneOf remainder) +#if NET + public bool TryPickT7([NotNullWhen(true)] out T7? value, out OneOf remainder) +#else + public bool TryPickT7(out T7? value, out OneOf remainder) +#endif { value = IsT7 ? AsT7 : default; remainder = _index switch @@ -1892,12 +1926,16 @@ public bool TryPickT7(out T7 value, out OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT7; } - public bool TryPickT8(out T8 value, out OneOf remainder) +#if NET + public bool TryPickT8([NotNullWhen(true)] out T8? value, out OneOf remainder) +#else + public bool TryPickT8(out T8? value, out OneOf remainder) +#endif { value = IsT8 ? AsT8 : default; remainder = _index switch @@ -1929,12 +1967,16 @@ public bool TryPickT8(out T8 value, out OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT8; } - public bool TryPickT9(out T9 value, out OneOf remainder) +#if NET + public bool TryPickT9([NotNullWhen(true)] out T9? value, out OneOf remainder) +#else + public bool TryPickT9(out T9? value, out OneOf remainder) +#endif { value = IsT9 ? AsT9 : default; remainder = _index switch @@ -1966,12 +2008,16 @@ public bool TryPickT9(out T9 value, out OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT9; } - public bool TryPickT10(out T10 value, out OneOf remainder) +#if NET + public bool TryPickT10([NotNullWhen(true)] out T10? value, out OneOf remainder) +#else + public bool TryPickT10(out T10? value, out OneOf remainder) +#endif { value = IsT10 ? AsT10 : default; remainder = _index switch @@ -2003,12 +2049,16 @@ public bool TryPickT10(out T10 value, out OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT10; } - public bool TryPickT11(out T11 value, out OneOf remainder) +#if NET + public bool TryPickT11([NotNullWhen(true)] out T11? value, out OneOf remainder) +#else + public bool TryPickT11(out T11? value, out OneOf remainder) +#endif { value = IsT11 ? AsT11 : default; remainder = _index switch @@ -2040,12 +2090,16 @@ public bool TryPickT11(out T11 value, out OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT11; } - public bool TryPickT12(out T12 value, out OneOf remainder) +#if NET + public bool TryPickT12([NotNullWhen(true)] out T12? value, out OneOf remainder) +#else + public bool TryPickT12(out T12? value, out OneOf remainder) +#endif { value = IsT12 ? AsT12 : default; remainder = _index switch @@ -2077,12 +2131,16 @@ public bool TryPickT12(out T12 value, out OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT12; } - public bool TryPickT13(out T13 value, out OneOf remainder) +#if NET + public bool TryPickT13([NotNullWhen(true)] out T13? value, out OneOf remainder) +#else + public bool TryPickT13(out T13? value, out OneOf remainder) +#endif { value = IsT13 ? AsT13 : default; remainder = _index switch @@ -2114,12 +2172,16 @@ public bool TryPickT13(out T13 value, out OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT13; } - public bool TryPickT14(out T14 value, out OneOf remainder) +#if NET + public bool TryPickT14([NotNullWhen(true)] out T14? value, out OneOf remainder) +#else + public bool TryPickT14(out T14? value, out OneOf remainder) +#endif { value = IsT14 ? AsT14 : default; remainder = _index switch @@ -2151,12 +2213,16 @@ public bool TryPickT14(out T14 value, out OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT14; } - public bool TryPickT15(out T15 value, out OneOf remainder) +#if NET + public bool TryPickT15([NotNullWhen(true)] out T15? value, out OneOf remainder) +#else + public bool TryPickT15(out T15? value, out OneOf remainder) +#endif { value = IsT15 ? AsT15 : default; remainder = _index switch @@ -2188,12 +2254,16 @@ public bool TryPickT15(out T15 value, out OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT15; } - public bool TryPickT16(out T16 value, out OneOf remainder) +#if NET + public bool TryPickT16([NotNullWhen(true)] out T16? value, out OneOf remainder) +#else + public bool TryPickT16(out T16? value, out OneOf remainder) +#endif { value = IsT16 ? AsT16 : default; remainder = _index switch @@ -2225,12 +2295,16 @@ public bool TryPickT16(out T16 value, out OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT16; } - public bool TryPickT17(out T17 value, out OneOf remainder) +#if NET + public bool TryPickT17([NotNullWhen(true)] out T17? value, out OneOf remainder) +#else + public bool TryPickT17(out T17? value, out OneOf remainder) +#endif { value = IsT17 ? AsT17 : default; remainder = _index switch @@ -2262,12 +2336,16 @@ public bool TryPickT17(out T17 value, out OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT17; } - public bool TryPickT18(out T18 value, out OneOf remainder) +#if NET + public bool TryPickT18([NotNullWhen(true)] out T18? value, out OneOf remainder) +#else + public bool TryPickT18(out T18? value, out OneOf remainder) +#endif { value = IsT18 ? AsT18 : default; remainder = _index switch @@ -2299,12 +2377,16 @@ public bool TryPickT18(out T18 value, out OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT18; } - public bool TryPickT19(out T19 value, out OneOf remainder) +#if NET + public bool TryPickT19([NotNullWhen(true)] out T19? value, out OneOf remainder) +#else + public bool TryPickT19(out T19? value, out OneOf remainder) +#endif { value = IsT19 ? AsT19 : default; remainder = _index switch @@ -2336,12 +2418,16 @@ public bool TryPickT19(out T19 value, out OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT19; } - public bool TryPickT20(out T20 value, out OneOf remainder) +#if NET + public bool TryPickT20([NotNullWhen(true)] out T20? value, out OneOf remainder) +#else + public bool TryPickT20(out T20? value, out OneOf remainder) +#endif { value = IsT20 ? AsT20 : default; remainder = _index switch @@ -2373,12 +2459,16 @@ public bool TryPickT20(out T20 value, out OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT20; } - public bool TryPickT21(out T21 value, out OneOf remainder) +#if NET + public bool TryPickT21([NotNullWhen(true)] out T21? value, out OneOf remainder) +#else + public bool TryPickT21(out T21? value, out OneOf remainder) +#endif { value = IsT21 ? AsT21 : default; remainder = _index switch @@ -2410,12 +2500,16 @@ public bool TryPickT21(out T21 value, out OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT21; } - public bool TryPickT22(out T22 value, out OneOf remainder) +#if NET + public bool TryPickT22([NotNullWhen(true)] out T22? value, out OneOf remainder) +#else + public bool TryPickT22(out T22? value, out OneOf remainder) +#endif { value = IsT22 ? AsT22 : default; remainder = _index switch @@ -2447,12 +2541,16 @@ public bool TryPickT22(out T22 value, out OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT22; } - public bool TryPickT23(out T23 value, out OneOf remainder) +#if NET + public bool TryPickT23([NotNullWhen(true)] out T23? value, out OneOf remainder) +#else + public bool TryPickT23(out T23? value, out OneOf remainder) +#endif { value = IsT23 ? AsT23 : default; remainder = _index switch @@ -2484,12 +2582,16 @@ public bool TryPickT23(out T23 value, out OneOf AsT24, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT23; } - public bool TryPickT24(out T24 value, out OneOf remainder) +#if NET + public bool TryPickT24([NotNullWhen(true)] out T24? value, out OneOf remainder) +#else + public bool TryPickT24(out T24? value, out OneOf remainder) +#endif { value = IsT24 ? AsT24 : default; remainder = _index switch @@ -2521,12 +2623,16 @@ public bool TryPickT24(out T24 value, out OneOf default, 25 => AsT25, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT24; } - public bool TryPickT25(out T25 value, out OneOf remainder) +#if NET + public bool TryPickT25([NotNullWhen(true)] out T25? value, out OneOf remainder) +#else + public bool TryPickT25(out T25? value, out OneOf remainder) +#endif { value = IsT25 ? AsT25 : default; remainder = _index switch @@ -2558,12 +2664,16 @@ public bool TryPickT25(out T25 value, out OneOf AsT24, 25 => default, 26 => AsT26, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT25; } - public bool TryPickT26(out T26 value, out OneOf remainder) +#if NET + public bool TryPickT26([NotNullWhen(true)] out T26? value, out OneOf remainder) +#else + public bool TryPickT26(out T26? value, out OneOf remainder) +#endif { value = IsT26 ? AsT26 : default; remainder = _index switch @@ -2595,7 +2705,7 @@ public bool TryPickT26(out T26 value, out OneOf AsT24, 25 => AsT25, 26 => default, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT26; } @@ -2634,7 +2744,7 @@ bool Equals(OneOf false }; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/OneOf.Extended/OneOfT27.generated.cs b/OneOf.Extended/OneOfT27.generated.cs index fc45eab..308d5bd 100644 --- a/OneOf.Extended/OneOfT27.generated.cs +++ b/OneOf.Extended/OneOfT27.generated.cs @@ -1,4 +1,6 @@ +#nullable enable using System; +using System.Diagnostics.CodeAnalysis; using static OneOf.Functions; namespace OneOf @@ -35,7 +37,7 @@ namespace OneOf readonly T27 _value27; readonly int _index; - OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default, T10 value10 = default, T11 value11 = default, T12 value12 = default, T13 value13 = default, T14 value14 = default, T15 value15 = default, T16 value16 = default, T17 value17 = default, T18 value18 = default, T19 value19 = default, T20 value20 = default, T21 value21 = default, T22 value22 = default, T23 value23 = default, T24 value24 = default, T25 value25 = default, T26 value26 = default, T27 value27 = default) + OneOf(int index, T0 value0 = default!, T1 value1 = default!, T2 value2 = default!, T3 value3 = default!, T4 value4 = default!, T5 value5 = default!, T6 value6 = default!, T7 value7 = default!, T8 value8 = default!, T9 value9 = default!, T10 value10 = default!, T11 value11 = default!, T12 value12 = default!, T13 value13 = default!, T14 value14 = default!, T15 value15 = default!, T16 value16 = default!, T17 value17 = default!, T18 value18 = default!, T19 value19 = default!, T20 value20 = default!, T21 value21 = default!, T22 value22 = default!, T23 value23 = default!, T24 value24 = default!, T25 value25 = default!, T26 value26 = default!, T27 value27 = default!) { _index = index; _value0 = value0; @@ -68,7 +70,7 @@ namespace OneOf _value27 = value27; } - public object Value => + public object? Value => _index switch { 0 => _value0, @@ -99,7 +101,7 @@ namespace OneOf 25 => _value25, 26 => _value26, 27 => _value27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; public int Index => _index; @@ -417,7 +419,7 @@ public void Switch(Action f0, Action f1, Action f2, Action f3, A f27(_value27); return; } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } public TResult Match(Func f0, Func f1, Func f2, Func f3, Func f4, Func f5, Func f6, Func f7, Func f8, Func f9, Func f10, Func f11, Func f12, Func f13, Func f14, Func f15, Func f16, Func f17, Func f18, Func f19, Func f20, Func f21, Func f22, Func f23, Func f24, Func f25, Func f26, Func f27) @@ -534,7 +536,7 @@ public TResult Match(Func f0, Func f1, Func FromT0(T0 input) => input; @@ -603,7 +605,7 @@ public OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -643,7 +645,7 @@ public OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -683,7 +685,7 @@ public OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -723,7 +725,7 @@ public OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -763,7 +765,7 @@ public OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -803,7 +805,7 @@ public OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -843,7 +845,7 @@ public OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -883,7 +885,7 @@ public OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -923,7 +925,7 @@ public OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -963,7 +965,7 @@ public OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1003,7 +1005,7 @@ public OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1043,7 +1045,7 @@ public OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1083,7 +1085,7 @@ public OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1123,7 +1125,7 @@ public OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1163,7 +1165,7 @@ public OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1203,7 +1205,7 @@ public OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1243,7 +1245,7 @@ public OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1283,7 +1285,7 @@ public OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1323,7 +1325,7 @@ public OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1363,7 +1365,7 @@ public OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1403,7 +1405,7 @@ public OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1443,7 +1445,7 @@ public OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1483,7 +1485,7 @@ public OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1523,7 +1525,7 @@ public OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1563,7 +1565,7 @@ public OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1603,7 +1605,7 @@ public OneOf mapFunc(AsT25), 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1643,7 +1645,7 @@ public OneOf AsT25, 26 => mapFunc(AsT26), 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1683,11 +1685,15 @@ public OneOf AsT25, 26 => AsT26, 27 => mapFunc(AsT27), - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } - public bool TryPickT0(out T0 value, out OneOf remainder) +#if NET + public bool TryPickT0([NotNullWhen(true)] out T0? value, out OneOf remainder) +#else + public bool TryPickT0(out T0? value, out OneOf remainder) +#endif { value = IsT0 ? AsT0 : default; remainder = _index switch @@ -1720,12 +1726,16 @@ public bool TryPickT0(out T0 value, out OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT0; } - public bool TryPickT1(out T1 value, out OneOf remainder) +#if NET + public bool TryPickT1([NotNullWhen(true)] out T1? value, out OneOf remainder) +#else + public bool TryPickT1(out T1? value, out OneOf remainder) +#endif { value = IsT1 ? AsT1 : default; remainder = _index switch @@ -1758,12 +1768,16 @@ public bool TryPickT1(out T1 value, out OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT1; } - public bool TryPickT2(out T2 value, out OneOf remainder) +#if NET + public bool TryPickT2([NotNullWhen(true)] out T2? value, out OneOf remainder) +#else + public bool TryPickT2(out T2? value, out OneOf remainder) +#endif { value = IsT2 ? AsT2 : default; remainder = _index switch @@ -1796,12 +1810,16 @@ public bool TryPickT2(out T2 value, out OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT2; } - public bool TryPickT3(out T3 value, out OneOf remainder) +#if NET + public bool TryPickT3([NotNullWhen(true)] out T3? value, out OneOf remainder) +#else + public bool TryPickT3(out T3? value, out OneOf remainder) +#endif { value = IsT3 ? AsT3 : default; remainder = _index switch @@ -1834,12 +1852,16 @@ public bool TryPickT3(out T3 value, out OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT3; } - public bool TryPickT4(out T4 value, out OneOf remainder) +#if NET + public bool TryPickT4([NotNullWhen(true)] out T4? value, out OneOf remainder) +#else + public bool TryPickT4(out T4? value, out OneOf remainder) +#endif { value = IsT4 ? AsT4 : default; remainder = _index switch @@ -1872,12 +1894,16 @@ public bool TryPickT4(out T4 value, out OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT4; } - public bool TryPickT5(out T5 value, out OneOf remainder) +#if NET + public bool TryPickT5([NotNullWhen(true)] out T5? value, out OneOf remainder) +#else + public bool TryPickT5(out T5? value, out OneOf remainder) +#endif { value = IsT5 ? AsT5 : default; remainder = _index switch @@ -1910,12 +1936,16 @@ public bool TryPickT5(out T5 value, out OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT5; } - public bool TryPickT6(out T6 value, out OneOf remainder) +#if NET + public bool TryPickT6([NotNullWhen(true)] out T6? value, out OneOf remainder) +#else + public bool TryPickT6(out T6? value, out OneOf remainder) +#endif { value = IsT6 ? AsT6 : default; remainder = _index switch @@ -1948,12 +1978,16 @@ public bool TryPickT6(out T6 value, out OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT6; } - public bool TryPickT7(out T7 value, out OneOf remainder) +#if NET + public bool TryPickT7([NotNullWhen(true)] out T7? value, out OneOf remainder) +#else + public bool TryPickT7(out T7? value, out OneOf remainder) +#endif { value = IsT7 ? AsT7 : default; remainder = _index switch @@ -1986,12 +2020,16 @@ public bool TryPickT7(out T7 value, out OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT7; } - public bool TryPickT8(out T8 value, out OneOf remainder) +#if NET + public bool TryPickT8([NotNullWhen(true)] out T8? value, out OneOf remainder) +#else + public bool TryPickT8(out T8? value, out OneOf remainder) +#endif { value = IsT8 ? AsT8 : default; remainder = _index switch @@ -2024,12 +2062,16 @@ public bool TryPickT8(out T8 value, out OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT8; } - public bool TryPickT9(out T9 value, out OneOf remainder) +#if NET + public bool TryPickT9([NotNullWhen(true)] out T9? value, out OneOf remainder) +#else + public bool TryPickT9(out T9? value, out OneOf remainder) +#endif { value = IsT9 ? AsT9 : default; remainder = _index switch @@ -2062,12 +2104,16 @@ public bool TryPickT9(out T9 value, out OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT9; } - public bool TryPickT10(out T10 value, out OneOf remainder) +#if NET + public bool TryPickT10([NotNullWhen(true)] out T10? value, out OneOf remainder) +#else + public bool TryPickT10(out T10? value, out OneOf remainder) +#endif { value = IsT10 ? AsT10 : default; remainder = _index switch @@ -2100,12 +2146,16 @@ public bool TryPickT10(out T10 value, out OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT10; } - public bool TryPickT11(out T11 value, out OneOf remainder) +#if NET + public bool TryPickT11([NotNullWhen(true)] out T11? value, out OneOf remainder) +#else + public bool TryPickT11(out T11? value, out OneOf remainder) +#endif { value = IsT11 ? AsT11 : default; remainder = _index switch @@ -2138,12 +2188,16 @@ public bool TryPickT11(out T11 value, out OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT11; } - public bool TryPickT12(out T12 value, out OneOf remainder) +#if NET + public bool TryPickT12([NotNullWhen(true)] out T12? value, out OneOf remainder) +#else + public bool TryPickT12(out T12? value, out OneOf remainder) +#endif { value = IsT12 ? AsT12 : default; remainder = _index switch @@ -2176,12 +2230,16 @@ public bool TryPickT12(out T12 value, out OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT12; } - public bool TryPickT13(out T13 value, out OneOf remainder) +#if NET + public bool TryPickT13([NotNullWhen(true)] out T13? value, out OneOf remainder) +#else + public bool TryPickT13(out T13? value, out OneOf remainder) +#endif { value = IsT13 ? AsT13 : default; remainder = _index switch @@ -2214,12 +2272,16 @@ public bool TryPickT13(out T13 value, out OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT13; } - public bool TryPickT14(out T14 value, out OneOf remainder) +#if NET + public bool TryPickT14([NotNullWhen(true)] out T14? value, out OneOf remainder) +#else + public bool TryPickT14(out T14? value, out OneOf remainder) +#endif { value = IsT14 ? AsT14 : default; remainder = _index switch @@ -2252,12 +2314,16 @@ public bool TryPickT14(out T14 value, out OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT14; } - public bool TryPickT15(out T15 value, out OneOf remainder) +#if NET + public bool TryPickT15([NotNullWhen(true)] out T15? value, out OneOf remainder) +#else + public bool TryPickT15(out T15? value, out OneOf remainder) +#endif { value = IsT15 ? AsT15 : default; remainder = _index switch @@ -2290,12 +2356,16 @@ public bool TryPickT15(out T15 value, out OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT15; } - public bool TryPickT16(out T16 value, out OneOf remainder) +#if NET + public bool TryPickT16([NotNullWhen(true)] out T16? value, out OneOf remainder) +#else + public bool TryPickT16(out T16? value, out OneOf remainder) +#endif { value = IsT16 ? AsT16 : default; remainder = _index switch @@ -2328,12 +2398,16 @@ public bool TryPickT16(out T16 value, out OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT16; } - public bool TryPickT17(out T17 value, out OneOf remainder) +#if NET + public bool TryPickT17([NotNullWhen(true)] out T17? value, out OneOf remainder) +#else + public bool TryPickT17(out T17? value, out OneOf remainder) +#endif { value = IsT17 ? AsT17 : default; remainder = _index switch @@ -2366,12 +2440,16 @@ public bool TryPickT17(out T17 value, out OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT17; } - public bool TryPickT18(out T18 value, out OneOf remainder) +#if NET + public bool TryPickT18([NotNullWhen(true)] out T18? value, out OneOf remainder) +#else + public bool TryPickT18(out T18? value, out OneOf remainder) +#endif { value = IsT18 ? AsT18 : default; remainder = _index switch @@ -2404,12 +2482,16 @@ public bool TryPickT18(out T18 value, out OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT18; } - public bool TryPickT19(out T19 value, out OneOf remainder) +#if NET + public bool TryPickT19([NotNullWhen(true)] out T19? value, out OneOf remainder) +#else + public bool TryPickT19(out T19? value, out OneOf remainder) +#endif { value = IsT19 ? AsT19 : default; remainder = _index switch @@ -2442,12 +2524,16 @@ public bool TryPickT19(out T19 value, out OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT19; } - public bool TryPickT20(out T20 value, out OneOf remainder) +#if NET + public bool TryPickT20([NotNullWhen(true)] out T20? value, out OneOf remainder) +#else + public bool TryPickT20(out T20? value, out OneOf remainder) +#endif { value = IsT20 ? AsT20 : default; remainder = _index switch @@ -2480,12 +2566,16 @@ public bool TryPickT20(out T20 value, out OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT20; } - public bool TryPickT21(out T21 value, out OneOf remainder) +#if NET + public bool TryPickT21([NotNullWhen(true)] out T21? value, out OneOf remainder) +#else + public bool TryPickT21(out T21? value, out OneOf remainder) +#endif { value = IsT21 ? AsT21 : default; remainder = _index switch @@ -2518,12 +2608,16 @@ public bool TryPickT21(out T21 value, out OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT21; } - public bool TryPickT22(out T22 value, out OneOf remainder) +#if NET + public bool TryPickT22([NotNullWhen(true)] out T22? value, out OneOf remainder) +#else + public bool TryPickT22(out T22? value, out OneOf remainder) +#endif { value = IsT22 ? AsT22 : default; remainder = _index switch @@ -2556,12 +2650,16 @@ public bool TryPickT22(out T22 value, out OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT22; } - public bool TryPickT23(out T23 value, out OneOf remainder) +#if NET + public bool TryPickT23([NotNullWhen(true)] out T23? value, out OneOf remainder) +#else + public bool TryPickT23(out T23? value, out OneOf remainder) +#endif { value = IsT23 ? AsT23 : default; remainder = _index switch @@ -2594,12 +2692,16 @@ public bool TryPickT23(out T23 value, out OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT23; } - public bool TryPickT24(out T24 value, out OneOf remainder) +#if NET + public bool TryPickT24([NotNullWhen(true)] out T24? value, out OneOf remainder) +#else + public bool TryPickT24(out T24? value, out OneOf remainder) +#endif { value = IsT24 ? AsT24 : default; remainder = _index switch @@ -2632,12 +2734,16 @@ public bool TryPickT24(out T24 value, out OneOf AsT25, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT24; } - public bool TryPickT25(out T25 value, out OneOf remainder) +#if NET + public bool TryPickT25([NotNullWhen(true)] out T25? value, out OneOf remainder) +#else + public bool TryPickT25(out T25? value, out OneOf remainder) +#endif { value = IsT25 ? AsT25 : default; remainder = _index switch @@ -2670,12 +2776,16 @@ public bool TryPickT25(out T25 value, out OneOf default, 26 => AsT26, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT25; } - public bool TryPickT26(out T26 value, out OneOf remainder) +#if NET + public bool TryPickT26([NotNullWhen(true)] out T26? value, out OneOf remainder) +#else + public bool TryPickT26(out T26? value, out OneOf remainder) +#endif { value = IsT26 ? AsT26 : default; remainder = _index switch @@ -2708,12 +2818,16 @@ public bool TryPickT26(out T26 value, out OneOf AsT25, 26 => default, 27 => AsT27, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT26; } - public bool TryPickT27(out T27 value, out OneOf remainder) +#if NET + public bool TryPickT27([NotNullWhen(true)] out T27? value, out OneOf remainder) +#else + public bool TryPickT27(out T27? value, out OneOf remainder) +#endif { value = IsT27 ? AsT27 : default; remainder = _index switch @@ -2746,7 +2860,7 @@ public bool TryPickT27(out T27 value, out OneOf AsT25, 26 => AsT26, 27 => default, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT27; } @@ -2786,7 +2900,7 @@ bool Equals(OneOf false }; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/OneOf.Extended/OneOfT28.generated.cs b/OneOf.Extended/OneOfT28.generated.cs index bdaa11f..c7c7db7 100644 --- a/OneOf.Extended/OneOfT28.generated.cs +++ b/OneOf.Extended/OneOfT28.generated.cs @@ -1,4 +1,6 @@ +#nullable enable using System; +using System.Diagnostics.CodeAnalysis; using static OneOf.Functions; namespace OneOf @@ -36,7 +38,7 @@ namespace OneOf readonly T28 _value28; readonly int _index; - OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default, T10 value10 = default, T11 value11 = default, T12 value12 = default, T13 value13 = default, T14 value14 = default, T15 value15 = default, T16 value16 = default, T17 value17 = default, T18 value18 = default, T19 value19 = default, T20 value20 = default, T21 value21 = default, T22 value22 = default, T23 value23 = default, T24 value24 = default, T25 value25 = default, T26 value26 = default, T27 value27 = default, T28 value28 = default) + OneOf(int index, T0 value0 = default!, T1 value1 = default!, T2 value2 = default!, T3 value3 = default!, T4 value4 = default!, T5 value5 = default!, T6 value6 = default!, T7 value7 = default!, T8 value8 = default!, T9 value9 = default!, T10 value10 = default!, T11 value11 = default!, T12 value12 = default!, T13 value13 = default!, T14 value14 = default!, T15 value15 = default!, T16 value16 = default!, T17 value17 = default!, T18 value18 = default!, T19 value19 = default!, T20 value20 = default!, T21 value21 = default!, T22 value22 = default!, T23 value23 = default!, T24 value24 = default!, T25 value25 = default!, T26 value26 = default!, T27 value27 = default!, T28 value28 = default!) { _index = index; _value0 = value0; @@ -70,7 +72,7 @@ namespace OneOf _value28 = value28; } - public object Value => + public object? Value => _index switch { 0 => _value0, @@ -102,7 +104,7 @@ namespace OneOf 26 => _value26, 27 => _value27, 28 => _value28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; public int Index => _index; @@ -431,7 +433,7 @@ public void Switch(Action f0, Action f1, Action f2, Action f3, A f28(_value28); return; } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } public TResult Match(Func f0, Func f1, Func f2, Func f3, Func f4, Func f5, Func f6, Func f7, Func f8, Func f9, Func f10, Func f11, Func f12, Func f13, Func f14, Func f15, Func f16, Func f17, Func f18, Func f19, Func f20, Func f21, Func f22, Func f23, Func f24, Func f25, Func f26, Func f27, Func f28) @@ -552,7 +554,7 @@ public TResult Match(Func f0, Func f1, Func FromT0(T0 input) => input; @@ -623,7 +625,7 @@ public OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -664,7 +666,7 @@ public OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -705,7 +707,7 @@ public OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -746,7 +748,7 @@ public OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -787,7 +789,7 @@ public OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -828,7 +830,7 @@ public OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -869,7 +871,7 @@ public OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -910,7 +912,7 @@ public OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -951,7 +953,7 @@ public OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -992,7 +994,7 @@ public OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1033,7 +1035,7 @@ public OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1074,7 +1076,7 @@ public OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1115,7 +1117,7 @@ public OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1156,7 +1158,7 @@ public OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1197,7 +1199,7 @@ public OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1238,7 +1240,7 @@ public OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1279,7 +1281,7 @@ public OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1320,7 +1322,7 @@ public OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1361,7 +1363,7 @@ public OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1402,7 +1404,7 @@ public OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1443,7 +1445,7 @@ public OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1484,7 +1486,7 @@ public OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1525,7 +1527,7 @@ public OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1566,7 +1568,7 @@ public OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1607,7 +1609,7 @@ public OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1648,7 +1650,7 @@ public OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1689,7 +1691,7 @@ public OneOf mapFunc(AsT26), 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1730,7 +1732,7 @@ public OneOf AsT26, 27 => mapFunc(AsT27), 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1771,11 +1773,15 @@ public OneOf AsT26, 27 => AsT27, 28 => mapFunc(AsT28), - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } - public bool TryPickT0(out T0 value, out OneOf remainder) +#if NET + public bool TryPickT0([NotNullWhen(true)] out T0? value, out OneOf remainder) +#else + public bool TryPickT0(out T0? value, out OneOf remainder) +#endif { value = IsT0 ? AsT0 : default; remainder = _index switch @@ -1809,12 +1815,16 @@ public bool TryPickT0(out T0 value, out OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT0; } - public bool TryPickT1(out T1 value, out OneOf remainder) +#if NET + public bool TryPickT1([NotNullWhen(true)] out T1? value, out OneOf remainder) +#else + public bool TryPickT1(out T1? value, out OneOf remainder) +#endif { value = IsT1 ? AsT1 : default; remainder = _index switch @@ -1848,12 +1858,16 @@ public bool TryPickT1(out T1 value, out OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT1; } - public bool TryPickT2(out T2 value, out OneOf remainder) +#if NET + public bool TryPickT2([NotNullWhen(true)] out T2? value, out OneOf remainder) +#else + public bool TryPickT2(out T2? value, out OneOf remainder) +#endif { value = IsT2 ? AsT2 : default; remainder = _index switch @@ -1887,12 +1901,16 @@ public bool TryPickT2(out T2 value, out OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT2; } - public bool TryPickT3(out T3 value, out OneOf remainder) +#if NET + public bool TryPickT3([NotNullWhen(true)] out T3? value, out OneOf remainder) +#else + public bool TryPickT3(out T3? value, out OneOf remainder) +#endif { value = IsT3 ? AsT3 : default; remainder = _index switch @@ -1926,12 +1944,16 @@ public bool TryPickT3(out T3 value, out OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT3; } - public bool TryPickT4(out T4 value, out OneOf remainder) +#if NET + public bool TryPickT4([NotNullWhen(true)] out T4? value, out OneOf remainder) +#else + public bool TryPickT4(out T4? value, out OneOf remainder) +#endif { value = IsT4 ? AsT4 : default; remainder = _index switch @@ -1965,12 +1987,16 @@ public bool TryPickT4(out T4 value, out OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT4; } - public bool TryPickT5(out T5 value, out OneOf remainder) +#if NET + public bool TryPickT5([NotNullWhen(true)] out T5? value, out OneOf remainder) +#else + public bool TryPickT5(out T5? value, out OneOf remainder) +#endif { value = IsT5 ? AsT5 : default; remainder = _index switch @@ -2004,12 +2030,16 @@ public bool TryPickT5(out T5 value, out OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT5; } - public bool TryPickT6(out T6 value, out OneOf remainder) +#if NET + public bool TryPickT6([NotNullWhen(true)] out T6? value, out OneOf remainder) +#else + public bool TryPickT6(out T6? value, out OneOf remainder) +#endif { value = IsT6 ? AsT6 : default; remainder = _index switch @@ -2043,12 +2073,16 @@ public bool TryPickT6(out T6 value, out OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT6; } - public bool TryPickT7(out T7 value, out OneOf remainder) +#if NET + public bool TryPickT7([NotNullWhen(true)] out T7? value, out OneOf remainder) +#else + public bool TryPickT7(out T7? value, out OneOf remainder) +#endif { value = IsT7 ? AsT7 : default; remainder = _index switch @@ -2082,12 +2116,16 @@ public bool TryPickT7(out T7 value, out OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT7; } - public bool TryPickT8(out T8 value, out OneOf remainder) +#if NET + public bool TryPickT8([NotNullWhen(true)] out T8? value, out OneOf remainder) +#else + public bool TryPickT8(out T8? value, out OneOf remainder) +#endif { value = IsT8 ? AsT8 : default; remainder = _index switch @@ -2121,12 +2159,16 @@ public bool TryPickT8(out T8 value, out OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT8; } - public bool TryPickT9(out T9 value, out OneOf remainder) +#if NET + public bool TryPickT9([NotNullWhen(true)] out T9? value, out OneOf remainder) +#else + public bool TryPickT9(out T9? value, out OneOf remainder) +#endif { value = IsT9 ? AsT9 : default; remainder = _index switch @@ -2160,12 +2202,16 @@ public bool TryPickT9(out T9 value, out OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT9; } - public bool TryPickT10(out T10 value, out OneOf remainder) +#if NET + public bool TryPickT10([NotNullWhen(true)] out T10? value, out OneOf remainder) +#else + public bool TryPickT10(out T10? value, out OneOf remainder) +#endif { value = IsT10 ? AsT10 : default; remainder = _index switch @@ -2199,12 +2245,16 @@ public bool TryPickT10(out T10 value, out OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT10; } - public bool TryPickT11(out T11 value, out OneOf remainder) +#if NET + public bool TryPickT11([NotNullWhen(true)] out T11? value, out OneOf remainder) +#else + public bool TryPickT11(out T11? value, out OneOf remainder) +#endif { value = IsT11 ? AsT11 : default; remainder = _index switch @@ -2238,12 +2288,16 @@ public bool TryPickT11(out T11 value, out OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT11; } - public bool TryPickT12(out T12 value, out OneOf remainder) +#if NET + public bool TryPickT12([NotNullWhen(true)] out T12? value, out OneOf remainder) +#else + public bool TryPickT12(out T12? value, out OneOf remainder) +#endif { value = IsT12 ? AsT12 : default; remainder = _index switch @@ -2277,12 +2331,16 @@ public bool TryPickT12(out T12 value, out OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT12; } - public bool TryPickT13(out T13 value, out OneOf remainder) +#if NET + public bool TryPickT13([NotNullWhen(true)] out T13? value, out OneOf remainder) +#else + public bool TryPickT13(out T13? value, out OneOf remainder) +#endif { value = IsT13 ? AsT13 : default; remainder = _index switch @@ -2316,12 +2374,16 @@ public bool TryPickT13(out T13 value, out OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT13; } - public bool TryPickT14(out T14 value, out OneOf remainder) +#if NET + public bool TryPickT14([NotNullWhen(true)] out T14? value, out OneOf remainder) +#else + public bool TryPickT14(out T14? value, out OneOf remainder) +#endif { value = IsT14 ? AsT14 : default; remainder = _index switch @@ -2355,12 +2417,16 @@ public bool TryPickT14(out T14 value, out OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT14; } - public bool TryPickT15(out T15 value, out OneOf remainder) +#if NET + public bool TryPickT15([NotNullWhen(true)] out T15? value, out OneOf remainder) +#else + public bool TryPickT15(out T15? value, out OneOf remainder) +#endif { value = IsT15 ? AsT15 : default; remainder = _index switch @@ -2394,12 +2460,16 @@ public bool TryPickT15(out T15 value, out OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT15; } - public bool TryPickT16(out T16 value, out OneOf remainder) +#if NET + public bool TryPickT16([NotNullWhen(true)] out T16? value, out OneOf remainder) +#else + public bool TryPickT16(out T16? value, out OneOf remainder) +#endif { value = IsT16 ? AsT16 : default; remainder = _index switch @@ -2433,12 +2503,16 @@ public bool TryPickT16(out T16 value, out OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT16; } - public bool TryPickT17(out T17 value, out OneOf remainder) +#if NET + public bool TryPickT17([NotNullWhen(true)] out T17? value, out OneOf remainder) +#else + public bool TryPickT17(out T17? value, out OneOf remainder) +#endif { value = IsT17 ? AsT17 : default; remainder = _index switch @@ -2472,12 +2546,16 @@ public bool TryPickT17(out T17 value, out OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT17; } - public bool TryPickT18(out T18 value, out OneOf remainder) +#if NET + public bool TryPickT18([NotNullWhen(true)] out T18? value, out OneOf remainder) +#else + public bool TryPickT18(out T18? value, out OneOf remainder) +#endif { value = IsT18 ? AsT18 : default; remainder = _index switch @@ -2511,12 +2589,16 @@ public bool TryPickT18(out T18 value, out OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT18; } - public bool TryPickT19(out T19 value, out OneOf remainder) +#if NET + public bool TryPickT19([NotNullWhen(true)] out T19? value, out OneOf remainder) +#else + public bool TryPickT19(out T19? value, out OneOf remainder) +#endif { value = IsT19 ? AsT19 : default; remainder = _index switch @@ -2550,12 +2632,16 @@ public bool TryPickT19(out T19 value, out OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT19; } - public bool TryPickT20(out T20 value, out OneOf remainder) +#if NET + public bool TryPickT20([NotNullWhen(true)] out T20? value, out OneOf remainder) +#else + public bool TryPickT20(out T20? value, out OneOf remainder) +#endif { value = IsT20 ? AsT20 : default; remainder = _index switch @@ -2589,12 +2675,16 @@ public bool TryPickT20(out T20 value, out OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT20; } - public bool TryPickT21(out T21 value, out OneOf remainder) +#if NET + public bool TryPickT21([NotNullWhen(true)] out T21? value, out OneOf remainder) +#else + public bool TryPickT21(out T21? value, out OneOf remainder) +#endif { value = IsT21 ? AsT21 : default; remainder = _index switch @@ -2628,12 +2718,16 @@ public bool TryPickT21(out T21 value, out OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT21; } - public bool TryPickT22(out T22 value, out OneOf remainder) +#if NET + public bool TryPickT22([NotNullWhen(true)] out T22? value, out OneOf remainder) +#else + public bool TryPickT22(out T22? value, out OneOf remainder) +#endif { value = IsT22 ? AsT22 : default; remainder = _index switch @@ -2667,12 +2761,16 @@ public bool TryPickT22(out T22 value, out OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT22; } - public bool TryPickT23(out T23 value, out OneOf remainder) +#if NET + public bool TryPickT23([NotNullWhen(true)] out T23? value, out OneOf remainder) +#else + public bool TryPickT23(out T23? value, out OneOf remainder) +#endif { value = IsT23 ? AsT23 : default; remainder = _index switch @@ -2706,12 +2804,16 @@ public bool TryPickT23(out T23 value, out OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT23; } - public bool TryPickT24(out T24 value, out OneOf remainder) +#if NET + public bool TryPickT24([NotNullWhen(true)] out T24? value, out OneOf remainder) +#else + public bool TryPickT24(out T24? value, out OneOf remainder) +#endif { value = IsT24 ? AsT24 : default; remainder = _index switch @@ -2745,12 +2847,16 @@ public bool TryPickT24(out T24 value, out OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT24; } - public bool TryPickT25(out T25 value, out OneOf remainder) +#if NET + public bool TryPickT25([NotNullWhen(true)] out T25? value, out OneOf remainder) +#else + public bool TryPickT25(out T25? value, out OneOf remainder) +#endif { value = IsT25 ? AsT25 : default; remainder = _index switch @@ -2784,12 +2890,16 @@ public bool TryPickT25(out T25 value, out OneOf AsT26, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT25; } - public bool TryPickT26(out T26 value, out OneOf remainder) +#if NET + public bool TryPickT26([NotNullWhen(true)] out T26? value, out OneOf remainder) +#else + public bool TryPickT26(out T26? value, out OneOf remainder) +#endif { value = IsT26 ? AsT26 : default; remainder = _index switch @@ -2823,12 +2933,16 @@ public bool TryPickT26(out T26 value, out OneOf default, 27 => AsT27, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT26; } - public bool TryPickT27(out T27 value, out OneOf remainder) +#if NET + public bool TryPickT27([NotNullWhen(true)] out T27? value, out OneOf remainder) +#else + public bool TryPickT27(out T27? value, out OneOf remainder) +#endif { value = IsT27 ? AsT27 : default; remainder = _index switch @@ -2862,12 +2976,16 @@ public bool TryPickT27(out T27 value, out OneOf AsT26, 27 => default, 28 => AsT28, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT27; } - public bool TryPickT28(out T28 value, out OneOf remainder) +#if NET + public bool TryPickT28([NotNullWhen(true)] out T28? value, out OneOf remainder) +#else + public bool TryPickT28(out T28? value, out OneOf remainder) +#endif { value = IsT28 ? AsT28 : default; remainder = _index switch @@ -2901,7 +3019,7 @@ public bool TryPickT28(out T28 value, out OneOf AsT26, 27 => AsT27, 28 => default, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT28; } @@ -2942,7 +3060,7 @@ bool Equals(OneOf false }; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/OneOf.Extended/OneOfT29.generated.cs b/OneOf.Extended/OneOfT29.generated.cs index 74ec58e..74f4e9f 100644 --- a/OneOf.Extended/OneOfT29.generated.cs +++ b/OneOf.Extended/OneOfT29.generated.cs @@ -1,4 +1,6 @@ +#nullable enable using System; +using System.Diagnostics.CodeAnalysis; using static OneOf.Functions; namespace OneOf @@ -37,7 +39,7 @@ namespace OneOf readonly T29 _value29; readonly int _index; - OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default, T10 value10 = default, T11 value11 = default, T12 value12 = default, T13 value13 = default, T14 value14 = default, T15 value15 = default, T16 value16 = default, T17 value17 = default, T18 value18 = default, T19 value19 = default, T20 value20 = default, T21 value21 = default, T22 value22 = default, T23 value23 = default, T24 value24 = default, T25 value25 = default, T26 value26 = default, T27 value27 = default, T28 value28 = default, T29 value29 = default) + OneOf(int index, T0 value0 = default!, T1 value1 = default!, T2 value2 = default!, T3 value3 = default!, T4 value4 = default!, T5 value5 = default!, T6 value6 = default!, T7 value7 = default!, T8 value8 = default!, T9 value9 = default!, T10 value10 = default!, T11 value11 = default!, T12 value12 = default!, T13 value13 = default!, T14 value14 = default!, T15 value15 = default!, T16 value16 = default!, T17 value17 = default!, T18 value18 = default!, T19 value19 = default!, T20 value20 = default!, T21 value21 = default!, T22 value22 = default!, T23 value23 = default!, T24 value24 = default!, T25 value25 = default!, T26 value26 = default!, T27 value27 = default!, T28 value28 = default!, T29 value29 = default!) { _index = index; _value0 = value0; @@ -72,7 +74,7 @@ namespace OneOf _value29 = value29; } - public object Value => + public object? Value => _index switch { 0 => _value0, @@ -105,7 +107,7 @@ namespace OneOf 27 => _value27, 28 => _value28, 29 => _value29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; public int Index => _index; @@ -445,7 +447,7 @@ public void Switch(Action f0, Action f1, Action f2, Action f3, A f29(_value29); return; } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } public TResult Match(Func f0, Func f1, Func f2, Func f3, Func f4, Func f5, Func f6, Func f7, Func f8, Func f9, Func f10, Func f11, Func f12, Func f13, Func f14, Func f15, Func f16, Func f17, Func f18, Func f19, Func f20, Func f21, Func f22, Func f23, Func f24, Func f25, Func f26, Func f27, Func f28, Func f29) @@ -570,7 +572,7 @@ public TResult Match(Func f0, Func f1, Func FromT0(T0 input) => input; @@ -643,7 +645,7 @@ public OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -685,7 +687,7 @@ public OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -727,7 +729,7 @@ public OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -769,7 +771,7 @@ public OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -811,7 +813,7 @@ public OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -853,7 +855,7 @@ public OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -895,7 +897,7 @@ public OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -937,7 +939,7 @@ public OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -979,7 +981,7 @@ public OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1021,7 +1023,7 @@ public OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1063,7 +1065,7 @@ public OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1105,7 +1107,7 @@ public OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1147,7 +1149,7 @@ public OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1189,7 +1191,7 @@ public OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1231,7 +1233,7 @@ public OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1273,7 +1275,7 @@ public OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1315,7 +1317,7 @@ public OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1357,7 +1359,7 @@ public OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1399,7 +1401,7 @@ public OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1441,7 +1443,7 @@ public OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1483,7 +1485,7 @@ public OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1525,7 +1527,7 @@ public OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1567,7 +1569,7 @@ public OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1609,7 +1611,7 @@ public OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1651,7 +1653,7 @@ public OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1693,7 +1695,7 @@ public OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1735,7 +1737,7 @@ public OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1777,7 +1779,7 @@ public OneOf mapFunc(AsT27), 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1819,7 +1821,7 @@ public OneOf AsT27, 28 => mapFunc(AsT28), 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1861,11 +1863,15 @@ public OneOf AsT27, 28 => AsT28, 29 => mapFunc(AsT29), - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } - public bool TryPickT0(out T0 value, out OneOf remainder) +#if NET + public bool TryPickT0([NotNullWhen(true)] out T0? value, out OneOf remainder) +#else + public bool TryPickT0(out T0? value, out OneOf remainder) +#endif { value = IsT0 ? AsT0 : default; remainder = _index switch @@ -1900,12 +1906,16 @@ public bool TryPickT0(out T0 value, out OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT0; } - public bool TryPickT1(out T1 value, out OneOf remainder) +#if NET + public bool TryPickT1([NotNullWhen(true)] out T1? value, out OneOf remainder) +#else + public bool TryPickT1(out T1? value, out OneOf remainder) +#endif { value = IsT1 ? AsT1 : default; remainder = _index switch @@ -1940,12 +1950,16 @@ public bool TryPickT1(out T1 value, out OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT1; } - public bool TryPickT2(out T2 value, out OneOf remainder) +#if NET + public bool TryPickT2([NotNullWhen(true)] out T2? value, out OneOf remainder) +#else + public bool TryPickT2(out T2? value, out OneOf remainder) +#endif { value = IsT2 ? AsT2 : default; remainder = _index switch @@ -1980,12 +1994,16 @@ public bool TryPickT2(out T2 value, out OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT2; } - public bool TryPickT3(out T3 value, out OneOf remainder) +#if NET + public bool TryPickT3([NotNullWhen(true)] out T3? value, out OneOf remainder) +#else + public bool TryPickT3(out T3? value, out OneOf remainder) +#endif { value = IsT3 ? AsT3 : default; remainder = _index switch @@ -2020,12 +2038,16 @@ public bool TryPickT3(out T3 value, out OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT3; } - public bool TryPickT4(out T4 value, out OneOf remainder) +#if NET + public bool TryPickT4([NotNullWhen(true)] out T4? value, out OneOf remainder) +#else + public bool TryPickT4(out T4? value, out OneOf remainder) +#endif { value = IsT4 ? AsT4 : default; remainder = _index switch @@ -2060,12 +2082,16 @@ public bool TryPickT4(out T4 value, out OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT4; } - public bool TryPickT5(out T5 value, out OneOf remainder) +#if NET + public bool TryPickT5([NotNullWhen(true)] out T5? value, out OneOf remainder) +#else + public bool TryPickT5(out T5? value, out OneOf remainder) +#endif { value = IsT5 ? AsT5 : default; remainder = _index switch @@ -2100,12 +2126,16 @@ public bool TryPickT5(out T5 value, out OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT5; } - public bool TryPickT6(out T6 value, out OneOf remainder) +#if NET + public bool TryPickT6([NotNullWhen(true)] out T6? value, out OneOf remainder) +#else + public bool TryPickT6(out T6? value, out OneOf remainder) +#endif { value = IsT6 ? AsT6 : default; remainder = _index switch @@ -2140,12 +2170,16 @@ public bool TryPickT6(out T6 value, out OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT6; } - public bool TryPickT7(out T7 value, out OneOf remainder) +#if NET + public bool TryPickT7([NotNullWhen(true)] out T7? value, out OneOf remainder) +#else + public bool TryPickT7(out T7? value, out OneOf remainder) +#endif { value = IsT7 ? AsT7 : default; remainder = _index switch @@ -2180,12 +2214,16 @@ public bool TryPickT7(out T7 value, out OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT7; } - public bool TryPickT8(out T8 value, out OneOf remainder) +#if NET + public bool TryPickT8([NotNullWhen(true)] out T8? value, out OneOf remainder) +#else + public bool TryPickT8(out T8? value, out OneOf remainder) +#endif { value = IsT8 ? AsT8 : default; remainder = _index switch @@ -2220,12 +2258,16 @@ public bool TryPickT8(out T8 value, out OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT8; } - public bool TryPickT9(out T9 value, out OneOf remainder) +#if NET + public bool TryPickT9([NotNullWhen(true)] out T9? value, out OneOf remainder) +#else + public bool TryPickT9(out T9? value, out OneOf remainder) +#endif { value = IsT9 ? AsT9 : default; remainder = _index switch @@ -2260,12 +2302,16 @@ public bool TryPickT9(out T9 value, out OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT9; } - public bool TryPickT10(out T10 value, out OneOf remainder) +#if NET + public bool TryPickT10([NotNullWhen(true)] out T10? value, out OneOf remainder) +#else + public bool TryPickT10(out T10? value, out OneOf remainder) +#endif { value = IsT10 ? AsT10 : default; remainder = _index switch @@ -2300,12 +2346,16 @@ public bool TryPickT10(out T10 value, out OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT10; } - public bool TryPickT11(out T11 value, out OneOf remainder) +#if NET + public bool TryPickT11([NotNullWhen(true)] out T11? value, out OneOf remainder) +#else + public bool TryPickT11(out T11? value, out OneOf remainder) +#endif { value = IsT11 ? AsT11 : default; remainder = _index switch @@ -2340,12 +2390,16 @@ public bool TryPickT11(out T11 value, out OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT11; } - public bool TryPickT12(out T12 value, out OneOf remainder) +#if NET + public bool TryPickT12([NotNullWhen(true)] out T12? value, out OneOf remainder) +#else + public bool TryPickT12(out T12? value, out OneOf remainder) +#endif { value = IsT12 ? AsT12 : default; remainder = _index switch @@ -2380,12 +2434,16 @@ public bool TryPickT12(out T12 value, out OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT12; } - public bool TryPickT13(out T13 value, out OneOf remainder) +#if NET + public bool TryPickT13([NotNullWhen(true)] out T13? value, out OneOf remainder) +#else + public bool TryPickT13(out T13? value, out OneOf remainder) +#endif { value = IsT13 ? AsT13 : default; remainder = _index switch @@ -2420,12 +2478,16 @@ public bool TryPickT13(out T13 value, out OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT13; } - public bool TryPickT14(out T14 value, out OneOf remainder) +#if NET + public bool TryPickT14([NotNullWhen(true)] out T14? value, out OneOf remainder) +#else + public bool TryPickT14(out T14? value, out OneOf remainder) +#endif { value = IsT14 ? AsT14 : default; remainder = _index switch @@ -2460,12 +2522,16 @@ public bool TryPickT14(out T14 value, out OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT14; } - public bool TryPickT15(out T15 value, out OneOf remainder) +#if NET + public bool TryPickT15([NotNullWhen(true)] out T15? value, out OneOf remainder) +#else + public bool TryPickT15(out T15? value, out OneOf remainder) +#endif { value = IsT15 ? AsT15 : default; remainder = _index switch @@ -2500,12 +2566,16 @@ public bool TryPickT15(out T15 value, out OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT15; } - public bool TryPickT16(out T16 value, out OneOf remainder) +#if NET + public bool TryPickT16([NotNullWhen(true)] out T16? value, out OneOf remainder) +#else + public bool TryPickT16(out T16? value, out OneOf remainder) +#endif { value = IsT16 ? AsT16 : default; remainder = _index switch @@ -2540,12 +2610,16 @@ public bool TryPickT16(out T16 value, out OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT16; } - public bool TryPickT17(out T17 value, out OneOf remainder) +#if NET + public bool TryPickT17([NotNullWhen(true)] out T17? value, out OneOf remainder) +#else + public bool TryPickT17(out T17? value, out OneOf remainder) +#endif { value = IsT17 ? AsT17 : default; remainder = _index switch @@ -2580,12 +2654,16 @@ public bool TryPickT17(out T17 value, out OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT17; } - public bool TryPickT18(out T18 value, out OneOf remainder) +#if NET + public bool TryPickT18([NotNullWhen(true)] out T18? value, out OneOf remainder) +#else + public bool TryPickT18(out T18? value, out OneOf remainder) +#endif { value = IsT18 ? AsT18 : default; remainder = _index switch @@ -2620,12 +2698,16 @@ public bool TryPickT18(out T18 value, out OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT18; } - public bool TryPickT19(out T19 value, out OneOf remainder) +#if NET + public bool TryPickT19([NotNullWhen(true)] out T19? value, out OneOf remainder) +#else + public bool TryPickT19(out T19? value, out OneOf remainder) +#endif { value = IsT19 ? AsT19 : default; remainder = _index switch @@ -2660,12 +2742,16 @@ public bool TryPickT19(out T19 value, out OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT19; } - public bool TryPickT20(out T20 value, out OneOf remainder) +#if NET + public bool TryPickT20([NotNullWhen(true)] out T20? value, out OneOf remainder) +#else + public bool TryPickT20(out T20? value, out OneOf remainder) +#endif { value = IsT20 ? AsT20 : default; remainder = _index switch @@ -2700,12 +2786,16 @@ public bool TryPickT20(out T20 value, out OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT20; } - public bool TryPickT21(out T21 value, out OneOf remainder) +#if NET + public bool TryPickT21([NotNullWhen(true)] out T21? value, out OneOf remainder) +#else + public bool TryPickT21(out T21? value, out OneOf remainder) +#endif { value = IsT21 ? AsT21 : default; remainder = _index switch @@ -2740,12 +2830,16 @@ public bool TryPickT21(out T21 value, out OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT21; } - public bool TryPickT22(out T22 value, out OneOf remainder) +#if NET + public bool TryPickT22([NotNullWhen(true)] out T22? value, out OneOf remainder) +#else + public bool TryPickT22(out T22? value, out OneOf remainder) +#endif { value = IsT22 ? AsT22 : default; remainder = _index switch @@ -2780,12 +2874,16 @@ public bool TryPickT22(out T22 value, out OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT22; } - public bool TryPickT23(out T23 value, out OneOf remainder) +#if NET + public bool TryPickT23([NotNullWhen(true)] out T23? value, out OneOf remainder) +#else + public bool TryPickT23(out T23? value, out OneOf remainder) +#endif { value = IsT23 ? AsT23 : default; remainder = _index switch @@ -2820,12 +2918,16 @@ public bool TryPickT23(out T23 value, out OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT23; } - public bool TryPickT24(out T24 value, out OneOf remainder) +#if NET + public bool TryPickT24([NotNullWhen(true)] out T24? value, out OneOf remainder) +#else + public bool TryPickT24(out T24? value, out OneOf remainder) +#endif { value = IsT24 ? AsT24 : default; remainder = _index switch @@ -2860,12 +2962,16 @@ public bool TryPickT24(out T24 value, out OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT24; } - public bool TryPickT25(out T25 value, out OneOf remainder) +#if NET + public bool TryPickT25([NotNullWhen(true)] out T25? value, out OneOf remainder) +#else + public bool TryPickT25(out T25? value, out OneOf remainder) +#endif { value = IsT25 ? AsT25 : default; remainder = _index switch @@ -2900,12 +3006,16 @@ public bool TryPickT25(out T25 value, out OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT25; } - public bool TryPickT26(out T26 value, out OneOf remainder) +#if NET + public bool TryPickT26([NotNullWhen(true)] out T26? value, out OneOf remainder) +#else + public bool TryPickT26(out T26? value, out OneOf remainder) +#endif { value = IsT26 ? AsT26 : default; remainder = _index switch @@ -2940,12 +3050,16 @@ public bool TryPickT26(out T26 value, out OneOf AsT27, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT26; } - public bool TryPickT27(out T27 value, out OneOf remainder) +#if NET + public bool TryPickT27([NotNullWhen(true)] out T27? value, out OneOf remainder) +#else + public bool TryPickT27(out T27? value, out OneOf remainder) +#endif { value = IsT27 ? AsT27 : default; remainder = _index switch @@ -2980,12 +3094,16 @@ public bool TryPickT27(out T27 value, out OneOf default, 28 => AsT28, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT27; } - public bool TryPickT28(out T28 value, out OneOf remainder) +#if NET + public bool TryPickT28([NotNullWhen(true)] out T28? value, out OneOf remainder) +#else + public bool TryPickT28(out T28? value, out OneOf remainder) +#endif { value = IsT28 ? AsT28 : default; remainder = _index switch @@ -3020,12 +3138,16 @@ public bool TryPickT28(out T28 value, out OneOf AsT27, 28 => default, 29 => AsT29, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT28; } - public bool TryPickT29(out T29 value, out OneOf remainder) +#if NET + public bool TryPickT29([NotNullWhen(true)] out T29? value, out OneOf remainder) +#else + public bool TryPickT29(out T29? value, out OneOf remainder) +#endif { value = IsT29 ? AsT29 : default; remainder = _index switch @@ -3060,7 +3182,7 @@ public bool TryPickT29(out T29 value, out OneOf AsT27, 28 => AsT28, 29 => default, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT29; } @@ -3102,7 +3224,7 @@ bool Equals(OneOf false }; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/OneOf.Extended/OneOfT30.generated.cs b/OneOf.Extended/OneOfT30.generated.cs index 5c6e763..958072a 100644 --- a/OneOf.Extended/OneOfT30.generated.cs +++ b/OneOf.Extended/OneOfT30.generated.cs @@ -1,4 +1,6 @@ +#nullable enable using System; +using System.Diagnostics.CodeAnalysis; using static OneOf.Functions; namespace OneOf @@ -38,7 +40,7 @@ namespace OneOf readonly T30 _value30; readonly int _index; - OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default, T10 value10 = default, T11 value11 = default, T12 value12 = default, T13 value13 = default, T14 value14 = default, T15 value15 = default, T16 value16 = default, T17 value17 = default, T18 value18 = default, T19 value19 = default, T20 value20 = default, T21 value21 = default, T22 value22 = default, T23 value23 = default, T24 value24 = default, T25 value25 = default, T26 value26 = default, T27 value27 = default, T28 value28 = default, T29 value29 = default, T30 value30 = default) + OneOf(int index, T0 value0 = default!, T1 value1 = default!, T2 value2 = default!, T3 value3 = default!, T4 value4 = default!, T5 value5 = default!, T6 value6 = default!, T7 value7 = default!, T8 value8 = default!, T9 value9 = default!, T10 value10 = default!, T11 value11 = default!, T12 value12 = default!, T13 value13 = default!, T14 value14 = default!, T15 value15 = default!, T16 value16 = default!, T17 value17 = default!, T18 value18 = default!, T19 value19 = default!, T20 value20 = default!, T21 value21 = default!, T22 value22 = default!, T23 value23 = default!, T24 value24 = default!, T25 value25 = default!, T26 value26 = default!, T27 value27 = default!, T28 value28 = default!, T29 value29 = default!, T30 value30 = default!) { _index = index; _value0 = value0; @@ -74,7 +76,7 @@ namespace OneOf _value30 = value30; } - public object Value => + public object? Value => _index switch { 0 => _value0, @@ -108,7 +110,7 @@ namespace OneOf 28 => _value28, 29 => _value29, 30 => _value30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; public int Index => _index; @@ -459,7 +461,7 @@ public void Switch(Action f0, Action f1, Action f2, Action f3, A f30(_value30); return; } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } public TResult Match(Func f0, Func f1, Func f2, Func f3, Func f4, Func f5, Func f6, Func f7, Func f8, Func f9, Func f10, Func f11, Func f12, Func f13, Func f14, Func f15, Func f16, Func f17, Func f18, Func f19, Func f20, Func f21, Func f22, Func f23, Func f24, Func f25, Func f26, Func f27, Func f28, Func f29, Func f30) @@ -588,7 +590,7 @@ public TResult Match(Func f0, Func f1, Func FromT0(T0 input) => input; @@ -663,7 +665,7 @@ public OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -706,7 +708,7 @@ public OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -749,7 +751,7 @@ public OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -792,7 +794,7 @@ public OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -835,7 +837,7 @@ public OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -878,7 +880,7 @@ public OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -921,7 +923,7 @@ public OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -964,7 +966,7 @@ public OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1007,7 +1009,7 @@ public OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1050,7 +1052,7 @@ public OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1093,7 +1095,7 @@ public OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1136,7 +1138,7 @@ public OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1179,7 +1181,7 @@ public OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1222,7 +1224,7 @@ public OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1265,7 +1267,7 @@ public OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1308,7 +1310,7 @@ public OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1351,7 +1353,7 @@ public OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1394,7 +1396,7 @@ public OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1437,7 +1439,7 @@ public OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1480,7 +1482,7 @@ public OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1523,7 +1525,7 @@ public OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1566,7 +1568,7 @@ public OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1609,7 +1611,7 @@ public OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1652,7 +1654,7 @@ public OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1695,7 +1697,7 @@ public OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1738,7 +1740,7 @@ public OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1781,7 +1783,7 @@ public OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1824,7 +1826,7 @@ public OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1867,7 +1869,7 @@ public OneOf mapFunc(AsT28), 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1910,7 +1912,7 @@ public OneOf AsT28, 29 => mapFunc(AsT29), 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1953,11 +1955,15 @@ public OneOf AsT28, 29 => AsT29, 30 => mapFunc(AsT30), - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } - public bool TryPickT0(out T0 value, out OneOf remainder) +#if NET + public bool TryPickT0([NotNullWhen(true)] out T0? value, out OneOf remainder) +#else + public bool TryPickT0(out T0? value, out OneOf remainder) +#endif { value = IsT0 ? AsT0 : default; remainder = _index switch @@ -1993,12 +1999,16 @@ public bool TryPickT0(out T0 value, out OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT0; } - public bool TryPickT1(out T1 value, out OneOf remainder) +#if NET + public bool TryPickT1([NotNullWhen(true)] out T1? value, out OneOf remainder) +#else + public bool TryPickT1(out T1? value, out OneOf remainder) +#endif { value = IsT1 ? AsT1 : default; remainder = _index switch @@ -2034,12 +2044,16 @@ public bool TryPickT1(out T1 value, out OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT1; } - public bool TryPickT2(out T2 value, out OneOf remainder) +#if NET + public bool TryPickT2([NotNullWhen(true)] out T2? value, out OneOf remainder) +#else + public bool TryPickT2(out T2? value, out OneOf remainder) +#endif { value = IsT2 ? AsT2 : default; remainder = _index switch @@ -2075,12 +2089,16 @@ public bool TryPickT2(out T2 value, out OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT2; } - public bool TryPickT3(out T3 value, out OneOf remainder) +#if NET + public bool TryPickT3([NotNullWhen(true)] out T3? value, out OneOf remainder) +#else + public bool TryPickT3(out T3? value, out OneOf remainder) +#endif { value = IsT3 ? AsT3 : default; remainder = _index switch @@ -2116,12 +2134,16 @@ public bool TryPickT3(out T3 value, out OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT3; } - public bool TryPickT4(out T4 value, out OneOf remainder) +#if NET + public bool TryPickT4([NotNullWhen(true)] out T4? value, out OneOf remainder) +#else + public bool TryPickT4(out T4? value, out OneOf remainder) +#endif { value = IsT4 ? AsT4 : default; remainder = _index switch @@ -2157,12 +2179,16 @@ public bool TryPickT4(out T4 value, out OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT4; } - public bool TryPickT5(out T5 value, out OneOf remainder) +#if NET + public bool TryPickT5([NotNullWhen(true)] out T5? value, out OneOf remainder) +#else + public bool TryPickT5(out T5? value, out OneOf remainder) +#endif { value = IsT5 ? AsT5 : default; remainder = _index switch @@ -2198,12 +2224,16 @@ public bool TryPickT5(out T5 value, out OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT5; } - public bool TryPickT6(out T6 value, out OneOf remainder) +#if NET + public bool TryPickT6([NotNullWhen(true)] out T6? value, out OneOf remainder) +#else + public bool TryPickT6(out T6? value, out OneOf remainder) +#endif { value = IsT6 ? AsT6 : default; remainder = _index switch @@ -2239,12 +2269,16 @@ public bool TryPickT6(out T6 value, out OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT6; } - public bool TryPickT7(out T7 value, out OneOf remainder) +#if NET + public bool TryPickT7([NotNullWhen(true)] out T7? value, out OneOf remainder) +#else + public bool TryPickT7(out T7? value, out OneOf remainder) +#endif { value = IsT7 ? AsT7 : default; remainder = _index switch @@ -2280,12 +2314,16 @@ public bool TryPickT7(out T7 value, out OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT7; } - public bool TryPickT8(out T8 value, out OneOf remainder) +#if NET + public bool TryPickT8([NotNullWhen(true)] out T8? value, out OneOf remainder) +#else + public bool TryPickT8(out T8? value, out OneOf remainder) +#endif { value = IsT8 ? AsT8 : default; remainder = _index switch @@ -2321,12 +2359,16 @@ public bool TryPickT8(out T8 value, out OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT8; } - public bool TryPickT9(out T9 value, out OneOf remainder) +#if NET + public bool TryPickT9([NotNullWhen(true)] out T9? value, out OneOf remainder) +#else + public bool TryPickT9(out T9? value, out OneOf remainder) +#endif { value = IsT9 ? AsT9 : default; remainder = _index switch @@ -2362,12 +2404,16 @@ public bool TryPickT9(out T9 value, out OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT9; } - public bool TryPickT10(out T10 value, out OneOf remainder) +#if NET + public bool TryPickT10([NotNullWhen(true)] out T10? value, out OneOf remainder) +#else + public bool TryPickT10(out T10? value, out OneOf remainder) +#endif { value = IsT10 ? AsT10 : default; remainder = _index switch @@ -2403,12 +2449,16 @@ public bool TryPickT10(out T10 value, out OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT10; } - public bool TryPickT11(out T11 value, out OneOf remainder) +#if NET + public bool TryPickT11([NotNullWhen(true)] out T11? value, out OneOf remainder) +#else + public bool TryPickT11(out T11? value, out OneOf remainder) +#endif { value = IsT11 ? AsT11 : default; remainder = _index switch @@ -2444,12 +2494,16 @@ public bool TryPickT11(out T11 value, out OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT11; } - public bool TryPickT12(out T12 value, out OneOf remainder) +#if NET + public bool TryPickT12([NotNullWhen(true)] out T12? value, out OneOf remainder) +#else + public bool TryPickT12(out T12? value, out OneOf remainder) +#endif { value = IsT12 ? AsT12 : default; remainder = _index switch @@ -2485,12 +2539,16 @@ public bool TryPickT12(out T12 value, out OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT12; } - public bool TryPickT13(out T13 value, out OneOf remainder) +#if NET + public bool TryPickT13([NotNullWhen(true)] out T13? value, out OneOf remainder) +#else + public bool TryPickT13(out T13? value, out OneOf remainder) +#endif { value = IsT13 ? AsT13 : default; remainder = _index switch @@ -2526,12 +2584,16 @@ public bool TryPickT13(out T13 value, out OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT13; } - public bool TryPickT14(out T14 value, out OneOf remainder) +#if NET + public bool TryPickT14([NotNullWhen(true)] out T14? value, out OneOf remainder) +#else + public bool TryPickT14(out T14? value, out OneOf remainder) +#endif { value = IsT14 ? AsT14 : default; remainder = _index switch @@ -2567,12 +2629,16 @@ public bool TryPickT14(out T14 value, out OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT14; } - public bool TryPickT15(out T15 value, out OneOf remainder) +#if NET + public bool TryPickT15([NotNullWhen(true)] out T15? value, out OneOf remainder) +#else + public bool TryPickT15(out T15? value, out OneOf remainder) +#endif { value = IsT15 ? AsT15 : default; remainder = _index switch @@ -2608,12 +2674,16 @@ public bool TryPickT15(out T15 value, out OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT15; } - public bool TryPickT16(out T16 value, out OneOf remainder) +#if NET + public bool TryPickT16([NotNullWhen(true)] out T16? value, out OneOf remainder) +#else + public bool TryPickT16(out T16? value, out OneOf remainder) +#endif { value = IsT16 ? AsT16 : default; remainder = _index switch @@ -2649,12 +2719,16 @@ public bool TryPickT16(out T16 value, out OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT16; } - public bool TryPickT17(out T17 value, out OneOf remainder) +#if NET + public bool TryPickT17([NotNullWhen(true)] out T17? value, out OneOf remainder) +#else + public bool TryPickT17(out T17? value, out OneOf remainder) +#endif { value = IsT17 ? AsT17 : default; remainder = _index switch @@ -2690,12 +2764,16 @@ public bool TryPickT17(out T17 value, out OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT17; } - public bool TryPickT18(out T18 value, out OneOf remainder) +#if NET + public bool TryPickT18([NotNullWhen(true)] out T18? value, out OneOf remainder) +#else + public bool TryPickT18(out T18? value, out OneOf remainder) +#endif { value = IsT18 ? AsT18 : default; remainder = _index switch @@ -2731,12 +2809,16 @@ public bool TryPickT18(out T18 value, out OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT18; } - public bool TryPickT19(out T19 value, out OneOf remainder) +#if NET + public bool TryPickT19([NotNullWhen(true)] out T19? value, out OneOf remainder) +#else + public bool TryPickT19(out T19? value, out OneOf remainder) +#endif { value = IsT19 ? AsT19 : default; remainder = _index switch @@ -2772,12 +2854,16 @@ public bool TryPickT19(out T19 value, out OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT19; } - public bool TryPickT20(out T20 value, out OneOf remainder) +#if NET + public bool TryPickT20([NotNullWhen(true)] out T20? value, out OneOf remainder) +#else + public bool TryPickT20(out T20? value, out OneOf remainder) +#endif { value = IsT20 ? AsT20 : default; remainder = _index switch @@ -2813,12 +2899,16 @@ public bool TryPickT20(out T20 value, out OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT20; } - public bool TryPickT21(out T21 value, out OneOf remainder) +#if NET + public bool TryPickT21([NotNullWhen(true)] out T21? value, out OneOf remainder) +#else + public bool TryPickT21(out T21? value, out OneOf remainder) +#endif { value = IsT21 ? AsT21 : default; remainder = _index switch @@ -2854,12 +2944,16 @@ public bool TryPickT21(out T21 value, out OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT21; } - public bool TryPickT22(out T22 value, out OneOf remainder) +#if NET + public bool TryPickT22([NotNullWhen(true)] out T22? value, out OneOf remainder) +#else + public bool TryPickT22(out T22? value, out OneOf remainder) +#endif { value = IsT22 ? AsT22 : default; remainder = _index switch @@ -2895,12 +2989,16 @@ public bool TryPickT22(out T22 value, out OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT22; } - public bool TryPickT23(out T23 value, out OneOf remainder) +#if NET + public bool TryPickT23([NotNullWhen(true)] out T23? value, out OneOf remainder) +#else + public bool TryPickT23(out T23? value, out OneOf remainder) +#endif { value = IsT23 ? AsT23 : default; remainder = _index switch @@ -2936,12 +3034,16 @@ public bool TryPickT23(out T23 value, out OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT23; } - public bool TryPickT24(out T24 value, out OneOf remainder) +#if NET + public bool TryPickT24([NotNullWhen(true)] out T24? value, out OneOf remainder) +#else + public bool TryPickT24(out T24? value, out OneOf remainder) +#endif { value = IsT24 ? AsT24 : default; remainder = _index switch @@ -2977,12 +3079,16 @@ public bool TryPickT24(out T24 value, out OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT24; } - public bool TryPickT25(out T25 value, out OneOf remainder) +#if NET + public bool TryPickT25([NotNullWhen(true)] out T25? value, out OneOf remainder) +#else + public bool TryPickT25(out T25? value, out OneOf remainder) +#endif { value = IsT25 ? AsT25 : default; remainder = _index switch @@ -3018,12 +3124,16 @@ public bool TryPickT25(out T25 value, out OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT25; } - public bool TryPickT26(out T26 value, out OneOf remainder) +#if NET + public bool TryPickT26([NotNullWhen(true)] out T26? value, out OneOf remainder) +#else + public bool TryPickT26(out T26? value, out OneOf remainder) +#endif { value = IsT26 ? AsT26 : default; remainder = _index switch @@ -3059,12 +3169,16 @@ public bool TryPickT26(out T26 value, out OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT26; } - public bool TryPickT27(out T27 value, out OneOf remainder) +#if NET + public bool TryPickT27([NotNullWhen(true)] out T27? value, out OneOf remainder) +#else + public bool TryPickT27(out T27? value, out OneOf remainder) +#endif { value = IsT27 ? AsT27 : default; remainder = _index switch @@ -3100,12 +3214,16 @@ public bool TryPickT27(out T27 value, out OneOf AsT28, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT27; } - public bool TryPickT28(out T28 value, out OneOf remainder) +#if NET + public bool TryPickT28([NotNullWhen(true)] out T28? value, out OneOf remainder) +#else + public bool TryPickT28(out T28? value, out OneOf remainder) +#endif { value = IsT28 ? AsT28 : default; remainder = _index switch @@ -3141,12 +3259,16 @@ public bool TryPickT28(out T28 value, out OneOf default, 29 => AsT29, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT28; } - public bool TryPickT29(out T29 value, out OneOf remainder) +#if NET + public bool TryPickT29([NotNullWhen(true)] out T29? value, out OneOf remainder) +#else + public bool TryPickT29(out T29? value, out OneOf remainder) +#endif { value = IsT29 ? AsT29 : default; remainder = _index switch @@ -3182,12 +3304,16 @@ public bool TryPickT29(out T29 value, out OneOf AsT28, 29 => default, 30 => AsT30, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT29; } - public bool TryPickT30(out T30 value, out OneOf remainder) +#if NET + public bool TryPickT30([NotNullWhen(true)] out T30? value, out OneOf remainder) +#else + public bool TryPickT30(out T30? value, out OneOf remainder) +#endif { value = IsT30 ? AsT30 : default; remainder = _index switch @@ -3223,7 +3349,7 @@ public bool TryPickT30(out T30 value, out OneOf AsT28, 29 => AsT29, 30 => default, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT30; } @@ -3266,7 +3392,7 @@ bool Equals(OneOf false }; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/OneOf.Extended/OneOfT31.generated.cs b/OneOf.Extended/OneOfT31.generated.cs index 5e2686e..4ccf4fb 100644 --- a/OneOf.Extended/OneOfT31.generated.cs +++ b/OneOf.Extended/OneOfT31.generated.cs @@ -1,4 +1,6 @@ +#nullable enable using System; +using System.Diagnostics.CodeAnalysis; using static OneOf.Functions; namespace OneOf @@ -39,7 +41,7 @@ namespace OneOf readonly T31 _value31; readonly int _index; - OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default, T10 value10 = default, T11 value11 = default, T12 value12 = default, T13 value13 = default, T14 value14 = default, T15 value15 = default, T16 value16 = default, T17 value17 = default, T18 value18 = default, T19 value19 = default, T20 value20 = default, T21 value21 = default, T22 value22 = default, T23 value23 = default, T24 value24 = default, T25 value25 = default, T26 value26 = default, T27 value27 = default, T28 value28 = default, T29 value29 = default, T30 value30 = default, T31 value31 = default) + OneOf(int index, T0 value0 = default!, T1 value1 = default!, T2 value2 = default!, T3 value3 = default!, T4 value4 = default!, T5 value5 = default!, T6 value6 = default!, T7 value7 = default!, T8 value8 = default!, T9 value9 = default!, T10 value10 = default!, T11 value11 = default!, T12 value12 = default!, T13 value13 = default!, T14 value14 = default!, T15 value15 = default!, T16 value16 = default!, T17 value17 = default!, T18 value18 = default!, T19 value19 = default!, T20 value20 = default!, T21 value21 = default!, T22 value22 = default!, T23 value23 = default!, T24 value24 = default!, T25 value25 = default!, T26 value26 = default!, T27 value27 = default!, T28 value28 = default!, T29 value29 = default!, T30 value30 = default!, T31 value31 = default!) { _index = index; _value0 = value0; @@ -76,7 +78,7 @@ namespace OneOf _value31 = value31; } - public object Value => + public object? Value => _index switch { 0 => _value0, @@ -111,7 +113,7 @@ namespace OneOf 29 => _value29, 30 => _value30, 31 => _value31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; public int Index => _index; @@ -473,7 +475,7 @@ public void Switch(Action f0, Action f1, Action f2, Action f3, A f31(_value31); return; } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } public TResult Match(Func f0, Func f1, Func f2, Func f3, Func f4, Func f5, Func f6, Func f7, Func f8, Func f9, Func f10, Func f11, Func f12, Func f13, Func f14, Func f15, Func f16, Func f17, Func f18, Func f19, Func f20, Func f21, Func f22, Func f23, Func f24, Func f25, Func f26, Func f27, Func f28, Func f29, Func f30, Func f31) @@ -606,7 +608,7 @@ public TResult Match(Func f0, Func f1, Func FromT0(T0 input) => input; @@ -683,7 +685,7 @@ public OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -727,7 +729,7 @@ public OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -771,7 +773,7 @@ public OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -815,7 +817,7 @@ public OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -859,7 +861,7 @@ public OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -903,7 +905,7 @@ public OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -947,7 +949,7 @@ public OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -991,7 +993,7 @@ public OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1035,7 +1037,7 @@ public OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1079,7 +1081,7 @@ public OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1123,7 +1125,7 @@ public OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1167,7 +1169,7 @@ public OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1211,7 +1213,7 @@ public OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1255,7 +1257,7 @@ public OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1299,7 +1301,7 @@ public OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1343,7 +1345,7 @@ public OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1387,7 +1389,7 @@ public OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1431,7 +1433,7 @@ public OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1475,7 +1477,7 @@ public OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1519,7 +1521,7 @@ public OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1563,7 +1565,7 @@ public OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1607,7 +1609,7 @@ public OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1651,7 +1653,7 @@ public OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1695,7 +1697,7 @@ public OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1739,7 +1741,7 @@ public OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1783,7 +1785,7 @@ public OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1827,7 +1829,7 @@ public OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1871,7 +1873,7 @@ public OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1915,7 +1917,7 @@ public OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -1959,7 +1961,7 @@ public OneOf mapFunc(AsT29), 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -2003,7 +2005,7 @@ public OneOf AsT29, 30 => mapFunc(AsT30), 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -2047,11 +2049,15 @@ public OneOf AsT29, 30 => AsT30, 31 => mapFunc(AsT31), - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } - public bool TryPickT0(out T0 value, out OneOf remainder) +#if NET + public bool TryPickT0([NotNullWhen(true)] out T0? value, out OneOf remainder) +#else + public bool TryPickT0(out T0? value, out OneOf remainder) +#endif { value = IsT0 ? AsT0 : default; remainder = _index switch @@ -2088,12 +2094,16 @@ public bool TryPickT0(out T0 value, out OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT0; } - public bool TryPickT1(out T1 value, out OneOf remainder) +#if NET + public bool TryPickT1([NotNullWhen(true)] out T1? value, out OneOf remainder) +#else + public bool TryPickT1(out T1? value, out OneOf remainder) +#endif { value = IsT1 ? AsT1 : default; remainder = _index switch @@ -2130,12 +2140,16 @@ public bool TryPickT1(out T1 value, out OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT1; } - public bool TryPickT2(out T2 value, out OneOf remainder) +#if NET + public bool TryPickT2([NotNullWhen(true)] out T2? value, out OneOf remainder) +#else + public bool TryPickT2(out T2? value, out OneOf remainder) +#endif { value = IsT2 ? AsT2 : default; remainder = _index switch @@ -2172,12 +2186,16 @@ public bool TryPickT2(out T2 value, out OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT2; } - public bool TryPickT3(out T3 value, out OneOf remainder) +#if NET + public bool TryPickT3([NotNullWhen(true)] out T3? value, out OneOf remainder) +#else + public bool TryPickT3(out T3? value, out OneOf remainder) +#endif { value = IsT3 ? AsT3 : default; remainder = _index switch @@ -2214,12 +2232,16 @@ public bool TryPickT3(out T3 value, out OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT3; } - public bool TryPickT4(out T4 value, out OneOf remainder) +#if NET + public bool TryPickT4([NotNullWhen(true)] out T4? value, out OneOf remainder) +#else + public bool TryPickT4(out T4? value, out OneOf remainder) +#endif { value = IsT4 ? AsT4 : default; remainder = _index switch @@ -2256,12 +2278,16 @@ public bool TryPickT4(out T4 value, out OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT4; } - public bool TryPickT5(out T5 value, out OneOf remainder) +#if NET + public bool TryPickT5([NotNullWhen(true)] out T5? value, out OneOf remainder) +#else + public bool TryPickT5(out T5? value, out OneOf remainder) +#endif { value = IsT5 ? AsT5 : default; remainder = _index switch @@ -2298,12 +2324,16 @@ public bool TryPickT5(out T5 value, out OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT5; } - public bool TryPickT6(out T6 value, out OneOf remainder) +#if NET + public bool TryPickT6([NotNullWhen(true)] out T6? value, out OneOf remainder) +#else + public bool TryPickT6(out T6? value, out OneOf remainder) +#endif { value = IsT6 ? AsT6 : default; remainder = _index switch @@ -2340,12 +2370,16 @@ public bool TryPickT6(out T6 value, out OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT6; } - public bool TryPickT7(out T7 value, out OneOf remainder) +#if NET + public bool TryPickT7([NotNullWhen(true)] out T7? value, out OneOf remainder) +#else + public bool TryPickT7(out T7? value, out OneOf remainder) +#endif { value = IsT7 ? AsT7 : default; remainder = _index switch @@ -2382,12 +2416,16 @@ public bool TryPickT7(out T7 value, out OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT7; } - public bool TryPickT8(out T8 value, out OneOf remainder) +#if NET + public bool TryPickT8([NotNullWhen(true)] out T8? value, out OneOf remainder) +#else + public bool TryPickT8(out T8? value, out OneOf remainder) +#endif { value = IsT8 ? AsT8 : default; remainder = _index switch @@ -2424,12 +2462,16 @@ public bool TryPickT8(out T8 value, out OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT8; } - public bool TryPickT9(out T9 value, out OneOf remainder) +#if NET + public bool TryPickT9([NotNullWhen(true)] out T9? value, out OneOf remainder) +#else + public bool TryPickT9(out T9? value, out OneOf remainder) +#endif { value = IsT9 ? AsT9 : default; remainder = _index switch @@ -2466,12 +2508,16 @@ public bool TryPickT9(out T9 value, out OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT9; } - public bool TryPickT10(out T10 value, out OneOf remainder) +#if NET + public bool TryPickT10([NotNullWhen(true)] out T10? value, out OneOf remainder) +#else + public bool TryPickT10(out T10? value, out OneOf remainder) +#endif { value = IsT10 ? AsT10 : default; remainder = _index switch @@ -2508,12 +2554,16 @@ public bool TryPickT10(out T10 value, out OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT10; } - public bool TryPickT11(out T11 value, out OneOf remainder) +#if NET + public bool TryPickT11([NotNullWhen(true)] out T11? value, out OneOf remainder) +#else + public bool TryPickT11(out T11? value, out OneOf remainder) +#endif { value = IsT11 ? AsT11 : default; remainder = _index switch @@ -2550,12 +2600,16 @@ public bool TryPickT11(out T11 value, out OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT11; } - public bool TryPickT12(out T12 value, out OneOf remainder) +#if NET + public bool TryPickT12([NotNullWhen(true)] out T12? value, out OneOf remainder) +#else + public bool TryPickT12(out T12? value, out OneOf remainder) +#endif { value = IsT12 ? AsT12 : default; remainder = _index switch @@ -2592,12 +2646,16 @@ public bool TryPickT12(out T12 value, out OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT12; } - public bool TryPickT13(out T13 value, out OneOf remainder) +#if NET + public bool TryPickT13([NotNullWhen(true)] out T13? value, out OneOf remainder) +#else + public bool TryPickT13(out T13? value, out OneOf remainder) +#endif { value = IsT13 ? AsT13 : default; remainder = _index switch @@ -2634,12 +2692,16 @@ public bool TryPickT13(out T13 value, out OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT13; } - public bool TryPickT14(out T14 value, out OneOf remainder) +#if NET + public bool TryPickT14([NotNullWhen(true)] out T14? value, out OneOf remainder) +#else + public bool TryPickT14(out T14? value, out OneOf remainder) +#endif { value = IsT14 ? AsT14 : default; remainder = _index switch @@ -2676,12 +2738,16 @@ public bool TryPickT14(out T14 value, out OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT14; } - public bool TryPickT15(out T15 value, out OneOf remainder) +#if NET + public bool TryPickT15([NotNullWhen(true)] out T15? value, out OneOf remainder) +#else + public bool TryPickT15(out T15? value, out OneOf remainder) +#endif { value = IsT15 ? AsT15 : default; remainder = _index switch @@ -2718,12 +2784,16 @@ public bool TryPickT15(out T15 value, out OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT15; } - public bool TryPickT16(out T16 value, out OneOf remainder) +#if NET + public bool TryPickT16([NotNullWhen(true)] out T16? value, out OneOf remainder) +#else + public bool TryPickT16(out T16? value, out OneOf remainder) +#endif { value = IsT16 ? AsT16 : default; remainder = _index switch @@ -2760,12 +2830,16 @@ public bool TryPickT16(out T16 value, out OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT16; } - public bool TryPickT17(out T17 value, out OneOf remainder) +#if NET + public bool TryPickT17([NotNullWhen(true)] out T17? value, out OneOf remainder) +#else + public bool TryPickT17(out T17? value, out OneOf remainder) +#endif { value = IsT17 ? AsT17 : default; remainder = _index switch @@ -2802,12 +2876,16 @@ public bool TryPickT17(out T17 value, out OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT17; } - public bool TryPickT18(out T18 value, out OneOf remainder) +#if NET + public bool TryPickT18([NotNullWhen(true)] out T18? value, out OneOf remainder) +#else + public bool TryPickT18(out T18? value, out OneOf remainder) +#endif { value = IsT18 ? AsT18 : default; remainder = _index switch @@ -2844,12 +2922,16 @@ public bool TryPickT18(out T18 value, out OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT18; } - public bool TryPickT19(out T19 value, out OneOf remainder) +#if NET + public bool TryPickT19([NotNullWhen(true)] out T19? value, out OneOf remainder) +#else + public bool TryPickT19(out T19? value, out OneOf remainder) +#endif { value = IsT19 ? AsT19 : default; remainder = _index switch @@ -2886,12 +2968,16 @@ public bool TryPickT19(out T19 value, out OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT19; } - public bool TryPickT20(out T20 value, out OneOf remainder) +#if NET + public bool TryPickT20([NotNullWhen(true)] out T20? value, out OneOf remainder) +#else + public bool TryPickT20(out T20? value, out OneOf remainder) +#endif { value = IsT20 ? AsT20 : default; remainder = _index switch @@ -2928,12 +3014,16 @@ public bool TryPickT20(out T20 value, out OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT20; } - public bool TryPickT21(out T21 value, out OneOf remainder) +#if NET + public bool TryPickT21([NotNullWhen(true)] out T21? value, out OneOf remainder) +#else + public bool TryPickT21(out T21? value, out OneOf remainder) +#endif { value = IsT21 ? AsT21 : default; remainder = _index switch @@ -2970,12 +3060,16 @@ public bool TryPickT21(out T21 value, out OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT21; } - public bool TryPickT22(out T22 value, out OneOf remainder) +#if NET + public bool TryPickT22([NotNullWhen(true)] out T22? value, out OneOf remainder) +#else + public bool TryPickT22(out T22? value, out OneOf remainder) +#endif { value = IsT22 ? AsT22 : default; remainder = _index switch @@ -3012,12 +3106,16 @@ public bool TryPickT22(out T22 value, out OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT22; } - public bool TryPickT23(out T23 value, out OneOf remainder) +#if NET + public bool TryPickT23([NotNullWhen(true)] out T23? value, out OneOf remainder) +#else + public bool TryPickT23(out T23? value, out OneOf remainder) +#endif { value = IsT23 ? AsT23 : default; remainder = _index switch @@ -3054,12 +3152,16 @@ public bool TryPickT23(out T23 value, out OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT23; } - public bool TryPickT24(out T24 value, out OneOf remainder) +#if NET + public bool TryPickT24([NotNullWhen(true)] out T24? value, out OneOf remainder) +#else + public bool TryPickT24(out T24? value, out OneOf remainder) +#endif { value = IsT24 ? AsT24 : default; remainder = _index switch @@ -3096,12 +3198,16 @@ public bool TryPickT24(out T24 value, out OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT24; } - public bool TryPickT25(out T25 value, out OneOf remainder) +#if NET + public bool TryPickT25([NotNullWhen(true)] out T25? value, out OneOf remainder) +#else + public bool TryPickT25(out T25? value, out OneOf remainder) +#endif { value = IsT25 ? AsT25 : default; remainder = _index switch @@ -3138,12 +3244,16 @@ public bool TryPickT25(out T25 value, out OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT25; } - public bool TryPickT26(out T26 value, out OneOf remainder) +#if NET + public bool TryPickT26([NotNullWhen(true)] out T26? value, out OneOf remainder) +#else + public bool TryPickT26(out T26? value, out OneOf remainder) +#endif { value = IsT26 ? AsT26 : default; remainder = _index switch @@ -3180,12 +3290,16 @@ public bool TryPickT26(out T26 value, out OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT26; } - public bool TryPickT27(out T27 value, out OneOf remainder) +#if NET + public bool TryPickT27([NotNullWhen(true)] out T27? value, out OneOf remainder) +#else + public bool TryPickT27(out T27? value, out OneOf remainder) +#endif { value = IsT27 ? AsT27 : default; remainder = _index switch @@ -3222,12 +3336,16 @@ public bool TryPickT27(out T27 value, out OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT27; } - public bool TryPickT28(out T28 value, out OneOf remainder) +#if NET + public bool TryPickT28([NotNullWhen(true)] out T28? value, out OneOf remainder) +#else + public bool TryPickT28(out T28? value, out OneOf remainder) +#endif { value = IsT28 ? AsT28 : default; remainder = _index switch @@ -3264,12 +3382,16 @@ public bool TryPickT28(out T28 value, out OneOf AsT29, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT28; } - public bool TryPickT29(out T29 value, out OneOf remainder) +#if NET + public bool TryPickT29([NotNullWhen(true)] out T29? value, out OneOf remainder) +#else + public bool TryPickT29(out T29? value, out OneOf remainder) +#endif { value = IsT29 ? AsT29 : default; remainder = _index switch @@ -3306,12 +3428,16 @@ public bool TryPickT29(out T29 value, out OneOf default, 30 => AsT30, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT29; } - public bool TryPickT30(out T30 value, out OneOf remainder) +#if NET + public bool TryPickT30([NotNullWhen(true)] out T30? value, out OneOf remainder) +#else + public bool TryPickT30(out T30? value, out OneOf remainder) +#endif { value = IsT30 ? AsT30 : default; remainder = _index switch @@ -3348,12 +3474,16 @@ public bool TryPickT30(out T30 value, out OneOf AsT29, 30 => default, 31 => AsT31, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT30; } - public bool TryPickT31(out T31 value, out OneOf remainder) +#if NET + public bool TryPickT31([NotNullWhen(true)] out T31? value, out OneOf remainder) +#else + public bool TryPickT31(out T31? value, out OneOf remainder) +#endif { value = IsT31 ? AsT31 : default; remainder = _index switch @@ -3390,7 +3520,7 @@ public bool TryPickT31(out T31 value, out OneOf AsT29, 30 => AsT30, 31 => default, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT31; } @@ -3434,7 +3564,7 @@ bool Equals(OneOf false }; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/OneOf.Extended/OneOfT9.generated.cs b/OneOf.Extended/OneOfT9.generated.cs index a1efcd2..d85ef1b 100644 --- a/OneOf.Extended/OneOfT9.generated.cs +++ b/OneOf.Extended/OneOfT9.generated.cs @@ -1,4 +1,6 @@ +#nullable enable using System; +using System.Diagnostics.CodeAnalysis; using static OneOf.Functions; namespace OneOf @@ -17,7 +19,7 @@ namespace OneOf readonly T9 _value9; readonly int _index; - OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default) + OneOf(int index, T0 value0 = default!, T1 value1 = default!, T2 value2 = default!, T3 value3 = default!, T4 value4 = default!, T5 value5 = default!, T6 value6 = default!, T7 value7 = default!, T8 value8 = default!, T9 value9 = default!) { _index = index; _value0 = value0; @@ -32,7 +34,7 @@ namespace OneOf _value9 = value9; } - public object Value => + public object? Value => _index switch { 0 => _value0, @@ -45,7 +47,7 @@ namespace OneOf 7 => _value7, 8 => _value8, 9 => _value9, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; public int Index => _index; @@ -165,7 +167,7 @@ public void Switch(Action f0, Action f1, Action f2, Action f3, A f9(_value9); return; } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } public TResult Match(Func f0, Func f1, Func f2, Func f3, Func f4, Func f5, Func f6, Func f7, Func f8, Func f9) @@ -210,7 +212,7 @@ public TResult Match(Func f0, Func f1, Func FromT0(T0 input) => input; @@ -243,7 +245,7 @@ public OneOf MapT0(Func AsT7, 8 => AsT8, 9 => AsT9, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -265,7 +267,7 @@ public OneOf MapT1(Func AsT7, 8 => AsT8, 9 => AsT9, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -287,7 +289,7 @@ public OneOf MapT2(Func AsT7, 8 => AsT8, 9 => AsT9, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -309,7 +311,7 @@ public OneOf MapT3(Func AsT7, 8 => AsT8, 9 => AsT9, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -331,7 +333,7 @@ public OneOf MapT4(Func AsT7, 8 => AsT8, 9 => AsT9, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -353,7 +355,7 @@ public OneOf MapT5(Func AsT7, 8 => AsT8, 9 => AsT9, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -375,7 +377,7 @@ public OneOf MapT6(Func AsT7, 8 => AsT8, 9 => AsT9, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -397,7 +399,7 @@ public OneOf MapT7(Func mapFunc(AsT7), 8 => AsT8, 9 => AsT9, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -419,7 +421,7 @@ public OneOf MapT8(Func AsT7, 8 => mapFunc(AsT8), 9 => AsT9, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -441,11 +443,15 @@ public OneOf MapT9(Func AsT7, 8 => AsT8, 9 => mapFunc(AsT9), - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } - public bool TryPickT0(out T0 value, out OneOf remainder) +#if NET + public bool TryPickT0([NotNullWhen(true)] out T0? value, out OneOf remainder) +#else + public bool TryPickT0(out T0? value, out OneOf remainder) +#endif { value = IsT0 ? AsT0 : default; remainder = _index switch @@ -460,12 +466,16 @@ public bool TryPickT0(out T0 value, out OneOf AsT7, 8 => AsT8, 9 => AsT9, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT0; } - public bool TryPickT1(out T1 value, out OneOf remainder) +#if NET + public bool TryPickT1([NotNullWhen(true)] out T1? value, out OneOf remainder) +#else + public bool TryPickT1(out T1? value, out OneOf remainder) +#endif { value = IsT1 ? AsT1 : default; remainder = _index switch @@ -480,12 +490,16 @@ public bool TryPickT1(out T1 value, out OneOf AsT7, 8 => AsT8, 9 => AsT9, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT1; } - public bool TryPickT2(out T2 value, out OneOf remainder) +#if NET + public bool TryPickT2([NotNullWhen(true)] out T2? value, out OneOf remainder) +#else + public bool TryPickT2(out T2? value, out OneOf remainder) +#endif { value = IsT2 ? AsT2 : default; remainder = _index switch @@ -500,12 +514,16 @@ public bool TryPickT2(out T2 value, out OneOf AsT7, 8 => AsT8, 9 => AsT9, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT2; } - public bool TryPickT3(out T3 value, out OneOf remainder) +#if NET + public bool TryPickT3([NotNullWhen(true)] out T3? value, out OneOf remainder) +#else + public bool TryPickT3(out T3? value, out OneOf remainder) +#endif { value = IsT3 ? AsT3 : default; remainder = _index switch @@ -520,12 +538,16 @@ public bool TryPickT3(out T3 value, out OneOf AsT7, 8 => AsT8, 9 => AsT9, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT3; } - public bool TryPickT4(out T4 value, out OneOf remainder) +#if NET + public bool TryPickT4([NotNullWhen(true)] out T4? value, out OneOf remainder) +#else + public bool TryPickT4(out T4? value, out OneOf remainder) +#endif { value = IsT4 ? AsT4 : default; remainder = _index switch @@ -540,12 +562,16 @@ public bool TryPickT4(out T4 value, out OneOf AsT7, 8 => AsT8, 9 => AsT9, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT4; } - public bool TryPickT5(out T5 value, out OneOf remainder) +#if NET + public bool TryPickT5([NotNullWhen(true)] out T5? value, out OneOf remainder) +#else + public bool TryPickT5(out T5? value, out OneOf remainder) +#endif { value = IsT5 ? AsT5 : default; remainder = _index switch @@ -560,12 +586,16 @@ public bool TryPickT5(out T5 value, out OneOf AsT7, 8 => AsT8, 9 => AsT9, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT5; } - public bool TryPickT6(out T6 value, out OneOf remainder) +#if NET + public bool TryPickT6([NotNullWhen(true)] out T6? value, out OneOf remainder) +#else + public bool TryPickT6(out T6? value, out OneOf remainder) +#endif { value = IsT6 ? AsT6 : default; remainder = _index switch @@ -580,12 +610,16 @@ public bool TryPickT6(out T6 value, out OneOf AsT7, 8 => AsT8, 9 => AsT9, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT6; } - public bool TryPickT7(out T7 value, out OneOf remainder) +#if NET + public bool TryPickT7([NotNullWhen(true)] out T7? value, out OneOf remainder) +#else + public bool TryPickT7(out T7? value, out OneOf remainder) +#endif { value = IsT7 ? AsT7 : default; remainder = _index switch @@ -600,12 +634,16 @@ public bool TryPickT7(out T7 value, out OneOf default, 8 => AsT8, 9 => AsT9, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT7; } - public bool TryPickT8(out T8 value, out OneOf remainder) +#if NET + public bool TryPickT8([NotNullWhen(true)] out T8? value, out OneOf remainder) +#else + public bool TryPickT8(out T8? value, out OneOf remainder) +#endif { value = IsT8 ? AsT8 : default; remainder = _index switch @@ -620,12 +658,16 @@ public bool TryPickT8(out T8 value, out OneOf AsT7, 8 => default, 9 => AsT9, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT8; } - public bool TryPickT9(out T9 value, out OneOf remainder) +#if NET + public bool TryPickT9([NotNullWhen(true)] out T9? value, out OneOf remainder) +#else + public bool TryPickT9(out T9? value, out OneOf remainder) +#endif { value = IsT9 ? AsT9 : default; remainder = _index switch @@ -640,7 +682,7 @@ public bool TryPickT9(out T9 value, out OneOf AsT7, 8 => AsT8, 9 => default, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT9; } @@ -662,7 +704,7 @@ bool Equals(OneOf other) => _ => false }; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/OneOf/OneOfBaseT0.generated.cs b/OneOf/OneOfBaseT0.generated.cs index 52a7fba..82ca96f 100644 --- a/OneOf/OneOfBaseT0.generated.cs +++ b/OneOf/OneOfBaseT0.generated.cs @@ -1,11 +1,13 @@ +#nullable enable using System; +using System.Diagnostics.CodeAnalysis; using static OneOf.Functions; namespace OneOf { public class OneOfBase : IOneOf { - readonly T0 _value0; + readonly T0 _value0 = default!; readonly int _index; protected OneOfBase(OneOf input) @@ -14,15 +16,15 @@ protected OneOfBase(OneOf input) switch (_index) { case 0: _value0 = input.AsT0; break; - default: throw new InvalidOperationException(); + default: throw InvalidIndexException(_index); } } - public object Value => + public object? Value => _index switch { 0 => _value0, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; public int Index => _index; @@ -43,7 +45,7 @@ public void Switch(Action f0) f0(_value0); return; } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } public TResult Match(Func f0) @@ -52,7 +54,7 @@ public TResult Match(Func f0) { return f0(_value0); } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } @@ -67,7 +69,7 @@ bool Equals(OneOfBase other) => _ => false }; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/OneOf/OneOfBaseT1.generated.cs b/OneOf/OneOfBaseT1.generated.cs index b5816b4..4a436f0 100644 --- a/OneOf/OneOfBaseT1.generated.cs +++ b/OneOf/OneOfBaseT1.generated.cs @@ -1,12 +1,14 @@ +#nullable enable using System; +using System.Diagnostics.CodeAnalysis; using static OneOf.Functions; namespace OneOf { public class OneOfBase : IOneOf { - readonly T0 _value0; - readonly T1 _value1; + readonly T0 _value0 = default!; + readonly T1 _value1 = default!; readonly int _index; protected OneOfBase(OneOf input) @@ -16,16 +18,16 @@ protected OneOfBase(OneOf input) { case 0: _value0 = input.AsT0; break; case 1: _value1 = input.AsT1; break; - default: throw new InvalidOperationException(); + default: throw InvalidIndexException(_index); } } - public object Value => + public object? Value => _index switch { 0 => _value0, 1 => _value1, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; public int Index => _index; @@ -56,7 +58,7 @@ public void Switch(Action f0, Action f1) f1(_value1); return; } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } public TResult Match(Func f0, Func f1) @@ -69,33 +71,41 @@ public TResult Match(Func f0, Func f1) { return f1(_value1); } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } - public bool TryPickT0(out T0 value, out T1 remainder) +#if NET + public bool TryPickT0([NotNullWhen(true)] out T0? value, [NotNullWhen(false)] out T1? remainder) +#else + public bool TryPickT0(out T0? value, out T1? remainder) +#endif { value = IsT0 ? AsT0 : default; remainder = _index switch { 0 => default, 1 => AsT1, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT0; } - public bool TryPickT1(out T1 value, out T0 remainder) +#if NET + public bool TryPickT1([NotNullWhen(true)] out T1? value, [NotNullWhen(false)] out T0? remainder) +#else + public bool TryPickT1(out T1? value, out T0? remainder) +#endif { value = IsT1 ? AsT1 : default; remainder = _index switch { 0 => AsT0, 1 => default, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT1; } @@ -109,7 +119,7 @@ bool Equals(OneOfBase other) => _ => false }; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/OneOf/OneOfBaseT2.generated.cs b/OneOf/OneOfBaseT2.generated.cs index d8ed1a8..52e52ac 100644 --- a/OneOf/OneOfBaseT2.generated.cs +++ b/OneOf/OneOfBaseT2.generated.cs @@ -1,13 +1,15 @@ +#nullable enable using System; +using System.Diagnostics.CodeAnalysis; using static OneOf.Functions; namespace OneOf { public class OneOfBase : IOneOf { - readonly T0 _value0; - readonly T1 _value1; - readonly T2 _value2; + readonly T0 _value0 = default!; + readonly T1 _value1 = default!; + readonly T2 _value2 = default!; readonly int _index; protected OneOfBase(OneOf input) @@ -18,17 +20,17 @@ protected OneOfBase(OneOf input) case 0: _value0 = input.AsT0; break; case 1: _value1 = input.AsT1; break; case 2: _value2 = input.AsT2; break; - default: throw new InvalidOperationException(); + default: throw InvalidIndexException(_index); } } - public object Value => + public object? Value => _index switch { 0 => _value0, 1 => _value1, 2 => _value2, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; public int Index => _index; @@ -69,7 +71,7 @@ public void Switch(Action f0, Action f1, Action f2) f2(_value2); return; } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } public TResult Match(Func f0, Func f1, Func f2) @@ -86,14 +88,18 @@ public TResult Match(Func f0, Func f1, Func remainder) +#if NET + public bool TryPickT0([NotNullWhen(true)] out T0? value, out OneOf remainder) +#else + public bool TryPickT0(out T0? value, out OneOf remainder) +#endif { value = IsT0 ? AsT0 : default; remainder = _index switch @@ -101,12 +107,16 @@ public bool TryPickT0(out T0 value, out OneOf remainder) 0 => default, 1 => AsT1, 2 => AsT2, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT0; } - public bool TryPickT1(out T1 value, out OneOf remainder) +#if NET + public bool TryPickT1([NotNullWhen(true)] out T1? value, out OneOf remainder) +#else + public bool TryPickT1(out T1? value, out OneOf remainder) +#endif { value = IsT1 ? AsT1 : default; remainder = _index switch @@ -114,12 +124,16 @@ public bool TryPickT1(out T1 value, out OneOf remainder) 0 => AsT0, 1 => default, 2 => AsT2, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT1; } - public bool TryPickT2(out T2 value, out OneOf remainder) +#if NET + public bool TryPickT2([NotNullWhen(true)] out T2? value, out OneOf remainder) +#else + public bool TryPickT2(out T2? value, out OneOf remainder) +#endif { value = IsT2 ? AsT2 : default; remainder = _index switch @@ -127,7 +141,7 @@ public bool TryPickT2(out T2 value, out OneOf remainder) 0 => AsT0, 1 => AsT1, 2 => default, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT2; } @@ -142,7 +156,7 @@ bool Equals(OneOfBase other) => _ => false }; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/OneOf/OneOfBaseT3.generated.cs b/OneOf/OneOfBaseT3.generated.cs index c47bd8e..9fc5f85 100644 --- a/OneOf/OneOfBaseT3.generated.cs +++ b/OneOf/OneOfBaseT3.generated.cs @@ -1,14 +1,16 @@ +#nullable enable using System; +using System.Diagnostics.CodeAnalysis; using static OneOf.Functions; namespace OneOf { public class OneOfBase : IOneOf { - readonly T0 _value0; - readonly T1 _value1; - readonly T2 _value2; - readonly T3 _value3; + readonly T0 _value0 = default!; + readonly T1 _value1 = default!; + readonly T2 _value2 = default!; + readonly T3 _value3 = default!; readonly int _index; protected OneOfBase(OneOf input) @@ -20,18 +22,18 @@ protected OneOfBase(OneOf input) case 1: _value1 = input.AsT1; break; case 2: _value2 = input.AsT2; break; case 3: _value3 = input.AsT3; break; - default: throw new InvalidOperationException(); + default: throw InvalidIndexException(_index); } } - public object Value => + public object? Value => _index switch { 0 => _value0, 1 => _value1, 2 => _value2, 3 => _value3, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; public int Index => _index; @@ -82,7 +84,7 @@ public void Switch(Action f0, Action f1, Action f2, Action f3) f3(_value3); return; } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } public TResult Match(Func f0, Func f1, Func f2, Func f3) @@ -103,14 +105,18 @@ public TResult Match(Func f0, Func f1, Func remainder) +#if NET + public bool TryPickT0([NotNullWhen(true)] out T0? value, out OneOf remainder) +#else + public bool TryPickT0(out T0? value, out OneOf remainder) +#endif { value = IsT0 ? AsT0 : default; remainder = _index switch @@ -119,12 +125,16 @@ public bool TryPickT0(out T0 value, out OneOf remainder) 1 => AsT1, 2 => AsT2, 3 => AsT3, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT0; } - public bool TryPickT1(out T1 value, out OneOf remainder) +#if NET + public bool TryPickT1([NotNullWhen(true)] out T1? value, out OneOf remainder) +#else + public bool TryPickT1(out T1? value, out OneOf remainder) +#endif { value = IsT1 ? AsT1 : default; remainder = _index switch @@ -133,12 +143,16 @@ public bool TryPickT1(out T1 value, out OneOf remainder) 1 => default, 2 => AsT2, 3 => AsT3, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT1; } - public bool TryPickT2(out T2 value, out OneOf remainder) +#if NET + public bool TryPickT2([NotNullWhen(true)] out T2? value, out OneOf remainder) +#else + public bool TryPickT2(out T2? value, out OneOf remainder) +#endif { value = IsT2 ? AsT2 : default; remainder = _index switch @@ -147,12 +161,16 @@ public bool TryPickT2(out T2 value, out OneOf remainder) 1 => AsT1, 2 => default, 3 => AsT3, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT2; } - public bool TryPickT3(out T3 value, out OneOf remainder) +#if NET + public bool TryPickT3([NotNullWhen(true)] out T3? value, out OneOf remainder) +#else + public bool TryPickT3(out T3? value, out OneOf remainder) +#endif { value = IsT3 ? AsT3 : default; remainder = _index switch @@ -161,7 +179,7 @@ public bool TryPickT3(out T3 value, out OneOf remainder) 1 => AsT1, 2 => AsT2, 3 => default, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT3; } @@ -177,7 +195,7 @@ bool Equals(OneOfBase other) => _ => false }; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/OneOf/OneOfBaseT4.generated.cs b/OneOf/OneOfBaseT4.generated.cs index 454c6cf..0f50361 100644 --- a/OneOf/OneOfBaseT4.generated.cs +++ b/OneOf/OneOfBaseT4.generated.cs @@ -1,15 +1,17 @@ +#nullable enable using System; +using System.Diagnostics.CodeAnalysis; using static OneOf.Functions; namespace OneOf { public class OneOfBase : IOneOf { - readonly T0 _value0; - readonly T1 _value1; - readonly T2 _value2; - readonly T3 _value3; - readonly T4 _value4; + readonly T0 _value0 = default!; + readonly T1 _value1 = default!; + readonly T2 _value2 = default!; + readonly T3 _value3 = default!; + readonly T4 _value4 = default!; readonly int _index; protected OneOfBase(OneOf input) @@ -22,11 +24,11 @@ protected OneOfBase(OneOf input) case 2: _value2 = input.AsT2; break; case 3: _value3 = input.AsT3; break; case 4: _value4 = input.AsT4; break; - default: throw new InvalidOperationException(); + default: throw InvalidIndexException(_index); } } - public object Value => + public object? Value => _index switch { 0 => _value0, @@ -34,7 +36,7 @@ protected OneOfBase(OneOf input) 2 => _value2, 3 => _value3, 4 => _value4, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; public int Index => _index; @@ -95,7 +97,7 @@ public void Switch(Action f0, Action f1, Action f2, Action f3, A f4(_value4); return; } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } public TResult Match(Func f0, Func f1, Func f2, Func f3, Func f4) @@ -120,14 +122,18 @@ public TResult Match(Func f0, Func f1, Func remainder) +#if NET + public bool TryPickT0([NotNullWhen(true)] out T0? value, out OneOf remainder) +#else + public bool TryPickT0(out T0? value, out OneOf remainder) +#endif { value = IsT0 ? AsT0 : default; remainder = _index switch @@ -137,12 +143,16 @@ public bool TryPickT0(out T0 value, out OneOf remainder) 2 => AsT2, 3 => AsT3, 4 => AsT4, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT0; } - public bool TryPickT1(out T1 value, out OneOf remainder) +#if NET + public bool TryPickT1([NotNullWhen(true)] out T1? value, out OneOf remainder) +#else + public bool TryPickT1(out T1? value, out OneOf remainder) +#endif { value = IsT1 ? AsT1 : default; remainder = _index switch @@ -152,12 +162,16 @@ public bool TryPickT1(out T1 value, out OneOf remainder) 2 => AsT2, 3 => AsT3, 4 => AsT4, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT1; } - public bool TryPickT2(out T2 value, out OneOf remainder) +#if NET + public bool TryPickT2([NotNullWhen(true)] out T2? value, out OneOf remainder) +#else + public bool TryPickT2(out T2? value, out OneOf remainder) +#endif { value = IsT2 ? AsT2 : default; remainder = _index switch @@ -167,12 +181,16 @@ public bool TryPickT2(out T2 value, out OneOf remainder) 2 => default, 3 => AsT3, 4 => AsT4, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT2; } - public bool TryPickT3(out T3 value, out OneOf remainder) +#if NET + public bool TryPickT3([NotNullWhen(true)] out T3? value, out OneOf remainder) +#else + public bool TryPickT3(out T3? value, out OneOf remainder) +#endif { value = IsT3 ? AsT3 : default; remainder = _index switch @@ -182,12 +200,16 @@ public bool TryPickT3(out T3 value, out OneOf remainder) 2 => AsT2, 3 => default, 4 => AsT4, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT3; } - public bool TryPickT4(out T4 value, out OneOf remainder) +#if NET + public bool TryPickT4([NotNullWhen(true)] out T4? value, out OneOf remainder) +#else + public bool TryPickT4(out T4? value, out OneOf remainder) +#endif { value = IsT4 ? AsT4 : default; remainder = _index switch @@ -197,7 +219,7 @@ public bool TryPickT4(out T4 value, out OneOf remainder) 2 => AsT2, 3 => AsT3, 4 => default, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT4; } @@ -214,7 +236,7 @@ bool Equals(OneOfBase other) => _ => false }; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/OneOf/OneOfBaseT5.generated.cs b/OneOf/OneOfBaseT5.generated.cs index feb72c3..ca02122 100644 --- a/OneOf/OneOfBaseT5.generated.cs +++ b/OneOf/OneOfBaseT5.generated.cs @@ -1,16 +1,18 @@ +#nullable enable using System; +using System.Diagnostics.CodeAnalysis; using static OneOf.Functions; namespace OneOf { public class OneOfBase : IOneOf { - readonly T0 _value0; - readonly T1 _value1; - readonly T2 _value2; - readonly T3 _value3; - readonly T4 _value4; - readonly T5 _value5; + readonly T0 _value0 = default!; + readonly T1 _value1 = default!; + readonly T2 _value2 = default!; + readonly T3 _value3 = default!; + readonly T4 _value4 = default!; + readonly T5 _value5 = default!; readonly int _index; protected OneOfBase(OneOf input) @@ -24,11 +26,11 @@ protected OneOfBase(OneOf input) case 3: _value3 = input.AsT3; break; case 4: _value4 = input.AsT4; break; case 5: _value5 = input.AsT5; break; - default: throw new InvalidOperationException(); + default: throw InvalidIndexException(_index); } } - public object Value => + public object? Value => _index switch { 0 => _value0, @@ -37,7 +39,7 @@ protected OneOfBase(OneOf input) 3 => _value3, 4 => _value4, 5 => _value5, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; public int Index => _index; @@ -108,7 +110,7 @@ public void Switch(Action f0, Action f1, Action f2, Action f3, A f5(_value5); return; } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } public TResult Match(Func f0, Func f1, Func f2, Func f3, Func f4, Func f5) @@ -137,14 +139,18 @@ public TResult Match(Func f0, Func f1, Func remainder) +#if NET + public bool TryPickT0([NotNullWhen(true)] out T0? value, out OneOf remainder) +#else + public bool TryPickT0(out T0? value, out OneOf remainder) +#endif { value = IsT0 ? AsT0 : default; remainder = _index switch @@ -155,12 +161,16 @@ public bool TryPickT0(out T0 value, out OneOf remainder) 3 => AsT3, 4 => AsT4, 5 => AsT5, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT0; } - public bool TryPickT1(out T1 value, out OneOf remainder) +#if NET + public bool TryPickT1([NotNullWhen(true)] out T1? value, out OneOf remainder) +#else + public bool TryPickT1(out T1? value, out OneOf remainder) +#endif { value = IsT1 ? AsT1 : default; remainder = _index switch @@ -171,12 +181,16 @@ public bool TryPickT1(out T1 value, out OneOf remainder) 3 => AsT3, 4 => AsT4, 5 => AsT5, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT1; } - public bool TryPickT2(out T2 value, out OneOf remainder) +#if NET + public bool TryPickT2([NotNullWhen(true)] out T2? value, out OneOf remainder) +#else + public bool TryPickT2(out T2? value, out OneOf remainder) +#endif { value = IsT2 ? AsT2 : default; remainder = _index switch @@ -187,12 +201,16 @@ public bool TryPickT2(out T2 value, out OneOf remainder) 3 => AsT3, 4 => AsT4, 5 => AsT5, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT2; } - public bool TryPickT3(out T3 value, out OneOf remainder) +#if NET + public bool TryPickT3([NotNullWhen(true)] out T3? value, out OneOf remainder) +#else + public bool TryPickT3(out T3? value, out OneOf remainder) +#endif { value = IsT3 ? AsT3 : default; remainder = _index switch @@ -203,12 +221,16 @@ public bool TryPickT3(out T3 value, out OneOf remainder) 3 => default, 4 => AsT4, 5 => AsT5, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT3; } - public bool TryPickT4(out T4 value, out OneOf remainder) +#if NET + public bool TryPickT4([NotNullWhen(true)] out T4? value, out OneOf remainder) +#else + public bool TryPickT4(out T4? value, out OneOf remainder) +#endif { value = IsT4 ? AsT4 : default; remainder = _index switch @@ -219,12 +241,16 @@ public bool TryPickT4(out T4 value, out OneOf remainder) 3 => AsT3, 4 => default, 5 => AsT5, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT4; } - public bool TryPickT5(out T5 value, out OneOf remainder) +#if NET + public bool TryPickT5([NotNullWhen(true)] out T5? value, out OneOf remainder) +#else + public bool TryPickT5(out T5? value, out OneOf remainder) +#endif { value = IsT5 ? AsT5 : default; remainder = _index switch @@ -235,7 +261,7 @@ public bool TryPickT5(out T5 value, out OneOf remainder) 3 => AsT3, 4 => AsT4, 5 => default, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT5; } @@ -253,7 +279,7 @@ bool Equals(OneOfBase other) => _ => false }; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/OneOf/OneOfBaseT6.generated.cs b/OneOf/OneOfBaseT6.generated.cs index 607b865..b57b560 100644 --- a/OneOf/OneOfBaseT6.generated.cs +++ b/OneOf/OneOfBaseT6.generated.cs @@ -1,17 +1,19 @@ +#nullable enable using System; +using System.Diagnostics.CodeAnalysis; using static OneOf.Functions; namespace OneOf { public class OneOfBase : IOneOf { - readonly T0 _value0; - readonly T1 _value1; - readonly T2 _value2; - readonly T3 _value3; - readonly T4 _value4; - readonly T5 _value5; - readonly T6 _value6; + readonly T0 _value0 = default!; + readonly T1 _value1 = default!; + readonly T2 _value2 = default!; + readonly T3 _value3 = default!; + readonly T4 _value4 = default!; + readonly T5 _value5 = default!; + readonly T6 _value6 = default!; readonly int _index; protected OneOfBase(OneOf input) @@ -26,11 +28,11 @@ protected OneOfBase(OneOf input) case 4: _value4 = input.AsT4; break; case 5: _value5 = input.AsT5; break; case 6: _value6 = input.AsT6; break; - default: throw new InvalidOperationException(); + default: throw InvalidIndexException(_index); } } - public object Value => + public object? Value => _index switch { 0 => _value0, @@ -40,7 +42,7 @@ protected OneOfBase(OneOf input) 4 => _value4, 5 => _value5, 6 => _value6, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; public int Index => _index; @@ -121,7 +123,7 @@ public void Switch(Action f0, Action f1, Action f2, Action f3, A f6(_value6); return; } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } public TResult Match(Func f0, Func f1, Func f2, Func f3, Func f4, Func f5, Func f6) @@ -154,14 +156,18 @@ public TResult Match(Func f0, Func f1, Func remainder) +#if NET + public bool TryPickT0([NotNullWhen(true)] out T0? value, out OneOf remainder) +#else + public bool TryPickT0(out T0? value, out OneOf remainder) +#endif { value = IsT0 ? AsT0 : default; remainder = _index switch @@ -173,12 +179,16 @@ public bool TryPickT0(out T0 value, out OneOf remainder) 4 => AsT4, 5 => AsT5, 6 => AsT6, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT0; } - public bool TryPickT1(out T1 value, out OneOf remainder) +#if NET + public bool TryPickT1([NotNullWhen(true)] out T1? value, out OneOf remainder) +#else + public bool TryPickT1(out T1? value, out OneOf remainder) +#endif { value = IsT1 ? AsT1 : default; remainder = _index switch @@ -190,12 +200,16 @@ public bool TryPickT1(out T1 value, out OneOf remainder) 4 => AsT4, 5 => AsT5, 6 => AsT6, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT1; } - public bool TryPickT2(out T2 value, out OneOf remainder) +#if NET + public bool TryPickT2([NotNullWhen(true)] out T2? value, out OneOf remainder) +#else + public bool TryPickT2(out T2? value, out OneOf remainder) +#endif { value = IsT2 ? AsT2 : default; remainder = _index switch @@ -207,12 +221,16 @@ public bool TryPickT2(out T2 value, out OneOf remainder) 4 => AsT4, 5 => AsT5, 6 => AsT6, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT2; } - public bool TryPickT3(out T3 value, out OneOf remainder) +#if NET + public bool TryPickT3([NotNullWhen(true)] out T3? value, out OneOf remainder) +#else + public bool TryPickT3(out T3? value, out OneOf remainder) +#endif { value = IsT3 ? AsT3 : default; remainder = _index switch @@ -224,12 +242,16 @@ public bool TryPickT3(out T3 value, out OneOf remainder) 4 => AsT4, 5 => AsT5, 6 => AsT6, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT3; } - public bool TryPickT4(out T4 value, out OneOf remainder) +#if NET + public bool TryPickT4([NotNullWhen(true)] out T4? value, out OneOf remainder) +#else + public bool TryPickT4(out T4? value, out OneOf remainder) +#endif { value = IsT4 ? AsT4 : default; remainder = _index switch @@ -241,12 +263,16 @@ public bool TryPickT4(out T4 value, out OneOf remainder) 4 => default, 5 => AsT5, 6 => AsT6, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT4; } - public bool TryPickT5(out T5 value, out OneOf remainder) +#if NET + public bool TryPickT5([NotNullWhen(true)] out T5? value, out OneOf remainder) +#else + public bool TryPickT5(out T5? value, out OneOf remainder) +#endif { value = IsT5 ? AsT5 : default; remainder = _index switch @@ -258,12 +284,16 @@ public bool TryPickT5(out T5 value, out OneOf remainder) 4 => AsT4, 5 => default, 6 => AsT6, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT5; } - public bool TryPickT6(out T6 value, out OneOf remainder) +#if NET + public bool TryPickT6([NotNullWhen(true)] out T6? value, out OneOf remainder) +#else + public bool TryPickT6(out T6? value, out OneOf remainder) +#endif { value = IsT6 ? AsT6 : default; remainder = _index switch @@ -275,7 +305,7 @@ public bool TryPickT6(out T6 value, out OneOf remainder) 4 => AsT4, 5 => AsT5, 6 => default, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT6; } @@ -294,7 +324,7 @@ bool Equals(OneOfBase other) => _ => false }; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/OneOf/OneOfBaseT7.generated.cs b/OneOf/OneOfBaseT7.generated.cs index c30d6bf..2dde29d 100644 --- a/OneOf/OneOfBaseT7.generated.cs +++ b/OneOf/OneOfBaseT7.generated.cs @@ -1,18 +1,20 @@ +#nullable enable using System; +using System.Diagnostics.CodeAnalysis; using static OneOf.Functions; namespace OneOf { public class OneOfBase : IOneOf { - readonly T0 _value0; - readonly T1 _value1; - readonly T2 _value2; - readonly T3 _value3; - readonly T4 _value4; - readonly T5 _value5; - readonly T6 _value6; - readonly T7 _value7; + readonly T0 _value0 = default!; + readonly T1 _value1 = default!; + readonly T2 _value2 = default!; + readonly T3 _value3 = default!; + readonly T4 _value4 = default!; + readonly T5 _value5 = default!; + readonly T6 _value6 = default!; + readonly T7 _value7 = default!; readonly int _index; protected OneOfBase(OneOf input) @@ -28,11 +30,11 @@ protected OneOfBase(OneOf input) case 5: _value5 = input.AsT5; break; case 6: _value6 = input.AsT6; break; case 7: _value7 = input.AsT7; break; - default: throw new InvalidOperationException(); + default: throw InvalidIndexException(_index); } } - public object Value => + public object? Value => _index switch { 0 => _value0, @@ -43,7 +45,7 @@ protected OneOfBase(OneOf input) 5 => _value5, 6 => _value6, 7 => _value7, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; public int Index => _index; @@ -134,7 +136,7 @@ public void Switch(Action f0, Action f1, Action f2, Action f3, A f7(_value7); return; } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } public TResult Match(Func f0, Func f1, Func f2, Func f3, Func f4, Func f5, Func f6, Func f7) @@ -171,14 +173,18 @@ public TResult Match(Func f0, Func f1, Func remainder) +#if NET + public bool TryPickT0([NotNullWhen(true)] out T0? value, out OneOf remainder) +#else + public bool TryPickT0(out T0? value, out OneOf remainder) +#endif { value = IsT0 ? AsT0 : default; remainder = _index switch @@ -191,12 +197,16 @@ public bool TryPickT0(out T0 value, out OneOf remain 5 => AsT5, 6 => AsT6, 7 => AsT7, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT0; } - public bool TryPickT1(out T1 value, out OneOf remainder) +#if NET + public bool TryPickT1([NotNullWhen(true)] out T1? value, out OneOf remainder) +#else + public bool TryPickT1(out T1? value, out OneOf remainder) +#endif { value = IsT1 ? AsT1 : default; remainder = _index switch @@ -209,12 +219,16 @@ public bool TryPickT1(out T1 value, out OneOf remain 5 => AsT5, 6 => AsT6, 7 => AsT7, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT1; } - public bool TryPickT2(out T2 value, out OneOf remainder) +#if NET + public bool TryPickT2([NotNullWhen(true)] out T2? value, out OneOf remainder) +#else + public bool TryPickT2(out T2? value, out OneOf remainder) +#endif { value = IsT2 ? AsT2 : default; remainder = _index switch @@ -227,12 +241,16 @@ public bool TryPickT2(out T2 value, out OneOf remain 5 => AsT5, 6 => AsT6, 7 => AsT7, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT2; } - public bool TryPickT3(out T3 value, out OneOf remainder) +#if NET + public bool TryPickT3([NotNullWhen(true)] out T3? value, out OneOf remainder) +#else + public bool TryPickT3(out T3? value, out OneOf remainder) +#endif { value = IsT3 ? AsT3 : default; remainder = _index switch @@ -245,12 +263,16 @@ public bool TryPickT3(out T3 value, out OneOf remain 5 => AsT5, 6 => AsT6, 7 => AsT7, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT3; } - public bool TryPickT4(out T4 value, out OneOf remainder) +#if NET + public bool TryPickT4([NotNullWhen(true)] out T4? value, out OneOf remainder) +#else + public bool TryPickT4(out T4? value, out OneOf remainder) +#endif { value = IsT4 ? AsT4 : default; remainder = _index switch @@ -263,12 +285,16 @@ public bool TryPickT4(out T4 value, out OneOf remain 5 => AsT5, 6 => AsT6, 7 => AsT7, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT4; } - public bool TryPickT5(out T5 value, out OneOf remainder) +#if NET + public bool TryPickT5([NotNullWhen(true)] out T5? value, out OneOf remainder) +#else + public bool TryPickT5(out T5? value, out OneOf remainder) +#endif { value = IsT5 ? AsT5 : default; remainder = _index switch @@ -281,12 +307,16 @@ public bool TryPickT5(out T5 value, out OneOf remain 5 => default, 6 => AsT6, 7 => AsT7, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT5; } - public bool TryPickT6(out T6 value, out OneOf remainder) +#if NET + public bool TryPickT6([NotNullWhen(true)] out T6? value, out OneOf remainder) +#else + public bool TryPickT6(out T6? value, out OneOf remainder) +#endif { value = IsT6 ? AsT6 : default; remainder = _index switch @@ -299,12 +329,16 @@ public bool TryPickT6(out T6 value, out OneOf remain 5 => AsT5, 6 => default, 7 => AsT7, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT6; } - public bool TryPickT7(out T7 value, out OneOf remainder) +#if NET + public bool TryPickT7([NotNullWhen(true)] out T7? value, out OneOf remainder) +#else + public bool TryPickT7(out T7? value, out OneOf remainder) +#endif { value = IsT7 ? AsT7 : default; remainder = _index switch @@ -317,7 +351,7 @@ public bool TryPickT7(out T7 value, out OneOf remain 5 => AsT5, 6 => AsT6, 7 => default, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT7; } @@ -337,7 +371,7 @@ bool Equals(OneOfBase other) => _ => false }; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/OneOf/OneOfBaseT8.generated.cs b/OneOf/OneOfBaseT8.generated.cs index 5ee8beb..08a66db 100644 --- a/OneOf/OneOfBaseT8.generated.cs +++ b/OneOf/OneOfBaseT8.generated.cs @@ -1,19 +1,21 @@ +#nullable enable using System; +using System.Diagnostics.CodeAnalysis; using static OneOf.Functions; namespace OneOf { public class OneOfBase : IOneOf { - readonly T0 _value0; - readonly T1 _value1; - readonly T2 _value2; - readonly T3 _value3; - readonly T4 _value4; - readonly T5 _value5; - readonly T6 _value6; - readonly T7 _value7; - readonly T8 _value8; + readonly T0 _value0 = default!; + readonly T1 _value1 = default!; + readonly T2 _value2 = default!; + readonly T3 _value3 = default!; + readonly T4 _value4 = default!; + readonly T5 _value5 = default!; + readonly T6 _value6 = default!; + readonly T7 _value7 = default!; + readonly T8 _value8 = default!; readonly int _index; protected OneOfBase(OneOf input) @@ -30,11 +32,11 @@ protected OneOfBase(OneOf input) case 6: _value6 = input.AsT6; break; case 7: _value7 = input.AsT7; break; case 8: _value8 = input.AsT8; break; - default: throw new InvalidOperationException(); + default: throw InvalidIndexException(_index); } } - public object Value => + public object? Value => _index switch { 0 => _value0, @@ -46,7 +48,7 @@ protected OneOfBase(OneOf input) 6 => _value6, 7 => _value7, 8 => _value8, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; public int Index => _index; @@ -147,7 +149,7 @@ public void Switch(Action f0, Action f1, Action f2, Action f3, A f8(_value8); return; } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } public TResult Match(Func f0, Func f1, Func f2, Func f3, Func f4, Func f5, Func f6, Func f7, Func f8) @@ -188,14 +190,18 @@ public TResult Match(Func f0, Func f1, Func remainder) +#if NET + public bool TryPickT0([NotNullWhen(true)] out T0? value, out OneOf remainder) +#else + public bool TryPickT0(out T0? value, out OneOf remainder) +#endif { value = IsT0 ? AsT0 : default; remainder = _index switch @@ -209,12 +215,16 @@ public bool TryPickT0(out T0 value, out OneOf re 6 => AsT6, 7 => AsT7, 8 => AsT8, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT0; } - public bool TryPickT1(out T1 value, out OneOf remainder) +#if NET + public bool TryPickT1([NotNullWhen(true)] out T1? value, out OneOf remainder) +#else + public bool TryPickT1(out T1? value, out OneOf remainder) +#endif { value = IsT1 ? AsT1 : default; remainder = _index switch @@ -228,12 +238,16 @@ public bool TryPickT1(out T1 value, out OneOf re 6 => AsT6, 7 => AsT7, 8 => AsT8, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT1; } - public bool TryPickT2(out T2 value, out OneOf remainder) +#if NET + public bool TryPickT2([NotNullWhen(true)] out T2? value, out OneOf remainder) +#else + public bool TryPickT2(out T2? value, out OneOf remainder) +#endif { value = IsT2 ? AsT2 : default; remainder = _index switch @@ -247,12 +261,16 @@ public bool TryPickT2(out T2 value, out OneOf re 6 => AsT6, 7 => AsT7, 8 => AsT8, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT2; } - public bool TryPickT3(out T3 value, out OneOf remainder) +#if NET + public bool TryPickT3([NotNullWhen(true)] out T3? value, out OneOf remainder) +#else + public bool TryPickT3(out T3? value, out OneOf remainder) +#endif { value = IsT3 ? AsT3 : default; remainder = _index switch @@ -266,12 +284,16 @@ public bool TryPickT3(out T3 value, out OneOf re 6 => AsT6, 7 => AsT7, 8 => AsT8, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT3; } - public bool TryPickT4(out T4 value, out OneOf remainder) +#if NET + public bool TryPickT4([NotNullWhen(true)] out T4? value, out OneOf remainder) +#else + public bool TryPickT4(out T4? value, out OneOf remainder) +#endif { value = IsT4 ? AsT4 : default; remainder = _index switch @@ -285,12 +307,16 @@ public bool TryPickT4(out T4 value, out OneOf re 6 => AsT6, 7 => AsT7, 8 => AsT8, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT4; } - public bool TryPickT5(out T5 value, out OneOf remainder) +#if NET + public bool TryPickT5([NotNullWhen(true)] out T5? value, out OneOf remainder) +#else + public bool TryPickT5(out T5? value, out OneOf remainder) +#endif { value = IsT5 ? AsT5 : default; remainder = _index switch @@ -304,12 +330,16 @@ public bool TryPickT5(out T5 value, out OneOf re 6 => AsT6, 7 => AsT7, 8 => AsT8, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT5; } - public bool TryPickT6(out T6 value, out OneOf remainder) +#if NET + public bool TryPickT6([NotNullWhen(true)] out T6? value, out OneOf remainder) +#else + public bool TryPickT6(out T6? value, out OneOf remainder) +#endif { value = IsT6 ? AsT6 : default; remainder = _index switch @@ -323,12 +353,16 @@ public bool TryPickT6(out T6 value, out OneOf re 6 => default, 7 => AsT7, 8 => AsT8, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT6; } - public bool TryPickT7(out T7 value, out OneOf remainder) +#if NET + public bool TryPickT7([NotNullWhen(true)] out T7? value, out OneOf remainder) +#else + public bool TryPickT7(out T7? value, out OneOf remainder) +#endif { value = IsT7 ? AsT7 : default; remainder = _index switch @@ -342,12 +376,16 @@ public bool TryPickT7(out T7 value, out OneOf re 6 => AsT6, 7 => default, 8 => AsT8, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT7; } - public bool TryPickT8(out T8 value, out OneOf remainder) +#if NET + public bool TryPickT8([NotNullWhen(true)] out T8? value, out OneOf remainder) +#else + public bool TryPickT8(out T8? value, out OneOf remainder) +#endif { value = IsT8 ? AsT8 : default; remainder = _index switch @@ -361,7 +399,7 @@ public bool TryPickT8(out T8 value, out OneOf re 6 => AsT6, 7 => AsT7, 8 => default, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT8; } @@ -382,7 +420,7 @@ bool Equals(OneOfBase other) => _ => false }; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/OneOf/OneOfT0.generated.cs b/OneOf/OneOfT0.generated.cs index 1f3090b..e473316 100644 --- a/OneOf/OneOfT0.generated.cs +++ b/OneOf/OneOfT0.generated.cs @@ -1,4 +1,6 @@ +#nullable enable using System; +using System.Diagnostics.CodeAnalysis; using static OneOf.Functions; namespace OneOf @@ -8,17 +10,17 @@ namespace OneOf readonly T0 _value0; readonly int _index; - OneOf(int index, T0 value0 = default) + OneOf(int index, T0 value0 = default!) { _index = index; _value0 = value0; } - public object Value => + public object? Value => _index switch { 0 => _value0, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; public int Index => _index; @@ -39,7 +41,7 @@ public void Switch(Action f0) f0(_value0); return; } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } public TResult Match(Func f0) @@ -48,7 +50,7 @@ public TResult Match(Func f0) { return f0(_value0); } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } public static OneOf FromT0(T0 input) => input; @@ -63,7 +65,7 @@ public OneOf MapT0(Func mapFunc) return _index switch { 0 => mapFunc(AsT0), - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -75,7 +77,7 @@ bool Equals(OneOf other) => _ => false }; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/OneOf/OneOfT1.generated.cs b/OneOf/OneOfT1.generated.cs index e6b645c..f182065 100644 --- a/OneOf/OneOfT1.generated.cs +++ b/OneOf/OneOfT1.generated.cs @@ -1,4 +1,6 @@ +#nullable enable using System; +using System.Diagnostics.CodeAnalysis; using static OneOf.Functions; namespace OneOf @@ -9,19 +11,19 @@ namespace OneOf readonly T1 _value1; readonly int _index; - OneOf(int index, T0 value0 = default, T1 value1 = default) + OneOf(int index, T0 value0 = default!, T1 value1 = default!) { _index = index; _value0 = value0; _value1 = value1; } - public object Value => + public object? Value => _index switch { 0 => _value0, 1 => _value1, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; public int Index => _index; @@ -53,7 +55,7 @@ public void Switch(Action f0, Action f1) f1(_value1); return; } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } public TResult Match(Func f0, Func f1) @@ -66,7 +68,7 @@ public TResult Match(Func f0, Func f1) { return f1(_value1); } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } public static OneOf FromT0(T0 input) => input; @@ -83,7 +85,7 @@ public OneOf MapT0(Func mapFunc) { 0 => mapFunc(AsT0), 1 => AsT1, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -97,30 +99,38 @@ public OneOf MapT1(Func mapFunc) { 0 => AsT0, 1 => mapFunc(AsT1), - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } - public bool TryPickT0(out T0 value, out T1 remainder) +#if NET + public bool TryPickT0([NotNullWhen(true)] out T0? value, [NotNullWhen(false)] out T1? remainder) +#else + public bool TryPickT0(out T0? value, out T1? remainder) +#endif { value = IsT0 ? AsT0 : default; remainder = _index switch { 0 => default, 1 => AsT1, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT0; } - public bool TryPickT1(out T1 value, out T0 remainder) +#if NET + public bool TryPickT1([NotNullWhen(true)] out T1? value, [NotNullWhen(false)] out T0? remainder) +#else + public bool TryPickT1(out T1? value, out T0? remainder) +#endif { value = IsT1 ? AsT1 : default; remainder = _index switch { 0 => AsT0, 1 => default, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT1; } @@ -134,7 +144,7 @@ bool Equals(OneOf other) => _ => false }; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/OneOf/OneOfT2.generated.cs b/OneOf/OneOfT2.generated.cs index 9e4e68c..d9f8be3 100644 --- a/OneOf/OneOfT2.generated.cs +++ b/OneOf/OneOfT2.generated.cs @@ -1,4 +1,6 @@ +#nullable enable using System; +using System.Diagnostics.CodeAnalysis; using static OneOf.Functions; namespace OneOf @@ -10,7 +12,7 @@ namespace OneOf readonly T2 _value2; readonly int _index; - OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default) + OneOf(int index, T0 value0 = default!, T1 value1 = default!, T2 value2 = default!) { _index = index; _value0 = value0; @@ -18,13 +20,13 @@ namespace OneOf _value2 = value2; } - public object Value => + public object? Value => _index switch { 0 => _value0, 1 => _value1, 2 => _value2, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; public int Index => _index; @@ -67,7 +69,7 @@ public void Switch(Action f0, Action f1, Action f2) f2(_value2); return; } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } public TResult Match(Func f0, Func f1, Func f2) @@ -84,7 +86,7 @@ public TResult Match(Func f0, Func f1, Func FromT0(T0 input) => input; @@ -103,7 +105,7 @@ public OneOf MapT0(Func mapFunc) 0 => mapFunc(AsT0), 1 => AsT1, 2 => AsT2, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -118,7 +120,7 @@ public OneOf MapT1(Func mapFunc) 0 => AsT0, 1 => mapFunc(AsT1), 2 => AsT2, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -133,11 +135,15 @@ public OneOf MapT2(Func mapFunc) 0 => AsT0, 1 => AsT1, 2 => mapFunc(AsT2), - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } - public bool TryPickT0(out T0 value, out OneOf remainder) +#if NET + public bool TryPickT0([NotNullWhen(true)] out T0? value, out OneOf remainder) +#else + public bool TryPickT0(out T0? value, out OneOf remainder) +#endif { value = IsT0 ? AsT0 : default; remainder = _index switch @@ -145,12 +151,16 @@ public bool TryPickT0(out T0 value, out OneOf remainder) 0 => default, 1 => AsT1, 2 => AsT2, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT0; } - public bool TryPickT1(out T1 value, out OneOf remainder) +#if NET + public bool TryPickT1([NotNullWhen(true)] out T1? value, out OneOf remainder) +#else + public bool TryPickT1(out T1? value, out OneOf remainder) +#endif { value = IsT1 ? AsT1 : default; remainder = _index switch @@ -158,12 +168,16 @@ public bool TryPickT1(out T1 value, out OneOf remainder) 0 => AsT0, 1 => default, 2 => AsT2, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT1; } - public bool TryPickT2(out T2 value, out OneOf remainder) +#if NET + public bool TryPickT2([NotNullWhen(true)] out T2? value, out OneOf remainder) +#else + public bool TryPickT2(out T2? value, out OneOf remainder) +#endif { value = IsT2 ? AsT2 : default; remainder = _index switch @@ -171,7 +185,7 @@ public bool TryPickT2(out T2 value, out OneOf remainder) 0 => AsT0, 1 => AsT1, 2 => default, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT2; } @@ -186,7 +200,7 @@ bool Equals(OneOf other) => _ => false }; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/OneOf/OneOfT3.generated.cs b/OneOf/OneOfT3.generated.cs index b6556fc..719e6c1 100644 --- a/OneOf/OneOfT3.generated.cs +++ b/OneOf/OneOfT3.generated.cs @@ -1,4 +1,6 @@ +#nullable enable using System; +using System.Diagnostics.CodeAnalysis; using static OneOf.Functions; namespace OneOf @@ -11,7 +13,7 @@ namespace OneOf readonly T3 _value3; readonly int _index; - OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default) + OneOf(int index, T0 value0 = default!, T1 value1 = default!, T2 value2 = default!, T3 value3 = default!) { _index = index; _value0 = value0; @@ -20,14 +22,14 @@ namespace OneOf _value3 = value3; } - public object Value => + public object? Value => _index switch { 0 => _value0, 1 => _value1, 2 => _value2, 3 => _value3, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; public int Index => _index; @@ -81,7 +83,7 @@ public void Switch(Action f0, Action f1, Action f2, Action f3) f3(_value3); return; } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } public TResult Match(Func f0, Func f1, Func f2, Func f3) @@ -102,7 +104,7 @@ public TResult Match(Func f0, Func f1, Func FromT0(T0 input) => input; @@ -123,7 +125,7 @@ public OneOf MapT0(Func mapFunc) 1 => AsT1, 2 => AsT2, 3 => AsT3, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -139,7 +141,7 @@ public OneOf MapT1(Func mapFunc) 1 => mapFunc(AsT1), 2 => AsT2, 3 => AsT3, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -155,7 +157,7 @@ public OneOf MapT2(Func mapFunc) 1 => AsT1, 2 => mapFunc(AsT2), 3 => AsT3, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -171,11 +173,15 @@ public OneOf MapT3(Func mapFunc) 1 => AsT1, 2 => AsT2, 3 => mapFunc(AsT3), - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } - public bool TryPickT0(out T0 value, out OneOf remainder) +#if NET + public bool TryPickT0([NotNullWhen(true)] out T0? value, out OneOf remainder) +#else + public bool TryPickT0(out T0? value, out OneOf remainder) +#endif { value = IsT0 ? AsT0 : default; remainder = _index switch @@ -184,12 +190,16 @@ public bool TryPickT0(out T0 value, out OneOf remainder) 1 => AsT1, 2 => AsT2, 3 => AsT3, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT0; } - public bool TryPickT1(out T1 value, out OneOf remainder) +#if NET + public bool TryPickT1([NotNullWhen(true)] out T1? value, out OneOf remainder) +#else + public bool TryPickT1(out T1? value, out OneOf remainder) +#endif { value = IsT1 ? AsT1 : default; remainder = _index switch @@ -198,12 +208,16 @@ public bool TryPickT1(out T1 value, out OneOf remainder) 1 => default, 2 => AsT2, 3 => AsT3, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT1; } - public bool TryPickT2(out T2 value, out OneOf remainder) +#if NET + public bool TryPickT2([NotNullWhen(true)] out T2? value, out OneOf remainder) +#else + public bool TryPickT2(out T2? value, out OneOf remainder) +#endif { value = IsT2 ? AsT2 : default; remainder = _index switch @@ -212,12 +226,16 @@ public bool TryPickT2(out T2 value, out OneOf remainder) 1 => AsT1, 2 => default, 3 => AsT3, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT2; } - public bool TryPickT3(out T3 value, out OneOf remainder) +#if NET + public bool TryPickT3([NotNullWhen(true)] out T3? value, out OneOf remainder) +#else + public bool TryPickT3(out T3? value, out OneOf remainder) +#endif { value = IsT3 ? AsT3 : default; remainder = _index switch @@ -226,7 +244,7 @@ public bool TryPickT3(out T3 value, out OneOf remainder) 1 => AsT1, 2 => AsT2, 3 => default, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT3; } @@ -242,7 +260,7 @@ bool Equals(OneOf other) => _ => false }; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/OneOf/OneOfT4.generated.cs b/OneOf/OneOfT4.generated.cs index 38245fb..3abec23 100644 --- a/OneOf/OneOfT4.generated.cs +++ b/OneOf/OneOfT4.generated.cs @@ -1,4 +1,6 @@ +#nullable enable using System; +using System.Diagnostics.CodeAnalysis; using static OneOf.Functions; namespace OneOf @@ -12,7 +14,7 @@ namespace OneOf readonly T4 _value4; readonly int _index; - OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default) + OneOf(int index, T0 value0 = default!, T1 value1 = default!, T2 value2 = default!, T3 value3 = default!, T4 value4 = default!) { _index = index; _value0 = value0; @@ -22,7 +24,7 @@ namespace OneOf _value4 = value4; } - public object Value => + public object? Value => _index switch { 0 => _value0, @@ -30,7 +32,7 @@ namespace OneOf 2 => _value2, 3 => _value3, 4 => _value4, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; public int Index => _index; @@ -95,7 +97,7 @@ public void Switch(Action f0, Action f1, Action f2, Action f3, A f4(_value4); return; } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } public TResult Match(Func f0, Func f1, Func f2, Func f3, Func f4) @@ -120,7 +122,7 @@ public TResult Match(Func f0, Func f1, Func FromT0(T0 input) => input; @@ -143,7 +145,7 @@ public OneOf MapT0(Func mapFunc) 2 => AsT2, 3 => AsT3, 4 => AsT4, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -160,7 +162,7 @@ public OneOf MapT1(Func mapFunc) 2 => AsT2, 3 => AsT3, 4 => AsT4, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -177,7 +179,7 @@ public OneOf MapT2(Func mapFunc) 2 => mapFunc(AsT2), 3 => AsT3, 4 => AsT4, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -194,7 +196,7 @@ public OneOf MapT3(Func mapFunc) 2 => AsT2, 3 => mapFunc(AsT3), 4 => AsT4, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -211,11 +213,15 @@ public OneOf MapT4(Func mapFunc) 2 => AsT2, 3 => AsT3, 4 => mapFunc(AsT4), - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } - public bool TryPickT0(out T0 value, out OneOf remainder) +#if NET + public bool TryPickT0([NotNullWhen(true)] out T0? value, out OneOf remainder) +#else + public bool TryPickT0(out T0? value, out OneOf remainder) +#endif { value = IsT0 ? AsT0 : default; remainder = _index switch @@ -225,12 +231,16 @@ public bool TryPickT0(out T0 value, out OneOf remainder) 2 => AsT2, 3 => AsT3, 4 => AsT4, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT0; } - public bool TryPickT1(out T1 value, out OneOf remainder) +#if NET + public bool TryPickT1([NotNullWhen(true)] out T1? value, out OneOf remainder) +#else + public bool TryPickT1(out T1? value, out OneOf remainder) +#endif { value = IsT1 ? AsT1 : default; remainder = _index switch @@ -240,12 +250,16 @@ public bool TryPickT1(out T1 value, out OneOf remainder) 2 => AsT2, 3 => AsT3, 4 => AsT4, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT1; } - public bool TryPickT2(out T2 value, out OneOf remainder) +#if NET + public bool TryPickT2([NotNullWhen(true)] out T2? value, out OneOf remainder) +#else + public bool TryPickT2(out T2? value, out OneOf remainder) +#endif { value = IsT2 ? AsT2 : default; remainder = _index switch @@ -255,12 +269,16 @@ public bool TryPickT2(out T2 value, out OneOf remainder) 2 => default, 3 => AsT3, 4 => AsT4, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT2; } - public bool TryPickT3(out T3 value, out OneOf remainder) +#if NET + public bool TryPickT3([NotNullWhen(true)] out T3? value, out OneOf remainder) +#else + public bool TryPickT3(out T3? value, out OneOf remainder) +#endif { value = IsT3 ? AsT3 : default; remainder = _index switch @@ -270,12 +288,16 @@ public bool TryPickT3(out T3 value, out OneOf remainder) 2 => AsT2, 3 => default, 4 => AsT4, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT3; } - public bool TryPickT4(out T4 value, out OneOf remainder) +#if NET + public bool TryPickT4([NotNullWhen(true)] out T4? value, out OneOf remainder) +#else + public bool TryPickT4(out T4? value, out OneOf remainder) +#endif { value = IsT4 ? AsT4 : default; remainder = _index switch @@ -285,7 +307,7 @@ public bool TryPickT4(out T4 value, out OneOf remainder) 2 => AsT2, 3 => AsT3, 4 => default, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT4; } @@ -302,7 +324,7 @@ bool Equals(OneOf other) => _ => false }; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/OneOf/OneOfT5.generated.cs b/OneOf/OneOfT5.generated.cs index 83ac23e..de2e1d4 100644 --- a/OneOf/OneOfT5.generated.cs +++ b/OneOf/OneOfT5.generated.cs @@ -1,4 +1,6 @@ +#nullable enable using System; +using System.Diagnostics.CodeAnalysis; using static OneOf.Functions; namespace OneOf @@ -13,7 +15,7 @@ namespace OneOf readonly T5 _value5; readonly int _index; - OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default) + OneOf(int index, T0 value0 = default!, T1 value1 = default!, T2 value2 = default!, T3 value3 = default!, T4 value4 = default!, T5 value5 = default!) { _index = index; _value0 = value0; @@ -24,7 +26,7 @@ namespace OneOf _value5 = value5; } - public object Value => + public object? Value => _index switch { 0 => _value0, @@ -33,7 +35,7 @@ namespace OneOf 3 => _value3, 4 => _value4, 5 => _value5, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; public int Index => _index; @@ -109,7 +111,7 @@ public void Switch(Action f0, Action f1, Action f2, Action f3, A f5(_value5); return; } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } public TResult Match(Func f0, Func f1, Func f2, Func f3, Func f4, Func f5) @@ -138,7 +140,7 @@ public TResult Match(Func f0, Func f1, Func FromT0(T0 input) => input; @@ -163,7 +165,7 @@ public OneOf MapT0(Func mapFu 3 => AsT3, 4 => AsT4, 5 => AsT5, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -181,7 +183,7 @@ public OneOf MapT1(Func mapFu 3 => AsT3, 4 => AsT4, 5 => AsT5, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -199,7 +201,7 @@ public OneOf MapT2(Func mapFu 3 => AsT3, 4 => AsT4, 5 => AsT5, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -217,7 +219,7 @@ public OneOf MapT3(Func mapFu 3 => mapFunc(AsT3), 4 => AsT4, 5 => AsT5, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -235,7 +237,7 @@ public OneOf MapT4(Func mapFu 3 => AsT3, 4 => mapFunc(AsT4), 5 => AsT5, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -253,11 +255,15 @@ public OneOf MapT5(Func mapFu 3 => AsT3, 4 => AsT4, 5 => mapFunc(AsT5), - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } - public bool TryPickT0(out T0 value, out OneOf remainder) +#if NET + public bool TryPickT0([NotNullWhen(true)] out T0? value, out OneOf remainder) +#else + public bool TryPickT0(out T0? value, out OneOf remainder) +#endif { value = IsT0 ? AsT0 : default; remainder = _index switch @@ -268,12 +274,16 @@ public bool TryPickT0(out T0 value, out OneOf remainder) 3 => AsT3, 4 => AsT4, 5 => AsT5, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT0; } - public bool TryPickT1(out T1 value, out OneOf remainder) +#if NET + public bool TryPickT1([NotNullWhen(true)] out T1? value, out OneOf remainder) +#else + public bool TryPickT1(out T1? value, out OneOf remainder) +#endif { value = IsT1 ? AsT1 : default; remainder = _index switch @@ -284,12 +294,16 @@ public bool TryPickT1(out T1 value, out OneOf remainder) 3 => AsT3, 4 => AsT4, 5 => AsT5, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT1; } - public bool TryPickT2(out T2 value, out OneOf remainder) +#if NET + public bool TryPickT2([NotNullWhen(true)] out T2? value, out OneOf remainder) +#else + public bool TryPickT2(out T2? value, out OneOf remainder) +#endif { value = IsT2 ? AsT2 : default; remainder = _index switch @@ -300,12 +314,16 @@ public bool TryPickT2(out T2 value, out OneOf remainder) 3 => AsT3, 4 => AsT4, 5 => AsT5, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT2; } - public bool TryPickT3(out T3 value, out OneOf remainder) +#if NET + public bool TryPickT3([NotNullWhen(true)] out T3? value, out OneOf remainder) +#else + public bool TryPickT3(out T3? value, out OneOf remainder) +#endif { value = IsT3 ? AsT3 : default; remainder = _index switch @@ -316,12 +334,16 @@ public bool TryPickT3(out T3 value, out OneOf remainder) 3 => default, 4 => AsT4, 5 => AsT5, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT3; } - public bool TryPickT4(out T4 value, out OneOf remainder) +#if NET + public bool TryPickT4([NotNullWhen(true)] out T4? value, out OneOf remainder) +#else + public bool TryPickT4(out T4? value, out OneOf remainder) +#endif { value = IsT4 ? AsT4 : default; remainder = _index switch @@ -332,12 +354,16 @@ public bool TryPickT4(out T4 value, out OneOf remainder) 3 => AsT3, 4 => default, 5 => AsT5, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT4; } - public bool TryPickT5(out T5 value, out OneOf remainder) +#if NET + public bool TryPickT5([NotNullWhen(true)] out T5? value, out OneOf remainder) +#else + public bool TryPickT5(out T5? value, out OneOf remainder) +#endif { value = IsT5 ? AsT5 : default; remainder = _index switch @@ -348,7 +374,7 @@ public bool TryPickT5(out T5 value, out OneOf remainder) 3 => AsT3, 4 => AsT4, 5 => default, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT5; } @@ -366,7 +392,7 @@ bool Equals(OneOf other) => _ => false }; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/OneOf/OneOfT6.generated.cs b/OneOf/OneOfT6.generated.cs index 9922c8a..be92d4c 100644 --- a/OneOf/OneOfT6.generated.cs +++ b/OneOf/OneOfT6.generated.cs @@ -1,4 +1,6 @@ +#nullable enable using System; +using System.Diagnostics.CodeAnalysis; using static OneOf.Functions; namespace OneOf @@ -14,7 +16,7 @@ namespace OneOf readonly T6 _value6; readonly int _index; - OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default) + OneOf(int index, T0 value0 = default!, T1 value1 = default!, T2 value2 = default!, T3 value3 = default!, T4 value4 = default!, T5 value5 = default!, T6 value6 = default!) { _index = index; _value0 = value0; @@ -26,7 +28,7 @@ namespace OneOf _value6 = value6; } - public object Value => + public object? Value => _index switch { 0 => _value0, @@ -36,7 +38,7 @@ namespace OneOf 4 => _value4, 5 => _value5, 6 => _value6, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; public int Index => _index; @@ -123,7 +125,7 @@ public void Switch(Action f0, Action f1, Action f2, Action f3, A f6(_value6); return; } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } public TResult Match(Func f0, Func f1, Func f2, Func f3, Func f4, Func f5, Func f6) @@ -156,7 +158,7 @@ public TResult Match(Func f0, Func f1, Func FromT0(T0 input) => input; @@ -183,7 +185,7 @@ public OneOf MapT0(Func m 4 => AsT4, 5 => AsT5, 6 => AsT6, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -202,7 +204,7 @@ public OneOf MapT1(Func m 4 => AsT4, 5 => AsT5, 6 => AsT6, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -221,7 +223,7 @@ public OneOf MapT2(Func m 4 => AsT4, 5 => AsT5, 6 => AsT6, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -240,7 +242,7 @@ public OneOf MapT3(Func m 4 => AsT4, 5 => AsT5, 6 => AsT6, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -259,7 +261,7 @@ public OneOf MapT4(Func m 4 => mapFunc(AsT4), 5 => AsT5, 6 => AsT6, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -278,7 +280,7 @@ public OneOf MapT5(Func m 4 => AsT4, 5 => mapFunc(AsT5), 6 => AsT6, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -297,11 +299,15 @@ public OneOf MapT6(Func m 4 => AsT4, 5 => AsT5, 6 => mapFunc(AsT6), - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } - public bool TryPickT0(out T0 value, out OneOf remainder) +#if NET + public bool TryPickT0([NotNullWhen(true)] out T0? value, out OneOf remainder) +#else + public bool TryPickT0(out T0? value, out OneOf remainder) +#endif { value = IsT0 ? AsT0 : default; remainder = _index switch @@ -313,12 +319,16 @@ public bool TryPickT0(out T0 value, out OneOf remainder) 4 => AsT4, 5 => AsT5, 6 => AsT6, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT0; } - public bool TryPickT1(out T1 value, out OneOf remainder) +#if NET + public bool TryPickT1([NotNullWhen(true)] out T1? value, out OneOf remainder) +#else + public bool TryPickT1(out T1? value, out OneOf remainder) +#endif { value = IsT1 ? AsT1 : default; remainder = _index switch @@ -330,12 +340,16 @@ public bool TryPickT1(out T1 value, out OneOf remainder) 4 => AsT4, 5 => AsT5, 6 => AsT6, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT1; } - public bool TryPickT2(out T2 value, out OneOf remainder) +#if NET + public bool TryPickT2([NotNullWhen(true)] out T2? value, out OneOf remainder) +#else + public bool TryPickT2(out T2? value, out OneOf remainder) +#endif { value = IsT2 ? AsT2 : default; remainder = _index switch @@ -347,12 +361,16 @@ public bool TryPickT2(out T2 value, out OneOf remainder) 4 => AsT4, 5 => AsT5, 6 => AsT6, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT2; } - public bool TryPickT3(out T3 value, out OneOf remainder) +#if NET + public bool TryPickT3([NotNullWhen(true)] out T3? value, out OneOf remainder) +#else + public bool TryPickT3(out T3? value, out OneOf remainder) +#endif { value = IsT3 ? AsT3 : default; remainder = _index switch @@ -364,12 +382,16 @@ public bool TryPickT3(out T3 value, out OneOf remainder) 4 => AsT4, 5 => AsT5, 6 => AsT6, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT3; } - public bool TryPickT4(out T4 value, out OneOf remainder) +#if NET + public bool TryPickT4([NotNullWhen(true)] out T4? value, out OneOf remainder) +#else + public bool TryPickT4(out T4? value, out OneOf remainder) +#endif { value = IsT4 ? AsT4 : default; remainder = _index switch @@ -381,12 +403,16 @@ public bool TryPickT4(out T4 value, out OneOf remainder) 4 => default, 5 => AsT5, 6 => AsT6, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT4; } - public bool TryPickT5(out T5 value, out OneOf remainder) +#if NET + public bool TryPickT5([NotNullWhen(true)] out T5? value, out OneOf remainder) +#else + public bool TryPickT5(out T5? value, out OneOf remainder) +#endif { value = IsT5 ? AsT5 : default; remainder = _index switch @@ -398,12 +424,16 @@ public bool TryPickT5(out T5 value, out OneOf remainder) 4 => AsT4, 5 => default, 6 => AsT6, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT5; } - public bool TryPickT6(out T6 value, out OneOf remainder) +#if NET + public bool TryPickT6([NotNullWhen(true)] out T6? value, out OneOf remainder) +#else + public bool TryPickT6(out T6? value, out OneOf remainder) +#endif { value = IsT6 ? AsT6 : default; remainder = _index switch @@ -415,7 +445,7 @@ public bool TryPickT6(out T6 value, out OneOf remainder) 4 => AsT4, 5 => AsT5, 6 => default, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT6; } @@ -434,7 +464,7 @@ bool Equals(OneOf other) => _ => false }; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/OneOf/OneOfT7.generated.cs b/OneOf/OneOfT7.generated.cs index c0b0160..3a822d2 100644 --- a/OneOf/OneOfT7.generated.cs +++ b/OneOf/OneOfT7.generated.cs @@ -1,4 +1,6 @@ +#nullable enable using System; +using System.Diagnostics.CodeAnalysis; using static OneOf.Functions; namespace OneOf @@ -15,7 +17,7 @@ namespace OneOf readonly T7 _value7; readonly int _index; - OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default) + OneOf(int index, T0 value0 = default!, T1 value1 = default!, T2 value2 = default!, T3 value3 = default!, T4 value4 = default!, T5 value5 = default!, T6 value6 = default!, T7 value7 = default!) { _index = index; _value0 = value0; @@ -28,7 +30,7 @@ namespace OneOf _value7 = value7; } - public object Value => + public object? Value => _index switch { 0 => _value0, @@ -39,7 +41,7 @@ namespace OneOf 5 => _value5, 6 => _value6, 7 => _value7, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; public int Index => _index; @@ -137,7 +139,7 @@ public void Switch(Action f0, Action f1, Action f2, Action f3, A f7(_value7); return; } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } public TResult Match(Func f0, Func f1, Func f2, Func f3, Func f4, Func f5, Func f6, Func f7) @@ -174,7 +176,7 @@ public TResult Match(Func f0, Func f1, Func FromT0(T0 input) => input; @@ -203,7 +205,7 @@ public OneOf MapT0(Func AsT5, 6 => AsT6, 7 => AsT7, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -223,7 +225,7 @@ public OneOf MapT1(Func AsT5, 6 => AsT6, 7 => AsT7, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -243,7 +245,7 @@ public OneOf MapT2(Func AsT5, 6 => AsT6, 7 => AsT7, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -263,7 +265,7 @@ public OneOf MapT3(Func AsT5, 6 => AsT6, 7 => AsT7, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -283,7 +285,7 @@ public OneOf MapT4(Func AsT5, 6 => AsT6, 7 => AsT7, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -303,7 +305,7 @@ public OneOf MapT5(Func mapFunc(AsT5), 6 => AsT6, 7 => AsT7, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -323,7 +325,7 @@ public OneOf MapT6(Func AsT5, 6 => mapFunc(AsT6), 7 => AsT7, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -343,11 +345,15 @@ public OneOf MapT7(Func AsT5, 6 => AsT6, 7 => mapFunc(AsT7), - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } - public bool TryPickT0(out T0 value, out OneOf remainder) +#if NET + public bool TryPickT0([NotNullWhen(true)] out T0? value, out OneOf remainder) +#else + public bool TryPickT0(out T0? value, out OneOf remainder) +#endif { value = IsT0 ? AsT0 : default; remainder = _index switch @@ -360,12 +366,16 @@ public bool TryPickT0(out T0 value, out OneOf remain 5 => AsT5, 6 => AsT6, 7 => AsT7, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT0; } - public bool TryPickT1(out T1 value, out OneOf remainder) +#if NET + public bool TryPickT1([NotNullWhen(true)] out T1? value, out OneOf remainder) +#else + public bool TryPickT1(out T1? value, out OneOf remainder) +#endif { value = IsT1 ? AsT1 : default; remainder = _index switch @@ -378,12 +388,16 @@ public bool TryPickT1(out T1 value, out OneOf remain 5 => AsT5, 6 => AsT6, 7 => AsT7, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT1; } - public bool TryPickT2(out T2 value, out OneOf remainder) +#if NET + public bool TryPickT2([NotNullWhen(true)] out T2? value, out OneOf remainder) +#else + public bool TryPickT2(out T2? value, out OneOf remainder) +#endif { value = IsT2 ? AsT2 : default; remainder = _index switch @@ -396,12 +410,16 @@ public bool TryPickT2(out T2 value, out OneOf remain 5 => AsT5, 6 => AsT6, 7 => AsT7, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT2; } - public bool TryPickT3(out T3 value, out OneOf remainder) +#if NET + public bool TryPickT3([NotNullWhen(true)] out T3? value, out OneOf remainder) +#else + public bool TryPickT3(out T3? value, out OneOf remainder) +#endif { value = IsT3 ? AsT3 : default; remainder = _index switch @@ -414,12 +432,16 @@ public bool TryPickT3(out T3 value, out OneOf remain 5 => AsT5, 6 => AsT6, 7 => AsT7, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT3; } - public bool TryPickT4(out T4 value, out OneOf remainder) +#if NET + public bool TryPickT4([NotNullWhen(true)] out T4? value, out OneOf remainder) +#else + public bool TryPickT4(out T4? value, out OneOf remainder) +#endif { value = IsT4 ? AsT4 : default; remainder = _index switch @@ -432,12 +454,16 @@ public bool TryPickT4(out T4 value, out OneOf remain 5 => AsT5, 6 => AsT6, 7 => AsT7, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT4; } - public bool TryPickT5(out T5 value, out OneOf remainder) +#if NET + public bool TryPickT5([NotNullWhen(true)] out T5? value, out OneOf remainder) +#else + public bool TryPickT5(out T5? value, out OneOf remainder) +#endif { value = IsT5 ? AsT5 : default; remainder = _index switch @@ -450,12 +476,16 @@ public bool TryPickT5(out T5 value, out OneOf remain 5 => default, 6 => AsT6, 7 => AsT7, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT5; } - public bool TryPickT6(out T6 value, out OneOf remainder) +#if NET + public bool TryPickT6([NotNullWhen(true)] out T6? value, out OneOf remainder) +#else + public bool TryPickT6(out T6? value, out OneOf remainder) +#endif { value = IsT6 ? AsT6 : default; remainder = _index switch @@ -468,12 +498,16 @@ public bool TryPickT6(out T6 value, out OneOf remain 5 => AsT5, 6 => default, 7 => AsT7, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT6; } - public bool TryPickT7(out T7 value, out OneOf remainder) +#if NET + public bool TryPickT7([NotNullWhen(true)] out T7? value, out OneOf remainder) +#else + public bool TryPickT7(out T7? value, out OneOf remainder) +#endif { value = IsT7 ? AsT7 : default; remainder = _index switch @@ -486,7 +520,7 @@ public bool TryPickT7(out T7 value, out OneOf remain 5 => AsT5, 6 => AsT6, 7 => default, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT7; } @@ -506,7 +540,7 @@ bool Equals(OneOf other) => _ => false }; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/OneOf/OneOfT8.generated.cs b/OneOf/OneOfT8.generated.cs index e040095..9fecb31 100644 --- a/OneOf/OneOfT8.generated.cs +++ b/OneOf/OneOfT8.generated.cs @@ -1,4 +1,6 @@ +#nullable enable using System; +using System.Diagnostics.CodeAnalysis; using static OneOf.Functions; namespace OneOf @@ -16,7 +18,7 @@ namespace OneOf readonly T8 _value8; readonly int _index; - OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default) + OneOf(int index, T0 value0 = default!, T1 value1 = default!, T2 value2 = default!, T3 value3 = default!, T4 value4 = default!, T5 value5 = default!, T6 value6 = default!, T7 value7 = default!, T8 value8 = default!) { _index = index; _value0 = value0; @@ -30,7 +32,7 @@ namespace OneOf _value8 = value8; } - public object Value => + public object? Value => _index switch { 0 => _value0, @@ -42,7 +44,7 @@ namespace OneOf 6 => _value6, 7 => _value7, 8 => _value8, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; public int Index => _index; @@ -151,7 +153,7 @@ public void Switch(Action f0, Action f1, Action f2, Action f3, A f8(_value8); return; } - throw new InvalidOperationException(); + throw InvalidIndexException(_index); } public TResult Match(Func f0, Func f1, Func f2, Func f3, Func f4, Func f5, Func f6, Func f7, Func f8) @@ -192,7 +194,7 @@ public TResult Match(Func f0, Func f1, Func FromT0(T0 input) => input; @@ -223,7 +225,7 @@ public OneOf MapT0(Func AsT6, 7 => AsT7, 8 => AsT8, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -244,7 +246,7 @@ public OneOf MapT1(Func AsT6, 7 => AsT7, 8 => AsT8, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -265,7 +267,7 @@ public OneOf MapT2(Func AsT6, 7 => AsT7, 8 => AsT8, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -286,7 +288,7 @@ public OneOf MapT3(Func AsT6, 7 => AsT7, 8 => AsT8, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -307,7 +309,7 @@ public OneOf MapT4(Func AsT6, 7 => AsT7, 8 => AsT8, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -328,7 +330,7 @@ public OneOf MapT5(Func AsT6, 7 => AsT7, 8 => AsT8, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -349,7 +351,7 @@ public OneOf MapT6(Func mapFunc(AsT6), 7 => AsT7, 8 => AsT8, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -370,7 +372,7 @@ public OneOf MapT7(Func AsT6, 7 => mapFunc(AsT7), 8 => AsT8, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } @@ -391,11 +393,15 @@ public OneOf MapT8(Func AsT6, 7 => AsT7, 8 => mapFunc(AsT8), - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; } - public bool TryPickT0(out T0 value, out OneOf remainder) +#if NET + public bool TryPickT0([NotNullWhen(true)] out T0? value, out OneOf remainder) +#else + public bool TryPickT0(out T0? value, out OneOf remainder) +#endif { value = IsT0 ? AsT0 : default; remainder = _index switch @@ -409,12 +415,16 @@ public bool TryPickT0(out T0 value, out OneOf re 6 => AsT6, 7 => AsT7, 8 => AsT8, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT0; } - public bool TryPickT1(out T1 value, out OneOf remainder) +#if NET + public bool TryPickT1([NotNullWhen(true)] out T1? value, out OneOf remainder) +#else + public bool TryPickT1(out T1? value, out OneOf remainder) +#endif { value = IsT1 ? AsT1 : default; remainder = _index switch @@ -428,12 +438,16 @@ public bool TryPickT1(out T1 value, out OneOf re 6 => AsT6, 7 => AsT7, 8 => AsT8, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT1; } - public bool TryPickT2(out T2 value, out OneOf remainder) +#if NET + public bool TryPickT2([NotNullWhen(true)] out T2? value, out OneOf remainder) +#else + public bool TryPickT2(out T2? value, out OneOf remainder) +#endif { value = IsT2 ? AsT2 : default; remainder = _index switch @@ -447,12 +461,16 @@ public bool TryPickT2(out T2 value, out OneOf re 6 => AsT6, 7 => AsT7, 8 => AsT8, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT2; } - public bool TryPickT3(out T3 value, out OneOf remainder) +#if NET + public bool TryPickT3([NotNullWhen(true)] out T3? value, out OneOf remainder) +#else + public bool TryPickT3(out T3? value, out OneOf remainder) +#endif { value = IsT3 ? AsT3 : default; remainder = _index switch @@ -466,12 +484,16 @@ public bool TryPickT3(out T3 value, out OneOf re 6 => AsT6, 7 => AsT7, 8 => AsT8, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT3; } - public bool TryPickT4(out T4 value, out OneOf remainder) +#if NET + public bool TryPickT4([NotNullWhen(true)] out T4? value, out OneOf remainder) +#else + public bool TryPickT4(out T4? value, out OneOf remainder) +#endif { value = IsT4 ? AsT4 : default; remainder = _index switch @@ -485,12 +507,16 @@ public bool TryPickT4(out T4 value, out OneOf re 6 => AsT6, 7 => AsT7, 8 => AsT8, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT4; } - public bool TryPickT5(out T5 value, out OneOf remainder) +#if NET + public bool TryPickT5([NotNullWhen(true)] out T5? value, out OneOf remainder) +#else + public bool TryPickT5(out T5? value, out OneOf remainder) +#endif { value = IsT5 ? AsT5 : default; remainder = _index switch @@ -504,12 +530,16 @@ public bool TryPickT5(out T5 value, out OneOf re 6 => AsT6, 7 => AsT7, 8 => AsT8, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT5; } - public bool TryPickT6(out T6 value, out OneOf remainder) +#if NET + public bool TryPickT6([NotNullWhen(true)] out T6? value, out OneOf remainder) +#else + public bool TryPickT6(out T6? value, out OneOf remainder) +#endif { value = IsT6 ? AsT6 : default; remainder = _index switch @@ -523,12 +553,16 @@ public bool TryPickT6(out T6 value, out OneOf re 6 => default, 7 => AsT7, 8 => AsT8, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT6; } - public bool TryPickT7(out T7 value, out OneOf remainder) +#if NET + public bool TryPickT7([NotNullWhen(true)] out T7? value, out OneOf remainder) +#else + public bool TryPickT7(out T7? value, out OneOf remainder) +#endif { value = IsT7 ? AsT7 : default; remainder = _index switch @@ -542,12 +576,16 @@ public bool TryPickT7(out T7 value, out OneOf re 6 => AsT6, 7 => default, 8 => AsT8, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT7; } - public bool TryPickT8(out T8 value, out OneOf remainder) +#if NET + public bool TryPickT8([NotNullWhen(true)] out T8? value, out OneOf remainder) +#else + public bool TryPickT8(out T8? value, out OneOf remainder) +#endif { value = IsT8 ? AsT8 : default; remainder = _index switch @@ -561,7 +599,7 @@ public bool TryPickT8(out T8 value, out OneOf re 6 => AsT6, 7 => AsT7, 8 => default, - _ => throw new InvalidOperationException() + _ => throw InvalidIndexException(_index) }; return this.IsT8; } @@ -582,7 +620,7 @@ bool Equals(OneOf other) => _ => false }; - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { From 9ead4565866265cbea3997995df76599c3a069bd Mon Sep 17 00:00:00 2001 From: Andrew McClement Date: Thu, 13 Mar 2025 13:46:30 +0000 Subject: [PATCH 3/3] Update tests to run on .NET 8 also. --- OneOf.Tests/OneOf.Tests.csproj | 2 +- OneOf.Tests/ToStringTests.cs | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/OneOf.Tests/OneOf.Tests.csproj b/OneOf.Tests/OneOf.Tests.csproj index 4598ccc..4edfcfa 100644 --- a/OneOf.Tests/OneOf.Tests.csproj +++ b/OneOf.Tests/OneOf.Tests.csproj @@ -1,7 +1,7 @@  - net451 + net451;net8.0 diff --git a/OneOf.Tests/ToStringTests.cs b/OneOf.Tests/ToStringTests.cs index e7e4daf..6940db1 100644 --- a/OneOf.Tests/ToStringTests.cs +++ b/OneOf.Tests/ToStringTests.cs @@ -21,7 +21,7 @@ static string RunInCulture(CultureInfo culture, Func action) } } - [TestCase("en-NZ", ExpectedResult = "System.DateTime: 2/01/2019 1:02:03 AM")] + [TestCase("en-NZ", ExpectedResult = "System.DateTime: 2/01/2019 1:02:03 am")] [TestCase("en-US", ExpectedResult = "System.DateTime: 1/2/2019 1:02:03 AM")] public string LeftSideFormatsWithCurrentCulture(string cultureName) { @@ -32,7 +32,7 @@ public string LeftSideFormatsWithCurrentCulture(string cultureName) }); } - [TestCase("en-NZ", ExpectedResult = "System.DateTime: 2/01/2019 1:02:03 AM")] + [TestCase("en-NZ", ExpectedResult = "System.DateTime: 2/01/2019 1:02:03 am")] [TestCase("en-US", ExpectedResult = "System.DateTime: 1/2/2019 1:02:03 AM")] public string RightSideFormatsWithCurrentCulture(string cultureName) { @@ -69,8 +69,13 @@ public void CallingToStringOnARecursiveTypeWorks() public void CallingToStringOnANestedNonRecursiveTypeWorks() { OneOf, OneOf> nestedType = (OneOf)true; +#if NET + const string mscorlib = @"System\.Private\.CoreLib, Version=\d\.0\.0\.0"; +#else + const string mscorlib = @"mscorlib, Version=4\.0\.0\.0"; +#endif - Assert.AreEqual("OneOf.OneOf`2[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]: System.Boolean: True", nestedType.ToString()); + Assert.That(nestedType.ToString(), Does.Match($@"OneOf\.OneOf`2\[\[System\.String, {mscorlib}, Culture=neutral, PublicKeyToken=[a-z0-9]+\],\[System\.Boolean, {mscorlib}, Culture=neutral, PublicKeyToken=[a-z0-9]+\]\]: System\.Boolean: True")); } } }