diff --git a/src/dotVariant.Generator.Test/samples/Variant-class-nullable-disable.out.cs b/src/dotVariant.Generator.Test/samples/Variant-class-nullable-disable.out.cs index 85c07cc..4d59c3f 100644 --- a/src/dotVariant.Generator.Test/samples/Variant-class-nullable-disable.out.cs +++ b/src/dotVariant.Generator.Test/samples/Variant-class-nullable-disable.out.cs @@ -86,6 +86,11 @@ public static Variant_class_nullable_disable Create(string s) public bool IsEmpty => _variant.IsEmpty; + /// + [global::System.Diagnostics.DebuggerNonUserCode] + public byte Index + => _variant.Index; + /// [global::System.Diagnostics.DebuggerNonUserCode] public override bool Equals(object other) @@ -113,6 +118,11 @@ public override int GetHashCode() public override string ToString() => _variant.ToString(); + /// + [global::System.Diagnostics.DebuggerNonUserCode] + public int UnsafeGet(global::dotVariant.Accessor._1 accessor) + => _variant.UnsafeGet(accessor); + /// [global::System.Diagnostics.DebuggerNonUserCode] public bool TryMatch(out int i) @@ -153,6 +163,11 @@ public TResult Match(global::System.Func i, TResult _) public TResult Match(global::System.Func i, global::System.Func _) => _variant.Match(i, _); + /// + [global::System.Diagnostics.DebuggerNonUserCode] + public float UnsafeGet(global::dotVariant.Accessor._2 accessor) + => _variant.UnsafeGet(accessor); + /// [global::System.Diagnostics.DebuggerNonUserCode] public bool TryMatch(out float f) @@ -193,6 +208,11 @@ public TResult Match(global::System.Func f, TResult _) public TResult Match(global::System.Func f, global::System.Func _) => _variant.Match(f, _); + /// + [global::System.Diagnostics.DebuggerNonUserCode] + public string UnsafeGet(global::dotVariant.Accessor._3 accessor) + => _variant.UnsafeGet(accessor); + /// [global::System.Diagnostics.DebuggerNonUserCode] public bool TryMatch(out string s) @@ -266,23 +286,6 @@ public __DebuggerTypeProxy(Variant_class_nullable_disable v) #pragma warning restore 8604, 8625 } } - - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - [global::System.Diagnostics.DebuggerNonUserCode] - public static explicit operator global::dotVariant.GeneratorSupport.Discriminator(Variant_class_nullable_disable v) - => (global::dotVariant.GeneratorSupport.Discriminator)v._variant; - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - [global::System.Diagnostics.DebuggerNonUserCode] - public static explicit operator global::dotVariant.GeneratorSupport.Accessor_1(Variant_class_nullable_disable v) - => (global::dotVariant.GeneratorSupport.Accessor_1)v._variant; - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - [global::System.Diagnostics.DebuggerNonUserCode] - public static explicit operator global::dotVariant.GeneratorSupport.Accessor_2(Variant_class_nullable_disable v) - => (global::dotVariant.GeneratorSupport.Accessor_2)v._variant; - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - [global::System.Diagnostics.DebuggerNonUserCode] - public static explicit operator global::dotVariant.GeneratorSupport.Accessor_3(Variant_class_nullable_disable v) - => (global::dotVariant.GeneratorSupport.Accessor_3)v._variant; } } @@ -318,38 +321,35 @@ public Union(string value) } private readonly Union _x; - private readonly byte _n; + + /// + /// The 1-based index of the currently stored type, + /// counted left-ro-right from the parameter list. + /// 0 if the variant is empty. + /// + public readonly byte Index; public Variant_class_nullable_disable(int i) { - _n = 1; + Index = 1; _x = new Union(i); } public Variant_class_nullable_disable(float f) { - _n = 2; + Index = 2; _x = new Union(f); } public Variant_class_nullable_disable(string s) { - _n = 3; + Index = 3; _x = new Union(s); } - public static explicit operator global::dotVariant.GeneratorSupport.Discriminator(in Variant_class_nullable_disable v) - => (global::dotVariant.GeneratorSupport.Discriminator)v._n; - public static explicit operator global::dotVariant.GeneratorSupport.Accessor_1(in Variant_class_nullable_disable v) - => new global::dotVariant.GeneratorSupport.Accessor_1(v._x._1); - public static explicit operator global::dotVariant.GeneratorSupport.Accessor_2(in Variant_class_nullable_disable v) - => new global::dotVariant.GeneratorSupport.Accessor_2(v._x._2); - public static explicit operator global::dotVariant.GeneratorSupport.Accessor_3(in Variant_class_nullable_disable v) - => new global::dotVariant.GeneratorSupport.Accessor_3(v._x._3); - /// /// if Variant_class_nullable_disable was constructed without a value. /// - public bool IsEmpty => _n == 0; + public bool IsEmpty => this.Index == 0; /// /// The string representation of the stored value's type. @@ -358,7 +358,7 @@ public string TypeString { get { - switch (_n) + switch (this.Index) { case 0: return ""; @@ -379,7 +379,7 @@ public string TypeString /// public override string ToString() { - switch (_n) + switch (this.Index) { case 0: return ""; @@ -401,7 +401,7 @@ public object AsObject { get { - switch (_n) + switch (this.Index) { case 0: return null; @@ -419,11 +419,11 @@ public object AsObject public bool Equals(in Variant_class_nullable_disable other) { - if (_n != other._n) + if (this.Index != other.Index) { return false; } - switch (_n) + switch (Index) { case 0: return true; @@ -440,7 +440,7 @@ public bool Equals(in Variant_class_nullable_disable other) public override int GetHashCode() { - switch (_n) + switch (this.Index) { case 0: return 0; @@ -455,6 +455,16 @@ public override int GetHashCode() } } + /// + /// Retrieve the stored value assuming it is of type . + /// + /// Only call this if you have ensured that Index == 1, + /// otherwise the correctness of the returned value is not guaranteed, + /// nor that any value is returned at all. + /// + public int UnsafeGet(global::dotVariant.Accessor._1 _) + => _x._1; + /// /// Retrieve the value stored within Variant_class_nullable_disable if it is of type . /// @@ -462,8 +472,8 @@ public override int GetHashCode() /// if Variant_class_nullable_disable contained a value of type . public bool TryMatch(out int i) { - i = _n == 1 ? _x._1 : default; - return _n == 1; + i = this.Index == 1 ? _x._1 : default; + return this.Index == 1; } /// @@ -474,7 +484,7 @@ public bool TryMatch(out int i) /// Any exception thrown from is rethrown. public bool TryMatch(global::System.Action i) { - if (_n == 1) + if (this.Index == 1) { i(_x._1); return true; @@ -490,7 +500,7 @@ public bool TryMatch(global::System.Action i) /// Variant_class_nullable_disable does not contain a value of type . public void Match(out int i) { - if (_n == 1) + if (this.Index == 1) { i = _x._1; return; @@ -507,7 +517,7 @@ public void Match(out int i) /// Any exception thrown from is rethrown. public void Match(global::System.Action i) { - if (_n == 1) + if (this.Index == 1) { i(_x._1); return; @@ -524,7 +534,7 @@ public void Match(global::System.Action i) /// Any exception thrown from or is rethrown. public void Match(global::System.Action i, global::System.Action _) { - if (_n == 1) + if (this.Index == 1) { i(_x._1); } @@ -544,7 +554,7 @@ public void Match(global::System.Action i, global::System.Action _) /// Any exception thrown from is rethrown. public TResult Match(global::System.Func i) { - if (_n == 1) + if (this.Index == 1) { return i(_x._1); } @@ -561,7 +571,7 @@ public TResult Match(global::System.Func i) /// Any exception thrown from or is rethrown. public TResult Match(global::System.Func i, TResult _) { - return _n == 1 ? i(_x._1) : _; + return this.Index == 1 ? i(_x._1) : _; } /// @@ -573,8 +583,18 @@ public TResult Match(global::System.Func i, TResult _) /// Any exception thrown from or is rethrown. public TResult Match(global::System.Func i, global::System.Func _) { - return _n == 1 ? i(_x._1) : _(); + return this.Index == 1 ? i(_x._1) : _(); } + /// + /// Retrieve the stored value assuming it is of type . + /// + /// Only call this if you have ensured that Index == 2, + /// otherwise the correctness of the returned value is not guaranteed, + /// nor that any value is returned at all. + /// + public float UnsafeGet(global::dotVariant.Accessor._2 _) + => _x._2; + /// /// Retrieve the value stored within Variant_class_nullable_disable if it is of type . /// @@ -582,8 +602,8 @@ public TResult Match(global::System.Func i, global::Syste /// if Variant_class_nullable_disable contained a value of type . public bool TryMatch(out float f) { - f = _n == 2 ? _x._2 : default; - return _n == 2; + f = this.Index == 2 ? _x._2 : default; + return this.Index == 2; } /// @@ -594,7 +614,7 @@ public bool TryMatch(out float f) /// Any exception thrown from is rethrown. public bool TryMatch(global::System.Action f) { - if (_n == 2) + if (this.Index == 2) { f(_x._2); return true; @@ -610,7 +630,7 @@ public bool TryMatch(global::System.Action f) /// Variant_class_nullable_disable does not contain a value of type . public void Match(out float f) { - if (_n == 2) + if (this.Index == 2) { f = _x._2; return; @@ -627,7 +647,7 @@ public void Match(out float f) /// Any exception thrown from is rethrown. public void Match(global::System.Action f) { - if (_n == 2) + if (this.Index == 2) { f(_x._2); return; @@ -644,7 +664,7 @@ public void Match(global::System.Action f) /// Any exception thrown from or is rethrown. public void Match(global::System.Action f, global::System.Action _) { - if (_n == 2) + if (this.Index == 2) { f(_x._2); } @@ -664,7 +684,7 @@ public void Match(global::System.Action f, global::System.Action _) /// Any exception thrown from is rethrown. public TResult Match(global::System.Func f) { - if (_n == 2) + if (this.Index == 2) { return f(_x._2); } @@ -681,7 +701,7 @@ public TResult Match(global::System.Func f) /// Any exception thrown from or is rethrown. public TResult Match(global::System.Func f, TResult _) { - return _n == 2 ? f(_x._2) : _; + return this.Index == 2 ? f(_x._2) : _; } /// @@ -693,8 +713,18 @@ public TResult Match(global::System.Func f, TResult _) /// Any exception thrown from or is rethrown. public TResult Match(global::System.Func f, global::System.Func _) { - return _n == 2 ? f(_x._2) : _(); + return this.Index == 2 ? f(_x._2) : _(); } + /// + /// Retrieve the stored value assuming it is of type . + /// + /// Only call this if you have ensured that Index == 3, + /// otherwise the correctness of the returned value is not guaranteed, + /// nor that any value is returned at all. + /// + public string UnsafeGet(global::dotVariant.Accessor._3 _) + => _x._3; + /// /// Retrieve the value stored within Variant_class_nullable_disable if it is of type . /// @@ -702,8 +732,8 @@ public TResult Match(global::System.Func f, global::Sys /// if Variant_class_nullable_disable contained a value of type . public bool TryMatch(out string s) { - s = _n == 3 ? _x._3 : default; - return _n == 3; + s = this.Index == 3 ? _x._3 : default; + return this.Index == 3; } /// @@ -714,7 +744,7 @@ public bool TryMatch(out string s) /// Any exception thrown from is rethrown. public bool TryMatch(global::System.Action s) { - if (_n == 3) + if (this.Index == 3) { s(_x._3); return true; @@ -730,7 +760,7 @@ public bool TryMatch(global::System.Action s) /// Variant_class_nullable_disable does not contain a value of type . public void Match(out string s) { - if (_n == 3) + if (this.Index == 3) { s = _x._3; return; @@ -747,7 +777,7 @@ public void Match(out string s) /// Any exception thrown from is rethrown. public void Match(global::System.Action s) { - if (_n == 3) + if (this.Index == 3) { s(_x._3); return; @@ -764,7 +794,7 @@ public void Match(global::System.Action s) /// Any exception thrown from or is rethrown. public void Match(global::System.Action s, global::System.Action _) { - if (_n == 3) + if (this.Index == 3) { s(_x._3); } @@ -784,7 +814,7 @@ public void Match(global::System.Action s, global::System.Action _) /// Any exception thrown from is rethrown. public TResult Match(global::System.Func s) { - if (_n == 3) + if (this.Index == 3) { return s(_x._3); } @@ -801,7 +831,7 @@ public TResult Match(global::System.Func s) /// Any exception thrown from or is rethrown. public TResult Match(global::System.Func s, TResult _) { - return _n == 3 ? s(_x._3) : _; + return this.Index == 3 ? s(_x._3) : _; } /// @@ -813,7 +843,7 @@ public TResult Match(global::System.Func s, TResult _) /// Any exception thrown from or is rethrown. public TResult Match(global::System.Func s, global::System.Func _) { - return _n == 3 ? s(_x._3) : _(); + return this.Index == 3 ? s(_x._3) : _(); } /// @@ -827,7 +857,7 @@ public TResult Match(global::System.Func s, global::Sy /// Any exception thrown from a delegate is rethrown. public void Visit(global::System.Action i, global::System.Action f, global::System.Action s, global::System.Action _) { - switch (_n) + switch (this.Index) { case 0: _(); @@ -858,7 +888,7 @@ public void Visit(global::System.Action i, global::System.Action f, /// Any exception thrown from a delegate is rethrown. public void Visit(global::System.Action i, global::System.Action f, global::System.Action s) { - switch (_n) + switch (this.Index) { case 0: global::dotVariant.GeneratorSupport.Errors.ThrowEmptyError("Foo.Variant_class_nullable_disable"); @@ -890,7 +920,7 @@ public void Visit(global::System.Action i, global::System.Action f, /// The return type of all delegates, and by extension the return type of this function. public TResult Visit(global::System.Func i, global::System.Func f, global::System.Func s, global::System.Func _) { - switch (_n) + switch (this.Index) { case 0: return _(); @@ -917,7 +947,7 @@ public TResult Visit(global::System.Func i, global::Syste /// The return type of all delegates, and by extension the return type of this function. public TResult Visit(global::System.Func i, global::System.Func f, global::System.Func s) { - switch (_n) + switch (this.Index) { case 0: return global::dotVariant.GeneratorSupport.Errors.ThrowEmptyError("Foo.Variant_class_nullable_disable"); @@ -955,9 +985,9 @@ public static partial class Variant_class_nullable_disableEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 1) + if (variant.Index == 1) { - yield return i(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return i(variant.UnsafeGet(new global::dotVariant.Accessor._1())); } } } @@ -977,9 +1007,9 @@ public static partial class Variant_class_nullable_disableEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 2) + if (variant.Index == 2) { - yield return f(((global::dotVariant.GeneratorSupport.Accessor_2)variant).Value); + yield return f(variant.UnsafeGet(new global::dotVariant.Accessor._2())); } } } @@ -999,9 +1029,9 @@ public static partial class Variant_class_nullable_disableEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 3) + if (variant.Index == 3) { - yield return s(((global::dotVariant.GeneratorSupport.Accessor_3)variant).Value); + yield return s(variant.UnsafeGet(new global::dotVariant.Accessor._3())); } } } @@ -1024,9 +1054,9 @@ public static partial class Variant_class_nullable_disableEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 1) + if (variant.Index == 1) { - yield return i(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return i(variant.UnsafeGet(new global::dotVariant.Accessor._1())); } else { @@ -1052,9 +1082,9 @@ public static partial class Variant_class_nullable_disableEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 2) + if (variant.Index == 2) { - yield return f(((global::dotVariant.GeneratorSupport.Accessor_2)variant).Value); + yield return f(variant.UnsafeGet(new global::dotVariant.Accessor._2())); } else { @@ -1080,9 +1110,9 @@ public static partial class Variant_class_nullable_disableEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 3) + if (variant.Index == 3) { - yield return s(((global::dotVariant.GeneratorSupport.Accessor_3)variant).Value); + yield return s(variant.UnsafeGet(new global::dotVariant.Accessor._3())); } else { @@ -1109,9 +1139,9 @@ public static partial class Variant_class_nullable_disableEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 1) + if (variant.Index == 1) { - yield return i(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return i(variant.UnsafeGet(new global::dotVariant.Accessor._1())); } else { @@ -1137,9 +1167,9 @@ public static partial class Variant_class_nullable_disableEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 2) + if (variant.Index == 2) { - yield return f(((global::dotVariant.GeneratorSupport.Accessor_2)variant).Value); + yield return f(variant.UnsafeGet(new global::dotVariant.Accessor._2())); } else { @@ -1165,9 +1195,9 @@ public static partial class Variant_class_nullable_disableEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 3) + if (variant.Index == 3) { - yield return s(((global::dotVariant.GeneratorSupport.Accessor_3)variant).Value); + yield return s(variant.UnsafeGet(new global::dotVariant.Accessor._3())); } else { @@ -1196,19 +1226,19 @@ public static partial class Variant_class_nullable_disableEx { foreach (var variant in source) { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant)) + switch (variant.Index) { case 0: global::dotVariant.GeneratorSupport.Errors.ThrowEmptyError("Foo.Variant_class_nullable_disable"); yield break; case 1: - yield return i(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return i(variant.UnsafeGet(new global::dotVariant.Accessor._1())); break; case 2: - yield return f(((global::dotVariant.GeneratorSupport.Accessor_2)variant).Value); + yield return f(variant.UnsafeGet(new global::dotVariant.Accessor._2())); break; case 3: - yield return s(((global::dotVariant.GeneratorSupport.Accessor_3)variant).Value); + yield return s(variant.UnsafeGet(new global::dotVariant.Accessor._3())); break; default: global::dotVariant.GeneratorSupport.Errors.ThrowInternalError("Foo.Variant_class_nullable_disable"); @@ -1237,19 +1267,19 @@ public static partial class Variant_class_nullable_disableEx { foreach (var variant in source) { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant)) + switch (variant.Index) { case 0: yield return _(); break; case 1: - yield return i(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return i(variant.UnsafeGet(new global::dotVariant.Accessor._1())); break; case 2: - yield return f(((global::dotVariant.GeneratorSupport.Accessor_2)variant).Value); + yield return f(variant.UnsafeGet(new global::dotVariant.Accessor._2())); break; case 3: - yield return s(((global::dotVariant.GeneratorSupport.Accessor_3)variant).Value); + yield return s(variant.UnsafeGet(new global::dotVariant.Accessor._3())); break; default: global::dotVariant.GeneratorSupport.Errors.ThrowInternalError("Foo.Variant_class_nullable_disable"); @@ -1277,8 +1307,8 @@ public static partial class Variant_class_nullable_disableEx global::System.Func i) { return global::System.Reactive.Linq.Observable.Select( - global::System.Reactive.Linq.Observable.Where(source, _variant => ((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 1), - _variant => i(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value)); + global::System.Reactive.Linq.Observable.Where(source, _variant => _variant.Index == 1), + _variant => i(_variant.UnsafeGet(new global::dotVariant.Accessor._1()))); } /// /// Projects each element of an observable sequence @@ -1294,8 +1324,8 @@ public static partial class Variant_class_nullable_disableEx global::System.Func f) { return global::System.Reactive.Linq.Observable.Select( - global::System.Reactive.Linq.Observable.Where(source, _variant => ((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 2), - _variant => f(((global::dotVariant.GeneratorSupport.Accessor_2)_variant).Value)); + global::System.Reactive.Linq.Observable.Where(source, _variant => _variant.Index == 2), + _variant => f(_variant.UnsafeGet(new global::dotVariant.Accessor._2()))); } /// /// Projects each element of an observable sequence @@ -1311,8 +1341,8 @@ public static partial class Variant_class_nullable_disableEx global::System.Func s) { return global::System.Reactive.Linq.Observable.Select( - global::System.Reactive.Linq.Observable.Where(source, _variant => ((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 3), - _variant => s(((global::dotVariant.GeneratorSupport.Accessor_3)_variant).Value)); + global::System.Reactive.Linq.Observable.Where(source, _variant => _variant.Index == 3), + _variant => s(_variant.UnsafeGet(new global::dotVariant.Accessor._3()))); } /// @@ -1332,9 +1362,9 @@ public static partial class Variant_class_nullable_disableEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 1) + if (_variant.Index == 1) { - return i(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + return i(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); } else { @@ -1359,9 +1389,9 @@ public static partial class Variant_class_nullable_disableEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 2) + if (_variant.Index == 2) { - return f(((global::dotVariant.GeneratorSupport.Accessor_2)_variant).Value); + return f(_variant.UnsafeGet(new global::dotVariant.Accessor._2())); } else { @@ -1386,9 +1416,9 @@ public static partial class Variant_class_nullable_disableEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 3) + if (_variant.Index == 3) { - return s(((global::dotVariant.GeneratorSupport.Accessor_3)_variant).Value); + return s(_variant.UnsafeGet(new global::dotVariant.Accessor._3())); } else { @@ -1414,9 +1444,9 @@ public static partial class Variant_class_nullable_disableEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 1) + if (_variant.Index == 1) { - return i(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + return i(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); } else { @@ -1441,9 +1471,9 @@ public static partial class Variant_class_nullable_disableEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 2) + if (_variant.Index == 2) { - return f(((global::dotVariant.GeneratorSupport.Accessor_2)_variant).Value); + return f(_variant.UnsafeGet(new global::dotVariant.Accessor._2())); } else { @@ -1468,9 +1498,9 @@ public static partial class Variant_class_nullable_disableEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 3) + if (_variant.Index == 3) { - return s(((global::dotVariant.GeneratorSupport.Accessor_3)_variant).Value); + return s(_variant.UnsafeGet(new global::dotVariant.Accessor._3())); } else { @@ -1496,16 +1526,16 @@ public static partial class Variant_class_nullable_disableEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant)) + switch (_variant.Index) { case 0: return global::dotVariant.GeneratorSupport.Errors.ThrowEmptyError("Foo.Variant_class_nullable_disable"); case 1: - return i(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + return i(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); case 2: - return f(((global::dotVariant.GeneratorSupport.Accessor_2)_variant).Value); + return f(_variant.UnsafeGet(new global::dotVariant.Accessor._2())); case 3: - return s(((global::dotVariant.GeneratorSupport.Accessor_3)_variant).Value); + return s(_variant.UnsafeGet(new global::dotVariant.Accessor._3())); default: return global::dotVariant.GeneratorSupport.Errors.ThrowInternalError("Foo.Variant_class_nullable_disable"); } @@ -1531,16 +1561,16 @@ public static partial class Variant_class_nullable_disableEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant)) + switch (_variant.Index) { case 0: return _(); case 1: - return i(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + return i(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); case 2: - return f(((global::dotVariant.GeneratorSupport.Accessor_2)_variant).Value); + return f(_variant.UnsafeGet(new global::dotVariant.Accessor._2())); case 3: - return s(((global::dotVariant.GeneratorSupport.Accessor_3)_variant).Value); + return s(_variant.UnsafeGet(new global::dotVariant.Accessor._3())); default: return global::dotVariant.GeneratorSupport.Errors.ThrowInternalError("Foo.Variant_class_nullable_disable"); } @@ -1698,7 +1728,7 @@ public void Dispose() public void OnNext(global::Foo.Variant_class_nullable_disable _variant) { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant)) + switch (_variant.Index) { case 0: if (_accept0) @@ -1711,13 +1741,13 @@ public void OnNext(global::Foo.Variant_class_nullable_disable _variant) } break; case 1: - Subject1.OnNext(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + Subject1.OnNext(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); break; case 2: - Subject2.OnNext(((global::dotVariant.GeneratorSupport.Accessor_2)_variant).Value); + Subject2.OnNext(_variant.UnsafeGet(new global::dotVariant.Accessor._2())); break; case 3: - Subject3.OnNext(((global::dotVariant.GeneratorSupport.Accessor_3)_variant).Value); + Subject3.OnNext(_variant.UnsafeGet(new global::dotVariant.Accessor._3())); break; default: OnError(global::dotVariant.GeneratorSupport.Errors.MakeInternalError("Foo.Variant_class_nullable_disable")); diff --git a/src/dotVariant.Generator.Test/samples/Variant-class-nullable-enable.out.cs b/src/dotVariant.Generator.Test/samples/Variant-class-nullable-enable.out.cs index eed34aa..2574406 100644 --- a/src/dotVariant.Generator.Test/samples/Variant-class-nullable-enable.out.cs +++ b/src/dotVariant.Generator.Test/samples/Variant-class-nullable-enable.out.cs @@ -107,6 +107,11 @@ public static Variant_class_nullable_enable Create(global::System.Array? a) public bool IsEmpty => _variant.IsEmpty; + /// + [global::System.Diagnostics.DebuggerNonUserCode] + public byte Index + => _variant.Index; + /// [global::System.Diagnostics.DebuggerNonUserCode] public override bool Equals(object? other) @@ -134,6 +139,11 @@ public override int GetHashCode() public override string ToString() => _variant.ToString(); + /// + [global::System.Diagnostics.DebuggerNonUserCode] + public int UnsafeGet(global::dotVariant.Accessor._1 accessor) + => _variant.UnsafeGet(accessor); + /// [global::System.Diagnostics.DebuggerNonUserCode] public bool TryMatch([global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out int i) @@ -174,6 +184,11 @@ public TResult Match(global::System.Func i, TResult _) public TResult Match(global::System.Func i, global::System.Func _) => _variant.Match(i, _); + /// + [global::System.Diagnostics.DebuggerNonUserCode] + public float UnsafeGet(global::dotVariant.Accessor._2 accessor) + => _variant.UnsafeGet(accessor); + /// [global::System.Diagnostics.DebuggerNonUserCode] public bool TryMatch([global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out float f) @@ -214,6 +229,11 @@ public TResult Match(global::System.Func f, TResult _) public TResult Match(global::System.Func f, global::System.Func _) => _variant.Match(f, _); + /// + [global::System.Diagnostics.DebuggerNonUserCode] + public string UnsafeGet(global::dotVariant.Accessor._3 accessor) + => _variant.UnsafeGet(accessor); + /// [global::System.Diagnostics.DebuggerNonUserCode] public bool TryMatch([global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out string? s) @@ -254,6 +274,11 @@ public TResult Match(global::System.Func s, TResult _) public TResult Match(global::System.Func s, global::System.Func _) => _variant.Match(s, _); + /// + [global::System.Diagnostics.DebuggerNonUserCode] + public global::System.Array? UnsafeGet(global::dotVariant.Accessor._4 accessor) + => _variant.UnsafeGet(accessor); + /// [global::System.Diagnostics.DebuggerNonUserCode] public bool TryMatch(out global::System.Array? a) @@ -327,27 +352,6 @@ public __DebuggerTypeProxy(Variant_class_nullable_enable v) #pragma warning restore 8604, 8625 } } - - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - [global::System.Diagnostics.DebuggerNonUserCode] - public static explicit operator global::dotVariant.GeneratorSupport.Discriminator(Variant_class_nullable_enable v) - => (global::dotVariant.GeneratorSupport.Discriminator)v._variant; - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - [global::System.Diagnostics.DebuggerNonUserCode] - public static explicit operator global::dotVariant.GeneratorSupport.Accessor_1(Variant_class_nullable_enable v) - => (global::dotVariant.GeneratorSupport.Accessor_1)v._variant; - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - [global::System.Diagnostics.DebuggerNonUserCode] - public static explicit operator global::dotVariant.GeneratorSupport.Accessor_2(Variant_class_nullable_enable v) - => (global::dotVariant.GeneratorSupport.Accessor_2)v._variant; - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - [global::System.Diagnostics.DebuggerNonUserCode] - public static explicit operator global::dotVariant.GeneratorSupport.Accessor_3(Variant_class_nullable_enable v) - => (global::dotVariant.GeneratorSupport.Accessor_3)v._variant; - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - [global::System.Diagnostics.DebuggerNonUserCode] - public static explicit operator global::dotVariant.GeneratorSupport.Accessor_4(Variant_class_nullable_enable v) - => (global::dotVariant.GeneratorSupport.Accessor_4)v._variant; } } @@ -394,45 +398,40 @@ public Union(global::System.Array? value) } private readonly Union _x; - private readonly byte _n; + + /// + /// The 1-based index of the currently stored type, + /// counted left-ro-right from the parameter list. + /// 0 if the variant is empty. + /// + public readonly byte Index; public Variant_class_nullable_enable(int i) { - _n = 1; + Index = 1; _x = new Union(i); } public Variant_class_nullable_enable(float f) { - _n = 2; + Index = 2; _x = new Union(f); } public Variant_class_nullable_enable(string s) { - _n = 3; + Index = 3; _x = new Union(s); } public Variant_class_nullable_enable(global::System.Array? a) { - _n = 4; + Index = 4; _x = new Union(a); } - public static explicit operator global::dotVariant.GeneratorSupport.Discriminator(in Variant_class_nullable_enable v) - => (global::dotVariant.GeneratorSupport.Discriminator)v._n; - public static explicit operator global::dotVariant.GeneratorSupport.Accessor_1(in Variant_class_nullable_enable v) - => new global::dotVariant.GeneratorSupport.Accessor_1(v._x._1); - public static explicit operator global::dotVariant.GeneratorSupport.Accessor_2(in Variant_class_nullable_enable v) - => new global::dotVariant.GeneratorSupport.Accessor_2(v._x._2); - public static explicit operator global::dotVariant.GeneratorSupport.Accessor_3(in Variant_class_nullable_enable v) - => new global::dotVariant.GeneratorSupport.Accessor_3(v._x._3); - public static explicit operator global::dotVariant.GeneratorSupport.Accessor_4(in Variant_class_nullable_enable v) - => new global::dotVariant.GeneratorSupport.Accessor_4(v._x._4); - /// /// if Variant_class_nullable_enable was constructed without a value. /// - public bool IsEmpty => _n == 0; + public bool IsEmpty => this.Index == 0; /// /// The string representation of the stored value's type. @@ -441,7 +440,7 @@ public string TypeString { get { - switch (_n) + switch (this.Index) { case 0: return ""; @@ -464,7 +463,7 @@ public string TypeString /// public override string ToString() { - switch (_n) + switch (this.Index) { case 0: return ""; @@ -488,7 +487,7 @@ public object? AsObject { get { - switch (_n) + switch (this.Index) { case 0: return null; @@ -508,11 +507,11 @@ public object? AsObject public bool Equals(in Variant_class_nullable_enable other) { - if (_n != other._n) + if (this.Index != other.Index) { return false; } - switch (_n) + switch (Index) { case 0: return true; @@ -531,7 +530,7 @@ public bool Equals(in Variant_class_nullable_enable other) public override int GetHashCode() { - switch (_n) + switch (this.Index) { case 0: return 0; @@ -548,6 +547,16 @@ public override int GetHashCode() } } + /// + /// Retrieve the stored value assuming it is of type . + /// + /// Only call this if you have ensured that Index == 1, + /// otherwise the correctness of the returned value is not guaranteed, + /// nor that any value is returned at all. + /// + public int UnsafeGet(global::dotVariant.Accessor._1 _) + => _x._1; + /// /// Retrieve the value stored within Variant_class_nullable_enable if it is of type . /// @@ -555,8 +564,8 @@ public override int GetHashCode() /// if Variant_class_nullable_enable contained a value of type . public bool TryMatch([global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out int i) { - i = _n == 1 ? _x._1 : default; - return _n == 1; + i = this.Index == 1 ? _x._1 : default; + return this.Index == 1; } /// @@ -567,7 +576,7 @@ public bool TryMatch([global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] /// Any exception thrown from is rethrown. public bool TryMatch(global::System.Action i) { - if (_n == 1) + if (this.Index == 1) { i(_x._1); return true; @@ -583,7 +592,7 @@ public bool TryMatch(global::System.Action i) /// Variant_class_nullable_enable does not contain a value of type . public void Match([global::System.Diagnostics.CodeAnalysis.NotNull] out int i) { - if (_n == 1) + if (this.Index == 1) { i = _x._1; return; @@ -600,7 +609,7 @@ public void Match([global::System.Diagnostics.CodeAnalysis.NotNull] out int i) /// Any exception thrown from is rethrown. public void Match(global::System.Action i) { - if (_n == 1) + if (this.Index == 1) { i(_x._1); return; @@ -617,7 +626,7 @@ public void Match(global::System.Action i) /// Any exception thrown from or is rethrown. public void Match(global::System.Action i, global::System.Action _) { - if (_n == 1) + if (this.Index == 1) { i(_x._1); } @@ -637,7 +646,7 @@ public void Match(global::System.Action i, global::System.Action _) /// Any exception thrown from is rethrown. public TResult Match(global::System.Func i) { - if (_n == 1) + if (this.Index == 1) { return i(_x._1); } @@ -654,7 +663,7 @@ public TResult Match(global::System.Func i) /// Any exception thrown from or is rethrown. public TResult Match(global::System.Func i, TResult _) { - return _n == 1 ? i(_x._1) : _; + return this.Index == 1 ? i(_x._1) : _; } /// @@ -666,8 +675,18 @@ public TResult Match(global::System.Func i, TResult _) /// Any exception thrown from or is rethrown. public TResult Match(global::System.Func i, global::System.Func _) { - return _n == 1 ? i(_x._1) : _(); + return this.Index == 1 ? i(_x._1) : _(); } + /// + /// Retrieve the stored value assuming it is of type . + /// + /// Only call this if you have ensured that Index == 2, + /// otherwise the correctness of the returned value is not guaranteed, + /// nor that any value is returned at all. + /// + public float UnsafeGet(global::dotVariant.Accessor._2 _) + => _x._2; + /// /// Retrieve the value stored within Variant_class_nullable_enable if it is of type . /// @@ -675,8 +694,8 @@ public TResult Match(global::System.Func i, global::Syste /// if Variant_class_nullable_enable contained a value of type . public bool TryMatch([global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out float f) { - f = _n == 2 ? _x._2 : default; - return _n == 2; + f = this.Index == 2 ? _x._2 : default; + return this.Index == 2; } /// @@ -687,7 +706,7 @@ public bool TryMatch([global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] /// Any exception thrown from is rethrown. public bool TryMatch(global::System.Action f) { - if (_n == 2) + if (this.Index == 2) { f(_x._2); return true; @@ -703,7 +722,7 @@ public bool TryMatch(global::System.Action f) /// Variant_class_nullable_enable does not contain a value of type . public void Match([global::System.Diagnostics.CodeAnalysis.NotNull] out float f) { - if (_n == 2) + if (this.Index == 2) { f = _x._2; return; @@ -720,7 +739,7 @@ public void Match([global::System.Diagnostics.CodeAnalysis.NotNull] out float f) /// Any exception thrown from is rethrown. public void Match(global::System.Action f) { - if (_n == 2) + if (this.Index == 2) { f(_x._2); return; @@ -737,7 +756,7 @@ public void Match(global::System.Action f) /// Any exception thrown from or is rethrown. public void Match(global::System.Action f, global::System.Action _) { - if (_n == 2) + if (this.Index == 2) { f(_x._2); } @@ -757,7 +776,7 @@ public void Match(global::System.Action f, global::System.Action _) /// Any exception thrown from is rethrown. public TResult Match(global::System.Func f) { - if (_n == 2) + if (this.Index == 2) { return f(_x._2); } @@ -774,7 +793,7 @@ public TResult Match(global::System.Func f) /// Any exception thrown from or is rethrown. public TResult Match(global::System.Func f, TResult _) { - return _n == 2 ? f(_x._2) : _; + return this.Index == 2 ? f(_x._2) : _; } /// @@ -786,8 +805,18 @@ public TResult Match(global::System.Func f, TResult _) /// Any exception thrown from or is rethrown. public TResult Match(global::System.Func f, global::System.Func _) { - return _n == 2 ? f(_x._2) : _(); + return this.Index == 2 ? f(_x._2) : _(); } + /// + /// Retrieve the stored value assuming it is of type . + /// + /// Only call this if you have ensured that Index == 3, + /// otherwise the correctness of the returned value is not guaranteed, + /// nor that any value is returned at all. + /// + public string UnsafeGet(global::dotVariant.Accessor._3 _) + => _x._3; + /// /// Retrieve the value stored within Variant_class_nullable_enable if it is of type . /// @@ -795,8 +824,8 @@ public TResult Match(global::System.Func f, global::Sys /// if Variant_class_nullable_enable contained a value of type . public bool TryMatch([global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out string? s) { - s = _n == 3 ? _x._3 : default; - return _n == 3; + s = this.Index == 3 ? _x._3 : default; + return this.Index == 3; } /// @@ -807,7 +836,7 @@ public bool TryMatch([global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] /// Any exception thrown from is rethrown. public bool TryMatch(global::System.Action s) { - if (_n == 3) + if (this.Index == 3) { s(_x._3); return true; @@ -823,7 +852,7 @@ public bool TryMatch(global::System.Action s) /// Variant_class_nullable_enable does not contain a value of type . public void Match([global::System.Diagnostics.CodeAnalysis.NotNull] out string? s) { - if (_n == 3) + if (this.Index == 3) { s = _x._3; return; @@ -840,7 +869,7 @@ public void Match([global::System.Diagnostics.CodeAnalysis.NotNull] out string? /// Any exception thrown from is rethrown. public void Match(global::System.Action s) { - if (_n == 3) + if (this.Index == 3) { s(_x._3); return; @@ -857,7 +886,7 @@ public void Match(global::System.Action s) /// Any exception thrown from or is rethrown. public void Match(global::System.Action s, global::System.Action _) { - if (_n == 3) + if (this.Index == 3) { s(_x._3); } @@ -877,7 +906,7 @@ public void Match(global::System.Action s, global::System.Action _) /// Any exception thrown from is rethrown. public TResult Match(global::System.Func s) { - if (_n == 3) + if (this.Index == 3) { return s(_x._3); } @@ -894,7 +923,7 @@ public TResult Match(global::System.Func s) /// Any exception thrown from or is rethrown. public TResult Match(global::System.Func s, TResult _) { - return _n == 3 ? s(_x._3) : _; + return this.Index == 3 ? s(_x._3) : _; } /// @@ -906,8 +935,18 @@ public TResult Match(global::System.Func s, TResult _) /// Any exception thrown from or is rethrown. public TResult Match(global::System.Func s, global::System.Func _) { - return _n == 3 ? s(_x._3) : _(); + return this.Index == 3 ? s(_x._3) : _(); } + /// + /// Retrieve the stored value assuming it is of type . + /// + /// Only call this if you have ensured that Index == 4, + /// otherwise the correctness of the returned value is not guaranteed, + /// nor that any value is returned at all. + /// + public global::System.Array? UnsafeGet(global::dotVariant.Accessor._4 _) + => _x._4; + /// /// Retrieve the value stored within Variant_class_nullable_enable if it is of type . /// @@ -915,8 +954,8 @@ public TResult Match(global::System.Func s, global::Sy /// if Variant_class_nullable_enable contained a value of type . public bool TryMatch(out global::System.Array? a) { - a = _n == 4 ? _x._4 : default; - return _n == 4; + a = this.Index == 4 ? _x._4 : default; + return this.Index == 4; } /// @@ -927,7 +966,7 @@ public bool TryMatch(out global::System.Array? a) /// Any exception thrown from is rethrown. public bool TryMatch(global::System.Action a) { - if (_n == 4) + if (this.Index == 4) { a(_x._4); return true; @@ -943,7 +982,7 @@ public bool TryMatch(global::System.Action a) /// Variant_class_nullable_enable does not contain a value of type . public void Match(out global::System.Array? a) { - if (_n == 4) + if (this.Index == 4) { a = _x._4; return; @@ -960,7 +999,7 @@ public void Match(out global::System.Array? a) /// Any exception thrown from is rethrown. public void Match(global::System.Action a) { - if (_n == 4) + if (this.Index == 4) { a(_x._4); return; @@ -977,7 +1016,7 @@ public void Match(global::System.Action a) /// Any exception thrown from or is rethrown. public void Match(global::System.Action a, global::System.Action _) { - if (_n == 4) + if (this.Index == 4) { a(_x._4); } @@ -997,7 +1036,7 @@ public void Match(global::System.Action a, global::System /// Any exception thrown from is rethrown. public TResult Match(global::System.Func a) { - if (_n == 4) + if (this.Index == 4) { return a(_x._4); } @@ -1014,7 +1053,7 @@ public TResult Match(global::System.FuncAny exception thrown from or is rethrown. public TResult Match(global::System.Func a, TResult _) { - return _n == 4 ? a(_x._4) : _; + return this.Index == 4 ? a(_x._4) : _; } /// @@ -1026,7 +1065,7 @@ public TResult Match(global::System.FuncAny exception thrown from or is rethrown. public TResult Match(global::System.Func a, global::System.Func _) { - return _n == 4 ? a(_x._4) : _(); + return this.Index == 4 ? a(_x._4) : _(); } /// @@ -1041,7 +1080,7 @@ public TResult Match(global::System.FuncAny exception thrown from a delegate is rethrown. public void Visit(global::System.Action i, global::System.Action f, global::System.Action s, global::System.Action a, global::System.Action _) { - switch (_n) + switch (this.Index) { case 0: _(); @@ -1076,7 +1115,7 @@ public void Visit(global::System.Action i, global::System.Action f, /// Any exception thrown from a delegate is rethrown. public void Visit(global::System.Action i, global::System.Action f, global::System.Action s, global::System.Action a) { - switch (_n) + switch (this.Index) { case 0: global::dotVariant.GeneratorSupport.Errors.ThrowEmptyError("Foo.Variant_class_nullable_enable"); @@ -1112,7 +1151,7 @@ public void Visit(global::System.Action i, global::System.Action f, /// The return type of all delegates, and by extension the return type of this function. public TResult Visit(global::System.Func i, global::System.Func f, global::System.Func s, global::System.Func a, global::System.Func _) { - switch (_n) + switch (this.Index) { case 0: return _(); @@ -1142,7 +1181,7 @@ public TResult Visit(global::System.Func i, global::Syste /// The return type of all delegates, and by extension the return type of this function. public TResult Visit(global::System.Func i, global::System.Func f, global::System.Func s, global::System.Func a) { - switch (_n) + switch (this.Index) { case 0: return global::dotVariant.GeneratorSupport.Errors.ThrowEmptyError("Foo.Variant_class_nullable_enable"); @@ -1182,9 +1221,9 @@ public static partial class Variant_class_nullable_enableEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 1) + if (variant.Index == 1) { - yield return i(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return i(variant.UnsafeGet(new global::dotVariant.Accessor._1())); } } } @@ -1204,9 +1243,9 @@ public static partial class Variant_class_nullable_enableEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 2) + if (variant.Index == 2) { - yield return f(((global::dotVariant.GeneratorSupport.Accessor_2)variant).Value); + yield return f(variant.UnsafeGet(new global::dotVariant.Accessor._2())); } } } @@ -1226,9 +1265,9 @@ public static partial class Variant_class_nullable_enableEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 3) + if (variant.Index == 3) { - yield return s(((global::dotVariant.GeneratorSupport.Accessor_3)variant).Value); + yield return s(variant.UnsafeGet(new global::dotVariant.Accessor._3())); } } } @@ -1248,9 +1287,9 @@ public static partial class Variant_class_nullable_enableEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 4) + if (variant.Index == 4) { - yield return a(((global::dotVariant.GeneratorSupport.Accessor_4)variant).Value); + yield return a(variant.UnsafeGet(new global::dotVariant.Accessor._4())); } } } @@ -1273,9 +1312,9 @@ public static partial class Variant_class_nullable_enableEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 1) + if (variant.Index == 1) { - yield return i(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return i(variant.UnsafeGet(new global::dotVariant.Accessor._1())); } else { @@ -1301,9 +1340,9 @@ public static partial class Variant_class_nullable_enableEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 2) + if (variant.Index == 2) { - yield return f(((global::dotVariant.GeneratorSupport.Accessor_2)variant).Value); + yield return f(variant.UnsafeGet(new global::dotVariant.Accessor._2())); } else { @@ -1329,9 +1368,9 @@ public static partial class Variant_class_nullable_enableEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 3) + if (variant.Index == 3) { - yield return s(((global::dotVariant.GeneratorSupport.Accessor_3)variant).Value); + yield return s(variant.UnsafeGet(new global::dotVariant.Accessor._3())); } else { @@ -1357,9 +1396,9 @@ public static partial class Variant_class_nullable_enableEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 4) + if (variant.Index == 4) { - yield return a(((global::dotVariant.GeneratorSupport.Accessor_4)variant).Value); + yield return a(variant.UnsafeGet(new global::dotVariant.Accessor._4())); } else { @@ -1386,9 +1425,9 @@ public static partial class Variant_class_nullable_enableEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 1) + if (variant.Index == 1) { - yield return i(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return i(variant.UnsafeGet(new global::dotVariant.Accessor._1())); } else { @@ -1414,9 +1453,9 @@ public static partial class Variant_class_nullable_enableEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 2) + if (variant.Index == 2) { - yield return f(((global::dotVariant.GeneratorSupport.Accessor_2)variant).Value); + yield return f(variant.UnsafeGet(new global::dotVariant.Accessor._2())); } else { @@ -1442,9 +1481,9 @@ public static partial class Variant_class_nullable_enableEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 3) + if (variant.Index == 3) { - yield return s(((global::dotVariant.GeneratorSupport.Accessor_3)variant).Value); + yield return s(variant.UnsafeGet(new global::dotVariant.Accessor._3())); } else { @@ -1470,9 +1509,9 @@ public static partial class Variant_class_nullable_enableEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 4) + if (variant.Index == 4) { - yield return a(((global::dotVariant.GeneratorSupport.Accessor_4)variant).Value); + yield return a(variant.UnsafeGet(new global::dotVariant.Accessor._4())); } else { @@ -1502,22 +1541,22 @@ public static partial class Variant_class_nullable_enableEx { foreach (var variant in source) { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant)) + switch (variant.Index) { case 0: global::dotVariant.GeneratorSupport.Errors.ThrowEmptyError("Foo.Variant_class_nullable_enable"); yield break; case 1: - yield return i(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return i(variant.UnsafeGet(new global::dotVariant.Accessor._1())); break; case 2: - yield return f(((global::dotVariant.GeneratorSupport.Accessor_2)variant).Value); + yield return f(variant.UnsafeGet(new global::dotVariant.Accessor._2())); break; case 3: - yield return s(((global::dotVariant.GeneratorSupport.Accessor_3)variant).Value); + yield return s(variant.UnsafeGet(new global::dotVariant.Accessor._3())); break; case 4: - yield return a(((global::dotVariant.GeneratorSupport.Accessor_4)variant).Value); + yield return a(variant.UnsafeGet(new global::dotVariant.Accessor._4())); break; default: global::dotVariant.GeneratorSupport.Errors.ThrowInternalError("Foo.Variant_class_nullable_enable"); @@ -1547,22 +1586,22 @@ public static partial class Variant_class_nullable_enableEx { foreach (var variant in source) { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant)) + switch (variant.Index) { case 0: yield return _(); break; case 1: - yield return i(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return i(variant.UnsafeGet(new global::dotVariant.Accessor._1())); break; case 2: - yield return f(((global::dotVariant.GeneratorSupport.Accessor_2)variant).Value); + yield return f(variant.UnsafeGet(new global::dotVariant.Accessor._2())); break; case 3: - yield return s(((global::dotVariant.GeneratorSupport.Accessor_3)variant).Value); + yield return s(variant.UnsafeGet(new global::dotVariant.Accessor._3())); break; case 4: - yield return a(((global::dotVariant.GeneratorSupport.Accessor_4)variant).Value); + yield return a(variant.UnsafeGet(new global::dotVariant.Accessor._4())); break; default: global::dotVariant.GeneratorSupport.Errors.ThrowInternalError("Foo.Variant_class_nullable_enable"); @@ -1590,8 +1629,8 @@ public static partial class Variant_class_nullable_enableEx global::System.Func i) { return global::System.Reactive.Linq.Observable.Select( - global::System.Reactive.Linq.Observable.Where(source, _variant => ((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 1), - _variant => i(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value)); + global::System.Reactive.Linq.Observable.Where(source, _variant => _variant.Index == 1), + _variant => i(_variant.UnsafeGet(new global::dotVariant.Accessor._1()))); } /// /// Projects each element of an observable sequence @@ -1607,8 +1646,8 @@ public static partial class Variant_class_nullable_enableEx global::System.Func f) { return global::System.Reactive.Linq.Observable.Select( - global::System.Reactive.Linq.Observable.Where(source, _variant => ((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 2), - _variant => f(((global::dotVariant.GeneratorSupport.Accessor_2)_variant).Value)); + global::System.Reactive.Linq.Observable.Where(source, _variant => _variant.Index == 2), + _variant => f(_variant.UnsafeGet(new global::dotVariant.Accessor._2()))); } /// /// Projects each element of an observable sequence @@ -1624,8 +1663,8 @@ public static partial class Variant_class_nullable_enableEx global::System.Func s) { return global::System.Reactive.Linq.Observable.Select( - global::System.Reactive.Linq.Observable.Where(source, _variant => ((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 3), - _variant => s(((global::dotVariant.GeneratorSupport.Accessor_3)_variant).Value)); + global::System.Reactive.Linq.Observable.Where(source, _variant => _variant.Index == 3), + _variant => s(_variant.UnsafeGet(new global::dotVariant.Accessor._3()))); } /// /// Projects each element of an observable sequence @@ -1641,8 +1680,8 @@ public static partial class Variant_class_nullable_enableEx global::System.Func a) { return global::System.Reactive.Linq.Observable.Select( - global::System.Reactive.Linq.Observable.Where(source, _variant => ((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 4), - _variant => a(((global::dotVariant.GeneratorSupport.Accessor_4)_variant).Value)); + global::System.Reactive.Linq.Observable.Where(source, _variant => _variant.Index == 4), + _variant => a(_variant.UnsafeGet(new global::dotVariant.Accessor._4()))); } /// @@ -1662,9 +1701,9 @@ public static partial class Variant_class_nullable_enableEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 1) + if (_variant.Index == 1) { - return i(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + return i(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); } else { @@ -1689,9 +1728,9 @@ public static partial class Variant_class_nullable_enableEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 2) + if (_variant.Index == 2) { - return f(((global::dotVariant.GeneratorSupport.Accessor_2)_variant).Value); + return f(_variant.UnsafeGet(new global::dotVariant.Accessor._2())); } else { @@ -1716,9 +1755,9 @@ public static partial class Variant_class_nullable_enableEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 3) + if (_variant.Index == 3) { - return s(((global::dotVariant.GeneratorSupport.Accessor_3)_variant).Value); + return s(_variant.UnsafeGet(new global::dotVariant.Accessor._3())); } else { @@ -1743,9 +1782,9 @@ public static partial class Variant_class_nullable_enableEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 4) + if (_variant.Index == 4) { - return a(((global::dotVariant.GeneratorSupport.Accessor_4)_variant).Value); + return a(_variant.UnsafeGet(new global::dotVariant.Accessor._4())); } else { @@ -1771,9 +1810,9 @@ public static partial class Variant_class_nullable_enableEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 1) + if (_variant.Index == 1) { - return i(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + return i(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); } else { @@ -1798,9 +1837,9 @@ public static partial class Variant_class_nullable_enableEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 2) + if (_variant.Index == 2) { - return f(((global::dotVariant.GeneratorSupport.Accessor_2)_variant).Value); + return f(_variant.UnsafeGet(new global::dotVariant.Accessor._2())); } else { @@ -1825,9 +1864,9 @@ public static partial class Variant_class_nullable_enableEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 3) + if (_variant.Index == 3) { - return s(((global::dotVariant.GeneratorSupport.Accessor_3)_variant).Value); + return s(_variant.UnsafeGet(new global::dotVariant.Accessor._3())); } else { @@ -1852,9 +1891,9 @@ public static partial class Variant_class_nullable_enableEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 4) + if (_variant.Index == 4) { - return a(((global::dotVariant.GeneratorSupport.Accessor_4)_variant).Value); + return a(_variant.UnsafeGet(new global::dotVariant.Accessor._4())); } else { @@ -1881,18 +1920,18 @@ public static partial class Variant_class_nullable_enableEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant)) + switch (_variant.Index) { case 0: return global::dotVariant.GeneratorSupport.Errors.ThrowEmptyError("Foo.Variant_class_nullable_enable"); case 1: - return i(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + return i(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); case 2: - return f(((global::dotVariant.GeneratorSupport.Accessor_2)_variant).Value); + return f(_variant.UnsafeGet(new global::dotVariant.Accessor._2())); case 3: - return s(((global::dotVariant.GeneratorSupport.Accessor_3)_variant).Value); + return s(_variant.UnsafeGet(new global::dotVariant.Accessor._3())); case 4: - return a(((global::dotVariant.GeneratorSupport.Accessor_4)_variant).Value); + return a(_variant.UnsafeGet(new global::dotVariant.Accessor._4())); default: return global::dotVariant.GeneratorSupport.Errors.ThrowInternalError("Foo.Variant_class_nullable_enable"); } @@ -1919,18 +1958,18 @@ public static partial class Variant_class_nullable_enableEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant)) + switch (_variant.Index) { case 0: return _(); case 1: - return i(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + return i(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); case 2: - return f(((global::dotVariant.GeneratorSupport.Accessor_2)_variant).Value); + return f(_variant.UnsafeGet(new global::dotVariant.Accessor._2())); case 3: - return s(((global::dotVariant.GeneratorSupport.Accessor_3)_variant).Value); + return s(_variant.UnsafeGet(new global::dotVariant.Accessor._3())); case 4: - return a(((global::dotVariant.GeneratorSupport.Accessor_4)_variant).Value); + return a(_variant.UnsafeGet(new global::dotVariant.Accessor._4())); default: return global::dotVariant.GeneratorSupport.Errors.ThrowInternalError("Foo.Variant_class_nullable_enable"); } @@ -2092,7 +2131,7 @@ public void Dispose() public void OnNext(global::Foo.Variant_class_nullable_enable _variant) { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant)) + switch (_variant.Index) { case 0: if (_accept0) @@ -2105,16 +2144,16 @@ public void OnNext(global::Foo.Variant_class_nullable_enable _variant) } break; case 1: - Subject1.OnNext(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + Subject1.OnNext(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); break; case 2: - Subject2.OnNext(((global::dotVariant.GeneratorSupport.Accessor_2)_variant).Value); + Subject2.OnNext(_variant.UnsafeGet(new global::dotVariant.Accessor._2())); break; case 3: - Subject3.OnNext(((global::dotVariant.GeneratorSupport.Accessor_3)_variant).Value); + Subject3.OnNext(_variant.UnsafeGet(new global::dotVariant.Accessor._3())); break; case 4: - Subject4.OnNext(((global::dotVariant.GeneratorSupport.Accessor_4)_variant).Value); + Subject4.OnNext(_variant.UnsafeGet(new global::dotVariant.Accessor._4())); break; default: OnError(global::dotVariant.GeneratorSupport.Errors.MakeInternalError("Foo.Variant_class_nullable_enable")); diff --git a/src/dotVariant.Generator.Test/samples/Variant-disposable.out.cs b/src/dotVariant.Generator.Test/samples/Variant-disposable.out.cs index 7ee07f7..c21bae9 100644 --- a/src/dotVariant.Generator.Test/samples/Variant-disposable.out.cs +++ b/src/dotVariant.Generator.Test/samples/Variant-disposable.out.cs @@ -73,6 +73,11 @@ public void Dispose() public bool IsEmpty => _variant.IsEmpty; + /// + [global::System.Diagnostics.DebuggerNonUserCode] + public byte Index + => _variant.Index; + /// [global::System.Diagnostics.DebuggerNonUserCode] public override bool Equals(object other) @@ -100,6 +105,11 @@ public override int GetHashCode() public override string ToString() => _variant.ToString(); + /// + [global::System.Diagnostics.DebuggerNonUserCode] + public int UnsafeGet(global::dotVariant.Accessor._1 accessor) + => _variant.UnsafeGet(accessor); + /// [global::System.Diagnostics.DebuggerNonUserCode] public bool TryMatch(out int i) @@ -140,6 +150,11 @@ public TResult Match(global::System.Func i, TResult _) public TResult Match(global::System.Func i, global::System.Func _) => _variant.Match(i, _); + /// + [global::System.Diagnostics.DebuggerNonUserCode] + public global::System.IO.Stream UnsafeGet(global::dotVariant.Accessor._2 accessor) + => _variant.UnsafeGet(accessor); + /// [global::System.Diagnostics.DebuggerNonUserCode] public bool TryMatch(out global::System.IO.Stream stream) @@ -213,19 +228,6 @@ public __DebuggerTypeProxy(Variant_disposable v) #pragma warning restore 8604, 8625 } } - - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - [global::System.Diagnostics.DebuggerNonUserCode] - public static explicit operator global::dotVariant.GeneratorSupport.Discriminator(Variant_disposable v) - => (global::dotVariant.GeneratorSupport.Discriminator)v._variant; - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - [global::System.Diagnostics.DebuggerNonUserCode] - public static explicit operator global::dotVariant.GeneratorSupport.Accessor_1(Variant_disposable v) - => (global::dotVariant.GeneratorSupport.Accessor_1)v._variant; - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - [global::System.Diagnostics.DebuggerNonUserCode] - public static explicit operator global::dotVariant.GeneratorSupport.Accessor_2(Variant_disposable v) - => (global::dotVariant.GeneratorSupport.Accessor_2)v._variant; } } @@ -253,16 +255,22 @@ public Union(global::System.IO.Stream value) } private readonly Union _x; - private readonly byte _n; + + /// + /// The 1-based index of the currently stored type, + /// counted left-ro-right from the parameter list. + /// 0 if the variant is empty. + /// + public readonly byte Index; public Variant_disposable(int i) { - _n = 1; + Index = 1; _x = new Union(i); } public Variant_disposable(global::System.IO.Stream stream) { - _n = 2; + Index = 2; _x = new Union(stream); } @@ -272,7 +280,7 @@ public Variant_disposable(global::System.IO.Stream stream) /// public void Dispose() { - switch (_n) + switch (this.Index) { case 0: break; @@ -287,17 +295,10 @@ public void Dispose() } } - public static explicit operator global::dotVariant.GeneratorSupport.Discriminator(in Variant_disposable v) - => (global::dotVariant.GeneratorSupport.Discriminator)v._n; - public static explicit operator global::dotVariant.GeneratorSupport.Accessor_1(in Variant_disposable v) - => new global::dotVariant.GeneratorSupport.Accessor_1(v._x._1); - public static explicit operator global::dotVariant.GeneratorSupport.Accessor_2(in Variant_disposable v) - => new global::dotVariant.GeneratorSupport.Accessor_2(v._x._2); - /// /// if Variant_disposable was constructed without a value. /// - public bool IsEmpty => _n == 0; + public bool IsEmpty => this.Index == 0; /// /// The string representation of the stored value's type. @@ -306,7 +307,7 @@ public string TypeString { get { - switch (_n) + switch (this.Index) { case 0: return ""; @@ -325,7 +326,7 @@ public string TypeString /// public override string ToString() { - switch (_n) + switch (this.Index) { case 0: return ""; @@ -345,7 +346,7 @@ public object AsObject { get { - switch (_n) + switch (this.Index) { case 0: return null; @@ -361,11 +362,11 @@ public object AsObject public bool Equals(in Variant_disposable other) { - if (_n != other._n) + if (this.Index != other.Index) { return false; } - switch (_n) + switch (Index) { case 0: return true; @@ -380,7 +381,7 @@ public bool Equals(in Variant_disposable other) public override int GetHashCode() { - switch (_n) + switch (this.Index) { case 0: return 0; @@ -393,6 +394,16 @@ public override int GetHashCode() } } + /// + /// Retrieve the stored value assuming it is of type . + /// + /// Only call this if you have ensured that Index == 1, + /// otherwise the correctness of the returned value is not guaranteed, + /// nor that any value is returned at all. + /// + public int UnsafeGet(global::dotVariant.Accessor._1 _) + => _x._1; + /// /// Retrieve the value stored within Variant_disposable if it is of type . /// @@ -400,8 +411,8 @@ public override int GetHashCode() /// if Variant_disposable contained a value of type . public bool TryMatch(out int i) { - i = _n == 1 ? _x._1 : default; - return _n == 1; + i = this.Index == 1 ? _x._1 : default; + return this.Index == 1; } /// @@ -412,7 +423,7 @@ public bool TryMatch(out int i) /// Any exception thrown from is rethrown. public bool TryMatch(global::System.Action i) { - if (_n == 1) + if (this.Index == 1) { i(_x._1); return true; @@ -428,7 +439,7 @@ public bool TryMatch(global::System.Action i) /// Variant_disposable does not contain a value of type . public void Match(out int i) { - if (_n == 1) + if (this.Index == 1) { i = _x._1; return; @@ -445,7 +456,7 @@ public void Match(out int i) /// Any exception thrown from is rethrown. public void Match(global::System.Action i) { - if (_n == 1) + if (this.Index == 1) { i(_x._1); return; @@ -462,7 +473,7 @@ public void Match(global::System.Action i) /// Any exception thrown from or is rethrown. public void Match(global::System.Action i, global::System.Action _) { - if (_n == 1) + if (this.Index == 1) { i(_x._1); } @@ -482,7 +493,7 @@ public void Match(global::System.Action i, global::System.Action _) /// Any exception thrown from is rethrown. public TResult Match(global::System.Func i) { - if (_n == 1) + if (this.Index == 1) { return i(_x._1); } @@ -499,7 +510,7 @@ public TResult Match(global::System.Func i) /// Any exception thrown from or is rethrown. public TResult Match(global::System.Func i, TResult _) { - return _n == 1 ? i(_x._1) : _; + return this.Index == 1 ? i(_x._1) : _; } /// @@ -511,8 +522,18 @@ public TResult Match(global::System.Func i, TResult _) /// Any exception thrown from or is rethrown. public TResult Match(global::System.Func i, global::System.Func _) { - return _n == 1 ? i(_x._1) : _(); + return this.Index == 1 ? i(_x._1) : _(); } + /// + /// Retrieve the stored value assuming it is of type . + /// + /// Only call this if you have ensured that Index == 2, + /// otherwise the correctness of the returned value is not guaranteed, + /// nor that any value is returned at all. + /// + public global::System.IO.Stream UnsafeGet(global::dotVariant.Accessor._2 _) + => _x._2; + /// /// Retrieve the value stored within Variant_disposable if it is of type . /// @@ -520,8 +541,8 @@ public TResult Match(global::System.Func i, global::Syste /// if Variant_disposable contained a value of type . public bool TryMatch(out global::System.IO.Stream stream) { - stream = _n == 2 ? _x._2 : default; - return _n == 2; + stream = this.Index == 2 ? _x._2 : default; + return this.Index == 2; } /// @@ -532,7 +553,7 @@ public bool TryMatch(out global::System.IO.Stream stream) /// Any exception thrown from is rethrown. public bool TryMatch(global::System.Action stream) { - if (_n == 2) + if (this.Index == 2) { stream(_x._2); return true; @@ -548,7 +569,7 @@ public bool TryMatch(global::System.Action stream) /// Variant_disposable does not contain a value of type . public void Match(out global::System.IO.Stream stream) { - if (_n == 2) + if (this.Index == 2) { stream = _x._2; return; @@ -565,7 +586,7 @@ public void Match(out global::System.IO.Stream stream) /// Any exception thrown from is rethrown. public void Match(global::System.Action stream) { - if (_n == 2) + if (this.Index == 2) { stream(_x._2); return; @@ -582,7 +603,7 @@ public void Match(global::System.Action stream) /// Any exception thrown from or is rethrown. public void Match(global::System.Action stream, global::System.Action _) { - if (_n == 2) + if (this.Index == 2) { stream(_x._2); } @@ -602,7 +623,7 @@ public void Match(global::System.Action stream, global /// Any exception thrown from is rethrown. public TResult Match(global::System.Func stream) { - if (_n == 2) + if (this.Index == 2) { return stream(_x._2); } @@ -619,7 +640,7 @@ public TResult Match(global::System.FuncAny exception thrown from or is rethrown. public TResult Match(global::System.Func stream, TResult _) { - return _n == 2 ? stream(_x._2) : _; + return this.Index == 2 ? stream(_x._2) : _; } /// @@ -631,7 +652,7 @@ public TResult Match(global::System.FuncAny exception thrown from or is rethrown. public TResult Match(global::System.Func stream, global::System.Func _) { - return _n == 2 ? stream(_x._2) : _(); + return this.Index == 2 ? stream(_x._2) : _(); } /// @@ -644,7 +665,7 @@ public TResult Match(global::System.FuncAny exception thrown from a delegate is rethrown. public void Visit(global::System.Action i, global::System.Action stream, global::System.Action _) { - switch (_n) + switch (this.Index) { case 0: _(); @@ -671,7 +692,7 @@ public void Visit(global::System.Action i, global::System.ActionAny exception thrown from a delegate is rethrown. public void Visit(global::System.Action i, global::System.Action stream) { - switch (_n) + switch (this.Index) { case 0: global::dotVariant.GeneratorSupport.Errors.ThrowEmptyError("Foo.Variant_disposable"); @@ -699,7 +720,7 @@ public void Visit(global::System.Action i, global::System.ActionThe return type of all delegates, and by extension the return type of this function. public TResult Visit(global::System.Func i, global::System.Func stream, global::System.Func _) { - switch (_n) + switch (this.Index) { case 0: return _(); @@ -723,7 +744,7 @@ public TResult Visit(global::System.Func i, global::Syste /// The return type of all delegates, and by extension the return type of this function. public TResult Visit(global::System.Func i, global::System.Func stream) { - switch (_n) + switch (this.Index) { case 0: return global::dotVariant.GeneratorSupport.Errors.ThrowEmptyError("Foo.Variant_disposable"); @@ -759,9 +780,9 @@ public static partial class Variant_disposableEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 1) + if (variant.Index == 1) { - yield return i(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return i(variant.UnsafeGet(new global::dotVariant.Accessor._1())); } } } @@ -781,9 +802,9 @@ public static partial class Variant_disposableEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 2) + if (variant.Index == 2) { - yield return stream(((global::dotVariant.GeneratorSupport.Accessor_2)variant).Value); + yield return stream(variant.UnsafeGet(new global::dotVariant.Accessor._2())); } } } @@ -806,9 +827,9 @@ public static partial class Variant_disposableEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 1) + if (variant.Index == 1) { - yield return i(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return i(variant.UnsafeGet(new global::dotVariant.Accessor._1())); } else { @@ -834,9 +855,9 @@ public static partial class Variant_disposableEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 2) + if (variant.Index == 2) { - yield return stream(((global::dotVariant.GeneratorSupport.Accessor_2)variant).Value); + yield return stream(variant.UnsafeGet(new global::dotVariant.Accessor._2())); } else { @@ -863,9 +884,9 @@ public static partial class Variant_disposableEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 1) + if (variant.Index == 1) { - yield return i(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return i(variant.UnsafeGet(new global::dotVariant.Accessor._1())); } else { @@ -891,9 +912,9 @@ public static partial class Variant_disposableEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 2) + if (variant.Index == 2) { - yield return stream(((global::dotVariant.GeneratorSupport.Accessor_2)variant).Value); + yield return stream(variant.UnsafeGet(new global::dotVariant.Accessor._2())); } else { @@ -921,16 +942,16 @@ public static partial class Variant_disposableEx { foreach (var variant in source) { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant)) + switch (variant.Index) { case 0: global::dotVariant.GeneratorSupport.Errors.ThrowEmptyError("Foo.Variant_disposable"); yield break; case 1: - yield return i(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return i(variant.UnsafeGet(new global::dotVariant.Accessor._1())); break; case 2: - yield return stream(((global::dotVariant.GeneratorSupport.Accessor_2)variant).Value); + yield return stream(variant.UnsafeGet(new global::dotVariant.Accessor._2())); break; default: global::dotVariant.GeneratorSupport.Errors.ThrowInternalError("Foo.Variant_disposable"); @@ -958,16 +979,16 @@ public static partial class Variant_disposableEx { foreach (var variant in source) { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant)) + switch (variant.Index) { case 0: yield return _(); break; case 1: - yield return i(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return i(variant.UnsafeGet(new global::dotVariant.Accessor._1())); break; case 2: - yield return stream(((global::dotVariant.GeneratorSupport.Accessor_2)variant).Value); + yield return stream(variant.UnsafeGet(new global::dotVariant.Accessor._2())); break; default: global::dotVariant.GeneratorSupport.Errors.ThrowInternalError("Foo.Variant_disposable"); @@ -995,8 +1016,8 @@ public static partial class Variant_disposableEx global::System.Func i) { return global::System.Reactive.Linq.Observable.Select( - global::System.Reactive.Linq.Observable.Where(source, _variant => ((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 1), - _variant => i(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value)); + global::System.Reactive.Linq.Observable.Where(source, _variant => _variant.Index == 1), + _variant => i(_variant.UnsafeGet(new global::dotVariant.Accessor._1()))); } /// /// Projects each element of an observable sequence @@ -1012,8 +1033,8 @@ public static partial class Variant_disposableEx global::System.Func stream) { return global::System.Reactive.Linq.Observable.Select( - global::System.Reactive.Linq.Observable.Where(source, _variant => ((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 2), - _variant => stream(((global::dotVariant.GeneratorSupport.Accessor_2)_variant).Value)); + global::System.Reactive.Linq.Observable.Where(source, _variant => _variant.Index == 2), + _variant => stream(_variant.UnsafeGet(new global::dotVariant.Accessor._2()))); } /// @@ -1033,9 +1054,9 @@ public static partial class Variant_disposableEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 1) + if (_variant.Index == 1) { - return i(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + return i(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); } else { @@ -1060,9 +1081,9 @@ public static partial class Variant_disposableEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 2) + if (_variant.Index == 2) { - return stream(((global::dotVariant.GeneratorSupport.Accessor_2)_variant).Value); + return stream(_variant.UnsafeGet(new global::dotVariant.Accessor._2())); } else { @@ -1088,9 +1109,9 @@ public static partial class Variant_disposableEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 1) + if (_variant.Index == 1) { - return i(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + return i(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); } else { @@ -1115,9 +1136,9 @@ public static partial class Variant_disposableEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 2) + if (_variant.Index == 2) { - return stream(((global::dotVariant.GeneratorSupport.Accessor_2)_variant).Value); + return stream(_variant.UnsafeGet(new global::dotVariant.Accessor._2())); } else { @@ -1142,14 +1163,14 @@ public static partial class Variant_disposableEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant)) + switch (_variant.Index) { case 0: return global::dotVariant.GeneratorSupport.Errors.ThrowEmptyError("Foo.Variant_disposable"); case 1: - return i(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + return i(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); case 2: - return stream(((global::dotVariant.GeneratorSupport.Accessor_2)_variant).Value); + return stream(_variant.UnsafeGet(new global::dotVariant.Accessor._2())); default: return global::dotVariant.GeneratorSupport.Errors.ThrowInternalError("Foo.Variant_disposable"); } @@ -1174,14 +1195,14 @@ public static partial class Variant_disposableEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant)) + switch (_variant.Index) { case 0: return _(); case 1: - return i(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + return i(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); case 2: - return stream(((global::dotVariant.GeneratorSupport.Accessor_2)_variant).Value); + return stream(_variant.UnsafeGet(new global::dotVariant.Accessor._2())); default: return global::dotVariant.GeneratorSupport.Errors.ThrowInternalError("Foo.Variant_disposable"); } @@ -1335,7 +1356,7 @@ public void Dispose() public void OnNext(global::Foo.Variant_disposable _variant) { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant)) + switch (_variant.Index) { case 0: if (_accept0) @@ -1348,10 +1369,10 @@ public void OnNext(global::Foo.Variant_disposable _variant) } break; case 1: - Subject1.OnNext(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + Subject1.OnNext(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); break; case 2: - Subject2.OnNext(((global::dotVariant.GeneratorSupport.Accessor_2)_variant).Value); + Subject2.OnNext(_variant.UnsafeGet(new global::dotVariant.Accessor._2())); break; default: OnError(global::dotVariant.GeneratorSupport.Errors.MakeInternalError("Foo.Variant_disposable")); diff --git a/src/dotVariant.Generator.Test/samples/Variant-generic-T-as-nullable.out.cs b/src/dotVariant.Generator.Test/samples/Variant-generic-T-as-nullable.out.cs index 3f92f26..09fe3f9 100644 --- a/src/dotVariant.Generator.Test/samples/Variant-generic-T-as-nullable.out.cs +++ b/src/dotVariant.Generator.Test/samples/Variant-generic-T-as-nullable.out.cs @@ -149,6 +149,11 @@ public static Variant Create(T6? f) public bool IsEmpty => _variant.IsEmpty; + /// + [global::System.Diagnostics.DebuggerNonUserCode] + public byte Index + => _variant.Index; + /// [global::System.Diagnostics.DebuggerNonUserCode] public override bool Equals(object? other) @@ -176,6 +181,11 @@ public override int GetHashCode() public override string ToString() => _variant.ToString(); + /// + [global::System.Diagnostics.DebuggerNonUserCode] + public T1? UnsafeGet(global::dotVariant.Accessor._1 accessor) + => _variant.UnsafeGet(accessor); + /// [global::System.Diagnostics.DebuggerNonUserCode] public bool TryMatch(out T1? a) @@ -216,6 +226,11 @@ public TResult Match(global::System.Func a, TResult _) public TResult Match(global::System.Func a, global::System.Func _) => _variant.Match(a, _); + /// + [global::System.Diagnostics.DebuggerNonUserCode] + public T2? UnsafeGet(global::dotVariant.Accessor._2 accessor) + => _variant.UnsafeGet(accessor); + /// [global::System.Diagnostics.DebuggerNonUserCode] public bool TryMatch(out T2? b) @@ -256,6 +271,11 @@ public TResult Match(global::System.Func b, TResult _) public TResult Match(global::System.Func b, global::System.Func _) => _variant.Match(b, _); + /// + [global::System.Diagnostics.DebuggerNonUserCode] + public T3? UnsafeGet(global::dotVariant.Accessor._3 accessor) + => _variant.UnsafeGet(accessor); + /// [global::System.Diagnostics.DebuggerNonUserCode] public bool TryMatch(out T3? c) @@ -296,6 +316,11 @@ public TResult Match(global::System.Func c, TResult _) public TResult Match(global::System.Func c, global::System.Func _) => _variant.Match(c, _); + /// + [global::System.Diagnostics.DebuggerNonUserCode] + public T4? UnsafeGet(global::dotVariant.Accessor._4 accessor) + => _variant.UnsafeGet(accessor); + /// [global::System.Diagnostics.DebuggerNonUserCode] public bool TryMatch(out T4? d) @@ -336,6 +361,11 @@ public TResult Match(global::System.Func d, TResult _) public TResult Match(global::System.Func d, global::System.Func _) => _variant.Match(d, _); + /// + [global::System.Diagnostics.DebuggerNonUserCode] + public T5? UnsafeGet(global::dotVariant.Accessor._5 accessor) + => _variant.UnsafeGet(accessor); + /// [global::System.Diagnostics.DebuggerNonUserCode] public bool TryMatch(out T5? e) @@ -376,6 +406,11 @@ public TResult Match(global::System.Func e, TResult _) public TResult Match(global::System.Func e, global::System.Func _) => _variant.Match(e, _); + /// + [global::System.Diagnostics.DebuggerNonUserCode] + public T6? UnsafeGet(global::dotVariant.Accessor._6 accessor) + => _variant.UnsafeGet(accessor); + /// [global::System.Diagnostics.DebuggerNonUserCode] public bool TryMatch(out T6? f) @@ -449,35 +484,6 @@ public __DebuggerTypeProxy(Variant v) #pragma warning restore 8604, 8625 } } - - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - [global::System.Diagnostics.DebuggerNonUserCode] - public static explicit operator global::dotVariant.GeneratorSupport.Discriminator(Variant v) - => (global::dotVariant.GeneratorSupport.Discriminator)v._variant; - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - [global::System.Diagnostics.DebuggerNonUserCode] - public static explicit operator global::dotVariant.GeneratorSupport.Accessor_1(Variant v) - => (global::dotVariant.GeneratorSupport.Accessor_1)v._variant; - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - [global::System.Diagnostics.DebuggerNonUserCode] - public static explicit operator global::dotVariant.GeneratorSupport.Accessor_2(Variant v) - => (global::dotVariant.GeneratorSupport.Accessor_2)v._variant; - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - [global::System.Diagnostics.DebuggerNonUserCode] - public static explicit operator global::dotVariant.GeneratorSupport.Accessor_3(Variant v) - => (global::dotVariant.GeneratorSupport.Accessor_3)v._variant; - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - [global::System.Diagnostics.DebuggerNonUserCode] - public static explicit operator global::dotVariant.GeneratorSupport.Accessor_4(Variant v) - => (global::dotVariant.GeneratorSupport.Accessor_4)v._variant; - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - [global::System.Diagnostics.DebuggerNonUserCode] - public static explicit operator global::dotVariant.GeneratorSupport.Accessor_5(Variant v) - => (global::dotVariant.GeneratorSupport.Accessor_5)v._variant; - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - [global::System.Diagnostics.DebuggerNonUserCode] - public static explicit operator global::dotVariant.GeneratorSupport.Accessor_6(Variant v) - => (global::dotVariant.GeneratorSupport.Accessor_6)v._variant; } } @@ -557,59 +563,50 @@ public Union(T6? value) } private readonly Union _x; - private readonly byte _n; + + /// + /// The 1-based index of the currently stored type, + /// counted left-ro-right from the parameter list. + /// 0 if the variant is empty. + /// + public readonly byte Index; public Variant(T1? a) { - _n = 1; + Index = 1; _x = new Union(a); } public Variant(T2? b) { - _n = 2; + Index = 2; _x = new Union(b); } public Variant(T3? c) { - _n = 3; + Index = 3; _x = new Union(c); } public Variant(T4? d) { - _n = 4; + Index = 4; _x = new Union(d); } public Variant(T5? e) { - _n = 5; + Index = 5; _x = new Union(e); } public Variant(T6? f) { - _n = 6; + Index = 6; _x = new Union(f); } - public static explicit operator global::dotVariant.GeneratorSupport.Discriminator(in Variant v) - => (global::dotVariant.GeneratorSupport.Discriminator)v._n; - public static explicit operator global::dotVariant.GeneratorSupport.Accessor_1(in Variant v) - => new global::dotVariant.GeneratorSupport.Accessor_1(v._x._1); - public static explicit operator global::dotVariant.GeneratorSupport.Accessor_2(in Variant v) - => new global::dotVariant.GeneratorSupport.Accessor_2(v._x._2); - public static explicit operator global::dotVariant.GeneratorSupport.Accessor_3(in Variant v) - => new global::dotVariant.GeneratorSupport.Accessor_3(v._x._3); - public static explicit operator global::dotVariant.GeneratorSupport.Accessor_4(in Variant v) - => new global::dotVariant.GeneratorSupport.Accessor_4(v._x._4); - public static explicit operator global::dotVariant.GeneratorSupport.Accessor_5(in Variant v) - => new global::dotVariant.GeneratorSupport.Accessor_5(v._x._5); - public static explicit operator global::dotVariant.GeneratorSupport.Accessor_6(in Variant v) - => new global::dotVariant.GeneratorSupport.Accessor_6(v._x._6); - /// /// if Variant was constructed without a value. /// - public bool IsEmpty => _n == 0; + public bool IsEmpty => this.Index == 0; /// /// The string representation of the stored value's type. @@ -618,7 +615,7 @@ public string TypeString { get { - switch (_n) + switch (this.Index) { case 0: return ""; @@ -645,7 +642,7 @@ public string TypeString /// public override string ToString() { - switch (_n) + switch (this.Index) { case 0: return ""; @@ -673,7 +670,7 @@ public object? AsObject { get { - switch (_n) + switch (this.Index) { case 0: return null; @@ -697,11 +694,11 @@ public object? AsObject public bool Equals(in Variant other) { - if (_n != other._n) + if (this.Index != other.Index) { return false; } - switch (_n) + switch (Index) { case 0: return true; @@ -724,7 +721,7 @@ public bool Equals(in Variant other) public override int GetHashCode() { - switch (_n) + switch (this.Index) { case 0: return 0; @@ -745,6 +742,16 @@ public override int GetHashCode() } } + /// + /// Retrieve the stored value assuming it is of type . + /// + /// Only call this if you have ensured that Index == 1, + /// otherwise the correctness of the returned value is not guaranteed, + /// nor that any value is returned at all. + /// + public T1? UnsafeGet(global::dotVariant.Accessor._1 _) + => _x._1; + /// /// Retrieve the value stored within Variant if it is of type . /// @@ -752,8 +759,8 @@ public override int GetHashCode() /// if Variant contained a value of type . public bool TryMatch(out T1? a) { - a = _n == 1 ? _x._1 : default; - return _n == 1; + a = this.Index == 1 ? _x._1 : default; + return this.Index == 1; } /// @@ -764,7 +771,7 @@ public bool TryMatch(out T1? a) /// Any exception thrown from is rethrown. public bool TryMatch(global::System.Action a) { - if (_n == 1) + if (this.Index == 1) { a(_x._1); return true; @@ -780,7 +787,7 @@ public bool TryMatch(global::System.Action a) /// Variant does not contain a value of type . public void Match(out T1? a) { - if (_n == 1) + if (this.Index == 1) { a = _x._1; return; @@ -797,7 +804,7 @@ public void Match(out T1? a) /// Any exception thrown from is rethrown. public void Match(global::System.Action a) { - if (_n == 1) + if (this.Index == 1) { a(_x._1); return; @@ -814,7 +821,7 @@ public void Match(global::System.Action a) /// Any exception thrown from or is rethrown. public void Match(global::System.Action a, global::System.Action _) { - if (_n == 1) + if (this.Index == 1) { a(_x._1); } @@ -834,7 +841,7 @@ public void Match(global::System.Action a, global::System.Action _) /// Any exception thrown from is rethrown. public TResult Match(global::System.Func a) { - if (_n == 1) + if (this.Index == 1) { return a(_x._1); } @@ -851,7 +858,7 @@ public TResult Match(global::System.Func a) /// Any exception thrown from or is rethrown. public TResult Match(global::System.Func a, TResult _) { - return _n == 1 ? a(_x._1) : _; + return this.Index == 1 ? a(_x._1) : _; } /// @@ -863,8 +870,18 @@ public TResult Match(global::System.Func a, TResult _) /// Any exception thrown from or is rethrown. public TResult Match(global::System.Func a, global::System.Func _) { - return _n == 1 ? a(_x._1) : _(); + return this.Index == 1 ? a(_x._1) : _(); } + /// + /// Retrieve the stored value assuming it is of type . + /// + /// Only call this if you have ensured that Index == 2, + /// otherwise the correctness of the returned value is not guaranteed, + /// nor that any value is returned at all. + /// + public T2? UnsafeGet(global::dotVariant.Accessor._2 _) + => _x._2; + /// /// Retrieve the value stored within Variant if it is of type . /// @@ -872,8 +889,8 @@ public TResult Match(global::System.Func a, global::Syste /// if Variant contained a value of type . public bool TryMatch(out T2? b) { - b = _n == 2 ? _x._2 : default; - return _n == 2; + b = this.Index == 2 ? _x._2 : default; + return this.Index == 2; } /// @@ -884,7 +901,7 @@ public bool TryMatch(out T2? b) /// Any exception thrown from is rethrown. public bool TryMatch(global::System.Action b) { - if (_n == 2) + if (this.Index == 2) { b(_x._2); return true; @@ -900,7 +917,7 @@ public bool TryMatch(global::System.Action b) /// Variant does not contain a value of type . public void Match(out T2? b) { - if (_n == 2) + if (this.Index == 2) { b = _x._2; return; @@ -917,7 +934,7 @@ public void Match(out T2? b) /// Any exception thrown from is rethrown. public void Match(global::System.Action b) { - if (_n == 2) + if (this.Index == 2) { b(_x._2); return; @@ -934,7 +951,7 @@ public void Match(global::System.Action b) /// Any exception thrown from or is rethrown. public void Match(global::System.Action b, global::System.Action _) { - if (_n == 2) + if (this.Index == 2) { b(_x._2); } @@ -954,7 +971,7 @@ public void Match(global::System.Action b, global::System.Action _) /// Any exception thrown from is rethrown. public TResult Match(global::System.Func b) { - if (_n == 2) + if (this.Index == 2) { return b(_x._2); } @@ -971,7 +988,7 @@ public TResult Match(global::System.Func b) /// Any exception thrown from or is rethrown. public TResult Match(global::System.Func b, TResult _) { - return _n == 2 ? b(_x._2) : _; + return this.Index == 2 ? b(_x._2) : _; } /// @@ -983,8 +1000,18 @@ public TResult Match(global::System.Func b, TResult _) /// Any exception thrown from or is rethrown. public TResult Match(global::System.Func b, global::System.Func _) { - return _n == 2 ? b(_x._2) : _(); + return this.Index == 2 ? b(_x._2) : _(); } + /// + /// Retrieve the stored value assuming it is of type . + /// + /// Only call this if you have ensured that Index == 3, + /// otherwise the correctness of the returned value is not guaranteed, + /// nor that any value is returned at all. + /// + public T3? UnsafeGet(global::dotVariant.Accessor._3 _) + => _x._3; + /// /// Retrieve the value stored within Variant if it is of type . /// @@ -992,8 +1019,8 @@ public TResult Match(global::System.Func b, global::Syste /// if Variant contained a value of type . public bool TryMatch(out T3? c) { - c = _n == 3 ? _x._3 : default; - return _n == 3; + c = this.Index == 3 ? _x._3 : default; + return this.Index == 3; } /// @@ -1004,7 +1031,7 @@ public bool TryMatch(out T3? c) /// Any exception thrown from is rethrown. public bool TryMatch(global::System.Action c) { - if (_n == 3) + if (this.Index == 3) { c(_x._3); return true; @@ -1020,7 +1047,7 @@ public bool TryMatch(global::System.Action c) /// Variant does not contain a value of type . public void Match(out T3? c) { - if (_n == 3) + if (this.Index == 3) { c = _x._3; return; @@ -1037,7 +1064,7 @@ public void Match(out T3? c) /// Any exception thrown from is rethrown. public void Match(global::System.Action c) { - if (_n == 3) + if (this.Index == 3) { c(_x._3); return; @@ -1054,7 +1081,7 @@ public void Match(global::System.Action c) /// Any exception thrown from or is rethrown. public void Match(global::System.Action c, global::System.Action _) { - if (_n == 3) + if (this.Index == 3) { c(_x._3); } @@ -1074,7 +1101,7 @@ public void Match(global::System.Action c, global::System.Action _) /// Any exception thrown from is rethrown. public TResult Match(global::System.Func c) { - if (_n == 3) + if (this.Index == 3) { return c(_x._3); } @@ -1091,7 +1118,7 @@ public TResult Match(global::System.Func c) /// Any exception thrown from or is rethrown. public TResult Match(global::System.Func c, TResult _) { - return _n == 3 ? c(_x._3) : _; + return this.Index == 3 ? c(_x._3) : _; } /// @@ -1103,8 +1130,18 @@ public TResult Match(global::System.Func c, TResult _) /// Any exception thrown from or is rethrown. public TResult Match(global::System.Func c, global::System.Func _) { - return _n == 3 ? c(_x._3) : _(); + return this.Index == 3 ? c(_x._3) : _(); } + /// + /// Retrieve the stored value assuming it is of type . + /// + /// Only call this if you have ensured that Index == 4, + /// otherwise the correctness of the returned value is not guaranteed, + /// nor that any value is returned at all. + /// + public T4? UnsafeGet(global::dotVariant.Accessor._4 _) + => _x._4; + /// /// Retrieve the value stored within Variant if it is of type . /// @@ -1112,8 +1149,8 @@ public TResult Match(global::System.Func c, global::Syste /// if Variant contained a value of type . public bool TryMatch(out T4? d) { - d = _n == 4 ? _x._4 : default; - return _n == 4; + d = this.Index == 4 ? _x._4 : default; + return this.Index == 4; } /// @@ -1124,7 +1161,7 @@ public bool TryMatch(out T4? d) /// Any exception thrown from is rethrown. public bool TryMatch(global::System.Action d) { - if (_n == 4) + if (this.Index == 4) { d(_x._4); return true; @@ -1140,7 +1177,7 @@ public bool TryMatch(global::System.Action d) /// Variant does not contain a value of type . public void Match(out T4? d) { - if (_n == 4) + if (this.Index == 4) { d = _x._4; return; @@ -1157,7 +1194,7 @@ public void Match(out T4? d) /// Any exception thrown from is rethrown. public void Match(global::System.Action d) { - if (_n == 4) + if (this.Index == 4) { d(_x._4); return; @@ -1174,7 +1211,7 @@ public void Match(global::System.Action d) /// Any exception thrown from or is rethrown. public void Match(global::System.Action d, global::System.Action _) { - if (_n == 4) + if (this.Index == 4) { d(_x._4); } @@ -1194,7 +1231,7 @@ public void Match(global::System.Action d, global::System.Action _) /// Any exception thrown from is rethrown. public TResult Match(global::System.Func d) { - if (_n == 4) + if (this.Index == 4) { return d(_x._4); } @@ -1211,7 +1248,7 @@ public TResult Match(global::System.Func d) /// Any exception thrown from or is rethrown. public TResult Match(global::System.Func d, TResult _) { - return _n == 4 ? d(_x._4) : _; + return this.Index == 4 ? d(_x._4) : _; } /// @@ -1223,8 +1260,18 @@ public TResult Match(global::System.Func d, TResult _) /// Any exception thrown from or is rethrown. public TResult Match(global::System.Func d, global::System.Func _) { - return _n == 4 ? d(_x._4) : _(); + return this.Index == 4 ? d(_x._4) : _(); } + /// + /// Retrieve the stored value assuming it is of type . + /// + /// Only call this if you have ensured that Index == 5, + /// otherwise the correctness of the returned value is not guaranteed, + /// nor that any value is returned at all. + /// + public T5? UnsafeGet(global::dotVariant.Accessor._5 _) + => _x._5; + /// /// Retrieve the value stored within Variant if it is of type . /// @@ -1232,8 +1279,8 @@ public TResult Match(global::System.Func d, global::Syste /// if Variant contained a value of type . public bool TryMatch(out T5? e) { - e = _n == 5 ? _x._5 : default; - return _n == 5; + e = this.Index == 5 ? _x._5 : default; + return this.Index == 5; } /// @@ -1244,7 +1291,7 @@ public bool TryMatch(out T5? e) /// Any exception thrown from is rethrown. public bool TryMatch(global::System.Action e) { - if (_n == 5) + if (this.Index == 5) { e(_x._5); return true; @@ -1260,7 +1307,7 @@ public bool TryMatch(global::System.Action e) /// Variant does not contain a value of type . public void Match(out T5? e) { - if (_n == 5) + if (this.Index == 5) { e = _x._5; return; @@ -1277,7 +1324,7 @@ public void Match(out T5? e) /// Any exception thrown from is rethrown. public void Match(global::System.Action e) { - if (_n == 5) + if (this.Index == 5) { e(_x._5); return; @@ -1294,7 +1341,7 @@ public void Match(global::System.Action e) /// Any exception thrown from or is rethrown. public void Match(global::System.Action e, global::System.Action _) { - if (_n == 5) + if (this.Index == 5) { e(_x._5); } @@ -1314,7 +1361,7 @@ public void Match(global::System.Action e, global::System.Action _) /// Any exception thrown from is rethrown. public TResult Match(global::System.Func e) { - if (_n == 5) + if (this.Index == 5) { return e(_x._5); } @@ -1331,7 +1378,7 @@ public TResult Match(global::System.Func e) /// Any exception thrown from or is rethrown. public TResult Match(global::System.Func e, TResult _) { - return _n == 5 ? e(_x._5) : _; + return this.Index == 5 ? e(_x._5) : _; } /// @@ -1343,8 +1390,18 @@ public TResult Match(global::System.Func e, TResult _) /// Any exception thrown from or is rethrown. public TResult Match(global::System.Func e, global::System.Func _) { - return _n == 5 ? e(_x._5) : _(); + return this.Index == 5 ? e(_x._5) : _(); } + /// + /// Retrieve the stored value assuming it is of type . + /// + /// Only call this if you have ensured that Index == 6, + /// otherwise the correctness of the returned value is not guaranteed, + /// nor that any value is returned at all. + /// + public T6? UnsafeGet(global::dotVariant.Accessor._6 _) + => _x._6; + /// /// Retrieve the value stored within Variant if it is of type . /// @@ -1352,8 +1409,8 @@ public TResult Match(global::System.Func e, global::Syste /// if Variant contained a value of type . public bool TryMatch(out T6? f) { - f = _n == 6 ? _x._6 : default; - return _n == 6; + f = this.Index == 6 ? _x._6 : default; + return this.Index == 6; } /// @@ -1364,7 +1421,7 @@ public bool TryMatch(out T6? f) /// Any exception thrown from is rethrown. public bool TryMatch(global::System.Action f) { - if (_n == 6) + if (this.Index == 6) { f(_x._6); return true; @@ -1380,7 +1437,7 @@ public bool TryMatch(global::System.Action f) /// Variant does not contain a value of type . public void Match(out T6? f) { - if (_n == 6) + if (this.Index == 6) { f = _x._6; return; @@ -1397,7 +1454,7 @@ public void Match(out T6? f) /// Any exception thrown from is rethrown. public void Match(global::System.Action f) { - if (_n == 6) + if (this.Index == 6) { f(_x._6); return; @@ -1414,7 +1471,7 @@ public void Match(global::System.Action f) /// Any exception thrown from or is rethrown. public void Match(global::System.Action f, global::System.Action _) { - if (_n == 6) + if (this.Index == 6) { f(_x._6); } @@ -1434,7 +1491,7 @@ public void Match(global::System.Action f, global::System.Action _) /// Any exception thrown from is rethrown. public TResult Match(global::System.Func f) { - if (_n == 6) + if (this.Index == 6) { return f(_x._6); } @@ -1451,7 +1508,7 @@ public TResult Match(global::System.Func f) /// Any exception thrown from or is rethrown. public TResult Match(global::System.Func f, TResult _) { - return _n == 6 ? f(_x._6) : _; + return this.Index == 6 ? f(_x._6) : _; } /// @@ -1463,7 +1520,7 @@ public TResult Match(global::System.Func f, TResult _) /// Any exception thrown from or is rethrown. public TResult Match(global::System.Func f, global::System.Func _) { - return _n == 6 ? f(_x._6) : _(); + return this.Index == 6 ? f(_x._6) : _(); } /// @@ -1480,7 +1537,7 @@ public TResult Match(global::System.Func f, global::Syste /// Any exception thrown from a delegate is rethrown. public void Visit(global::System.Action a, global::System.Action b, global::System.Action c, global::System.Action d, global::System.Action e, global::System.Action f, global::System.Action _) { - switch (_n) + switch (this.Index) { case 0: _(); @@ -1523,7 +1580,7 @@ public void Visit(global::System.Action a, global::System.Action b, gl /// Any exception thrown from a delegate is rethrown. public void Visit(global::System.Action a, global::System.Action b, global::System.Action c, global::System.Action d, global::System.Action e, global::System.Action f) { - switch (_n) + switch (this.Index) { case 0: global::dotVariant.GeneratorSupport.Errors.ThrowEmptyError("Foo.Variant"); @@ -1567,7 +1624,7 @@ public void Visit(global::System.Action a, global::System.Action b, gl /// The return type of all delegates, and by extension the return type of this function. public TResult Visit(global::System.Func a, global::System.Func b, global::System.Func c, global::System.Func d, global::System.Func e, global::System.Func f, global::System.Func _) { - switch (_n) + switch (this.Index) { case 0: return _(); @@ -1603,7 +1660,7 @@ public TResult Visit(global::System.Func a, global::Syste /// The return type of all delegates, and by extension the return type of this function. public TResult Visit(global::System.Func a, global::System.Func b, global::System.Func c, global::System.Func d, global::System.Func e, global::System.Func f) { - switch (_n) + switch (this.Index) { case 0: return global::dotVariant.GeneratorSupport.Errors.ThrowEmptyError("Foo.Variant"); @@ -1652,9 +1709,9 @@ public static partial class VariantEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 1) + if (variant.Index == 1) { - yield return a(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return a(variant.UnsafeGet(new global::dotVariant.Accessor._1())); } } } @@ -1679,9 +1736,9 @@ public static partial class VariantEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 2) + if (variant.Index == 2) { - yield return b(((global::dotVariant.GeneratorSupport.Accessor_2)variant).Value); + yield return b(variant.UnsafeGet(new global::dotVariant.Accessor._2())); } } } @@ -1706,9 +1763,9 @@ public static partial class VariantEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 3) + if (variant.Index == 3) { - yield return c(((global::dotVariant.GeneratorSupport.Accessor_3)variant).Value); + yield return c(variant.UnsafeGet(new global::dotVariant.Accessor._3())); } } } @@ -1733,9 +1790,9 @@ public static partial class VariantEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 4) + if (variant.Index == 4) { - yield return d(((global::dotVariant.GeneratorSupport.Accessor_4)variant).Value); + yield return d(variant.UnsafeGet(new global::dotVariant.Accessor._4())); } } } @@ -1760,9 +1817,9 @@ public static partial class VariantEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 5) + if (variant.Index == 5) { - yield return e(((global::dotVariant.GeneratorSupport.Accessor_5)variant).Value); + yield return e(variant.UnsafeGet(new global::dotVariant.Accessor._5())); } } } @@ -1787,9 +1844,9 @@ public static partial class VariantEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 6) + if (variant.Index == 6) { - yield return f(((global::dotVariant.GeneratorSupport.Accessor_6)variant).Value); + yield return f(variant.UnsafeGet(new global::dotVariant.Accessor._6())); } } } @@ -1817,9 +1874,9 @@ public static partial class VariantEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 1) + if (variant.Index == 1) { - yield return a(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return a(variant.UnsafeGet(new global::dotVariant.Accessor._1())); } else { @@ -1850,9 +1907,9 @@ public static partial class VariantEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 2) + if (variant.Index == 2) { - yield return b(((global::dotVariant.GeneratorSupport.Accessor_2)variant).Value); + yield return b(variant.UnsafeGet(new global::dotVariant.Accessor._2())); } else { @@ -1883,9 +1940,9 @@ public static partial class VariantEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 3) + if (variant.Index == 3) { - yield return c(((global::dotVariant.GeneratorSupport.Accessor_3)variant).Value); + yield return c(variant.UnsafeGet(new global::dotVariant.Accessor._3())); } else { @@ -1916,9 +1973,9 @@ public static partial class VariantEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 4) + if (variant.Index == 4) { - yield return d(((global::dotVariant.GeneratorSupport.Accessor_4)variant).Value); + yield return d(variant.UnsafeGet(new global::dotVariant.Accessor._4())); } else { @@ -1949,9 +2006,9 @@ public static partial class VariantEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 5) + if (variant.Index == 5) { - yield return e(((global::dotVariant.GeneratorSupport.Accessor_5)variant).Value); + yield return e(variant.UnsafeGet(new global::dotVariant.Accessor._5())); } else { @@ -1982,9 +2039,9 @@ public static partial class VariantEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 6) + if (variant.Index == 6) { - yield return f(((global::dotVariant.GeneratorSupport.Accessor_6)variant).Value); + yield return f(variant.UnsafeGet(new global::dotVariant.Accessor._6())); } else { @@ -2016,9 +2073,9 @@ public static partial class VariantEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 1) + if (variant.Index == 1) { - yield return a(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return a(variant.UnsafeGet(new global::dotVariant.Accessor._1())); } else { @@ -2049,9 +2106,9 @@ public static partial class VariantEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 2) + if (variant.Index == 2) { - yield return b(((global::dotVariant.GeneratorSupport.Accessor_2)variant).Value); + yield return b(variant.UnsafeGet(new global::dotVariant.Accessor._2())); } else { @@ -2082,9 +2139,9 @@ public static partial class VariantEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 3) + if (variant.Index == 3) { - yield return c(((global::dotVariant.GeneratorSupport.Accessor_3)variant).Value); + yield return c(variant.UnsafeGet(new global::dotVariant.Accessor._3())); } else { @@ -2115,9 +2172,9 @@ public static partial class VariantEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 4) + if (variant.Index == 4) { - yield return d(((global::dotVariant.GeneratorSupport.Accessor_4)variant).Value); + yield return d(variant.UnsafeGet(new global::dotVariant.Accessor._4())); } else { @@ -2148,9 +2205,9 @@ public static partial class VariantEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 5) + if (variant.Index == 5) { - yield return e(((global::dotVariant.GeneratorSupport.Accessor_5)variant).Value); + yield return e(variant.UnsafeGet(new global::dotVariant.Accessor._5())); } else { @@ -2181,9 +2238,9 @@ public static partial class VariantEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 6) + if (variant.Index == 6) { - yield return f(((global::dotVariant.GeneratorSupport.Accessor_6)variant).Value); + yield return f(variant.UnsafeGet(new global::dotVariant.Accessor._6())); } else { @@ -2220,28 +2277,28 @@ public static partial class VariantEx { foreach (var variant in source) { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant)) + switch (variant.Index) { case 0: global::dotVariant.GeneratorSupport.Errors.ThrowEmptyError("Foo.Variant"); yield break; case 1: - yield return a(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return a(variant.UnsafeGet(new global::dotVariant.Accessor._1())); break; case 2: - yield return b(((global::dotVariant.GeneratorSupport.Accessor_2)variant).Value); + yield return b(variant.UnsafeGet(new global::dotVariant.Accessor._2())); break; case 3: - yield return c(((global::dotVariant.GeneratorSupport.Accessor_3)variant).Value); + yield return c(variant.UnsafeGet(new global::dotVariant.Accessor._3())); break; case 4: - yield return d(((global::dotVariant.GeneratorSupport.Accessor_4)variant).Value); + yield return d(variant.UnsafeGet(new global::dotVariant.Accessor._4())); break; case 5: - yield return e(((global::dotVariant.GeneratorSupport.Accessor_5)variant).Value); + yield return e(variant.UnsafeGet(new global::dotVariant.Accessor._5())); break; case 6: - yield return f(((global::dotVariant.GeneratorSupport.Accessor_6)variant).Value); + yield return f(variant.UnsafeGet(new global::dotVariant.Accessor._6())); break; default: global::dotVariant.GeneratorSupport.Errors.ThrowInternalError("Foo.Variant"); @@ -2278,28 +2335,28 @@ public static partial class VariantEx { foreach (var variant in source) { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant)) + switch (variant.Index) { case 0: yield return _(); break; case 1: - yield return a(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return a(variant.UnsafeGet(new global::dotVariant.Accessor._1())); break; case 2: - yield return b(((global::dotVariant.GeneratorSupport.Accessor_2)variant).Value); + yield return b(variant.UnsafeGet(new global::dotVariant.Accessor._2())); break; case 3: - yield return c(((global::dotVariant.GeneratorSupport.Accessor_3)variant).Value); + yield return c(variant.UnsafeGet(new global::dotVariant.Accessor._3())); break; case 4: - yield return d(((global::dotVariant.GeneratorSupport.Accessor_4)variant).Value); + yield return d(variant.UnsafeGet(new global::dotVariant.Accessor._4())); break; case 5: - yield return e(((global::dotVariant.GeneratorSupport.Accessor_5)variant).Value); + yield return e(variant.UnsafeGet(new global::dotVariant.Accessor._5())); break; case 6: - yield return f(((global::dotVariant.GeneratorSupport.Accessor_6)variant).Value); + yield return f(variant.UnsafeGet(new global::dotVariant.Accessor._6())); break; default: global::dotVariant.GeneratorSupport.Errors.ThrowInternalError("Foo.Variant"); @@ -2332,8 +2389,8 @@ public static partial class VariantEx where T5 : notnull { return global::System.Reactive.Linq.Observable.Select( - global::System.Reactive.Linq.Observable.Where(source, _variant => ((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 1), - _variant => a(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value)); + global::System.Reactive.Linq.Observable.Where(source, _variant => _variant.Index == 1), + _variant => a(_variant.UnsafeGet(new global::dotVariant.Accessor._1()))); } /// /// Projects each element of an observable sequence @@ -2354,8 +2411,8 @@ public static partial class VariantEx where T5 : notnull { return global::System.Reactive.Linq.Observable.Select( - global::System.Reactive.Linq.Observable.Where(source, _variant => ((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 2), - _variant => b(((global::dotVariant.GeneratorSupport.Accessor_2)_variant).Value)); + global::System.Reactive.Linq.Observable.Where(source, _variant => _variant.Index == 2), + _variant => b(_variant.UnsafeGet(new global::dotVariant.Accessor._2()))); } /// /// Projects each element of an observable sequence @@ -2376,8 +2433,8 @@ public static partial class VariantEx where T5 : notnull { return global::System.Reactive.Linq.Observable.Select( - global::System.Reactive.Linq.Observable.Where(source, _variant => ((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 3), - _variant => c(((global::dotVariant.GeneratorSupport.Accessor_3)_variant).Value)); + global::System.Reactive.Linq.Observable.Where(source, _variant => _variant.Index == 3), + _variant => c(_variant.UnsafeGet(new global::dotVariant.Accessor._3()))); } /// /// Projects each element of an observable sequence @@ -2398,8 +2455,8 @@ public static partial class VariantEx where T5 : notnull { return global::System.Reactive.Linq.Observable.Select( - global::System.Reactive.Linq.Observable.Where(source, _variant => ((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 4), - _variant => d(((global::dotVariant.GeneratorSupport.Accessor_4)_variant).Value)); + global::System.Reactive.Linq.Observable.Where(source, _variant => _variant.Index == 4), + _variant => d(_variant.UnsafeGet(new global::dotVariant.Accessor._4()))); } /// /// Projects each element of an observable sequence @@ -2420,8 +2477,8 @@ public static partial class VariantEx where T5 : notnull { return global::System.Reactive.Linq.Observable.Select( - global::System.Reactive.Linq.Observable.Where(source, _variant => ((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 5), - _variant => e(((global::dotVariant.GeneratorSupport.Accessor_5)_variant).Value)); + global::System.Reactive.Linq.Observable.Where(source, _variant => _variant.Index == 5), + _variant => e(_variant.UnsafeGet(new global::dotVariant.Accessor._5()))); } /// /// Projects each element of an observable sequence @@ -2442,8 +2499,8 @@ public static partial class VariantEx where T5 : notnull { return global::System.Reactive.Linq.Observable.Select( - global::System.Reactive.Linq.Observable.Where(source, _variant => ((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 6), - _variant => f(((global::dotVariant.GeneratorSupport.Accessor_6)_variant).Value)); + global::System.Reactive.Linq.Observable.Where(source, _variant => _variant.Index == 6), + _variant => f(_variant.UnsafeGet(new global::dotVariant.Accessor._6()))); } /// @@ -2468,9 +2525,9 @@ public static partial class VariantEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 1) + if (_variant.Index == 1) { - return a(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + return a(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); } else { @@ -2500,9 +2557,9 @@ public static partial class VariantEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 2) + if (_variant.Index == 2) { - return b(((global::dotVariant.GeneratorSupport.Accessor_2)_variant).Value); + return b(_variant.UnsafeGet(new global::dotVariant.Accessor._2())); } else { @@ -2532,9 +2589,9 @@ public static partial class VariantEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 3) + if (_variant.Index == 3) { - return c(((global::dotVariant.GeneratorSupport.Accessor_3)_variant).Value); + return c(_variant.UnsafeGet(new global::dotVariant.Accessor._3())); } else { @@ -2564,9 +2621,9 @@ public static partial class VariantEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 4) + if (_variant.Index == 4) { - return d(((global::dotVariant.GeneratorSupport.Accessor_4)_variant).Value); + return d(_variant.UnsafeGet(new global::dotVariant.Accessor._4())); } else { @@ -2596,9 +2653,9 @@ public static partial class VariantEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 5) + if (_variant.Index == 5) { - return e(((global::dotVariant.GeneratorSupport.Accessor_5)_variant).Value); + return e(_variant.UnsafeGet(new global::dotVariant.Accessor._5())); } else { @@ -2628,9 +2685,9 @@ public static partial class VariantEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 6) + if (_variant.Index == 6) { - return f(((global::dotVariant.GeneratorSupport.Accessor_6)_variant).Value); + return f(_variant.UnsafeGet(new global::dotVariant.Accessor._6())); } else { @@ -2661,9 +2718,9 @@ public static partial class VariantEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 1) + if (_variant.Index == 1) { - return a(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + return a(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); } else { @@ -2693,9 +2750,9 @@ public static partial class VariantEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 2) + if (_variant.Index == 2) { - return b(((global::dotVariant.GeneratorSupport.Accessor_2)_variant).Value); + return b(_variant.UnsafeGet(new global::dotVariant.Accessor._2())); } else { @@ -2725,9 +2782,9 @@ public static partial class VariantEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 3) + if (_variant.Index == 3) { - return c(((global::dotVariant.GeneratorSupport.Accessor_3)_variant).Value); + return c(_variant.UnsafeGet(new global::dotVariant.Accessor._3())); } else { @@ -2757,9 +2814,9 @@ public static partial class VariantEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 4) + if (_variant.Index == 4) { - return d(((global::dotVariant.GeneratorSupport.Accessor_4)_variant).Value); + return d(_variant.UnsafeGet(new global::dotVariant.Accessor._4())); } else { @@ -2789,9 +2846,9 @@ public static partial class VariantEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 5) + if (_variant.Index == 5) { - return e(((global::dotVariant.GeneratorSupport.Accessor_5)_variant).Value); + return e(_variant.UnsafeGet(new global::dotVariant.Accessor._5())); } else { @@ -2821,9 +2878,9 @@ public static partial class VariantEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 6) + if (_variant.Index == 6) { - return f(((global::dotVariant.GeneratorSupport.Accessor_6)_variant).Value); + return f(_variant.UnsafeGet(new global::dotVariant.Accessor._6())); } else { @@ -2857,22 +2914,22 @@ public static partial class VariantEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant)) + switch (_variant.Index) { case 0: return global::dotVariant.GeneratorSupport.Errors.ThrowEmptyError("Foo.Variant"); case 1: - return a(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + return a(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); case 2: - return b(((global::dotVariant.GeneratorSupport.Accessor_2)_variant).Value); + return b(_variant.UnsafeGet(new global::dotVariant.Accessor._2())); case 3: - return c(((global::dotVariant.GeneratorSupport.Accessor_3)_variant).Value); + return c(_variant.UnsafeGet(new global::dotVariant.Accessor._3())); case 4: - return d(((global::dotVariant.GeneratorSupport.Accessor_4)_variant).Value); + return d(_variant.UnsafeGet(new global::dotVariant.Accessor._4())); case 5: - return e(((global::dotVariant.GeneratorSupport.Accessor_5)_variant).Value); + return e(_variant.UnsafeGet(new global::dotVariant.Accessor._5())); case 6: - return f(((global::dotVariant.GeneratorSupport.Accessor_6)_variant).Value); + return f(_variant.UnsafeGet(new global::dotVariant.Accessor._6())); default: return global::dotVariant.GeneratorSupport.Errors.ThrowInternalError("Foo.Variant"); } @@ -2906,22 +2963,22 @@ public static partial class VariantEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant)) + switch (_variant.Index) { case 0: return _(); case 1: - return a(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + return a(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); case 2: - return b(((global::dotVariant.GeneratorSupport.Accessor_2)_variant).Value); + return b(_variant.UnsafeGet(new global::dotVariant.Accessor._2())); case 3: - return c(((global::dotVariant.GeneratorSupport.Accessor_3)_variant).Value); + return c(_variant.UnsafeGet(new global::dotVariant.Accessor._3())); case 4: - return d(((global::dotVariant.GeneratorSupport.Accessor_4)_variant).Value); + return d(_variant.UnsafeGet(new global::dotVariant.Accessor._4())); case 5: - return e(((global::dotVariant.GeneratorSupport.Accessor_5)_variant).Value); + return e(_variant.UnsafeGet(new global::dotVariant.Accessor._5())); case 6: - return f(((global::dotVariant.GeneratorSupport.Accessor_6)_variant).Value); + return f(_variant.UnsafeGet(new global::dotVariant.Accessor._6())); default: return global::dotVariant.GeneratorSupport.Errors.ThrowInternalError("Foo.Variant"); } @@ -3116,7 +3173,7 @@ public void Dispose() public void OnNext(global::Foo.Variant _variant) { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant)) + switch (_variant.Index) { case 0: if (_accept0) @@ -3129,22 +3186,22 @@ public void OnNext(global::Foo.Variant _variant) } break; case 1: - Subject1.OnNext(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + Subject1.OnNext(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); break; case 2: - Subject2.OnNext(((global::dotVariant.GeneratorSupport.Accessor_2)_variant).Value); + Subject2.OnNext(_variant.UnsafeGet(new global::dotVariant.Accessor._2())); break; case 3: - Subject3.OnNext(((global::dotVariant.GeneratorSupport.Accessor_3)_variant).Value); + Subject3.OnNext(_variant.UnsafeGet(new global::dotVariant.Accessor._3())); break; case 4: - Subject4.OnNext(((global::dotVariant.GeneratorSupport.Accessor_4)_variant).Value); + Subject4.OnNext(_variant.UnsafeGet(new global::dotVariant.Accessor._4())); break; case 5: - Subject5.OnNext(((global::dotVariant.GeneratorSupport.Accessor_5)_variant).Value); + Subject5.OnNext(_variant.UnsafeGet(new global::dotVariant.Accessor._5())); break; case 6: - Subject6.OnNext(((global::dotVariant.GeneratorSupport.Accessor_6)_variant).Value); + Subject6.OnNext(_variant.UnsafeGet(new global::dotVariant.Accessor._6())); break; default: OnError(global::dotVariant.GeneratorSupport.Errors.MakeInternalError("Foo.Variant")); diff --git a/src/dotVariant.Generator.Test/samples/Variant-generic-class-nullable.out.cs b/src/dotVariant.Generator.Test/samples/Variant-generic-class-nullable.out.cs index febe26e..27ead08 100644 --- a/src/dotVariant.Generator.Test/samples/Variant-generic-class-nullable.out.cs +++ b/src/dotVariant.Generator.Test/samples/Variant-generic-class-nullable.out.cs @@ -44,6 +44,11 @@ public static Variant Create(T value) public bool IsEmpty => _variant.IsEmpty; + /// + [global::System.Diagnostics.DebuggerNonUserCode] + public byte Index + => _variant.Index; + /// [global::System.Diagnostics.DebuggerNonUserCode] public override bool Equals(object? other) @@ -71,6 +76,11 @@ public override int GetHashCode() public override string ToString() => _variant.ToString(); + /// + [global::System.Diagnostics.DebuggerNonUserCode] + public T UnsafeGet(global::dotVariant.Accessor._1 accessor) + => _variant.UnsafeGet(accessor); + /// [global::System.Diagnostics.DebuggerNonUserCode] public bool TryMatch(out T? value) @@ -144,15 +154,6 @@ public __DebuggerTypeProxy(Variant v) #pragma warning restore 8604, 8625 } } - - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - [global::System.Diagnostics.DebuggerNonUserCode] - public static explicit operator global::dotVariant.GeneratorSupport.Discriminator(Variant v) - => (global::dotVariant.GeneratorSupport.Discriminator)v._variant; - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - [global::System.Diagnostics.DebuggerNonUserCode] - public static explicit operator global::dotVariant.GeneratorSupport.Accessor_1(Variant v) - => (global::dotVariant.GeneratorSupport.Accessor_1)v._variant; } } @@ -173,24 +174,25 @@ public Union(T value) } private readonly Union _x; - private readonly byte _n; + + /// + /// The 1-based index of the currently stored type, + /// counted left-ro-right from the parameter list. + /// 0 if the variant is empty. + /// + public readonly byte Index; public Variant(T value) { - _n = 1; + Index = 1; _x = new Union(value); } - public static explicit operator global::dotVariant.GeneratorSupport.Discriminator(in Variant v) - => (global::dotVariant.GeneratorSupport.Discriminator)v._n; - public static explicit operator global::dotVariant.GeneratorSupport.Accessor_1(in Variant v) - => new global::dotVariant.GeneratorSupport.Accessor_1(v._x._1); - /// /// if Variant was constructed without a value. /// - public bool IsEmpty => _n == 0; + public bool IsEmpty => this.Index == 0; /// /// The string representation of the stored value's type. @@ -199,7 +201,7 @@ public string TypeString { get { - switch (_n) + switch (this.Index) { case 0: return ""; @@ -216,7 +218,7 @@ public string TypeString /// public override string ToString() { - switch (_n) + switch (this.Index) { case 0: return ""; @@ -234,7 +236,7 @@ public object? AsObject { get { - switch (_n) + switch (this.Index) { case 0: return null; @@ -248,11 +250,11 @@ public object? AsObject public bool Equals(in Variant other) { - if (_n != other._n) + if (this.Index != other.Index) { return false; } - switch (_n) + switch (Index) { case 0: return true; @@ -265,7 +267,7 @@ public bool Equals(in Variant other) public override int GetHashCode() { - switch (_n) + switch (this.Index) { case 0: return 0; @@ -276,6 +278,16 @@ public override int GetHashCode() } } + /// + /// Retrieve the stored value assuming it is of type . + /// + /// Only call this if you have ensured that Index == 1, + /// otherwise the correctness of the returned value is not guaranteed, + /// nor that any value is returned at all. + /// + public T UnsafeGet(global::dotVariant.Accessor._1 _) + => _x._1; + /// /// Retrieve the value stored within Variant if it is of type . /// @@ -283,8 +295,8 @@ public override int GetHashCode() /// if Variant contained a value of type . public bool TryMatch(out T? value) { - value = _n == 1 ? _x._1 : default; - return _n == 1; + value = this.Index == 1 ? _x._1 : default; + return this.Index == 1; } /// @@ -295,7 +307,7 @@ public bool TryMatch(out T? value) /// Any exception thrown from is rethrown. public bool TryMatch(global::System.Action value) { - if (_n == 1) + if (this.Index == 1) { value(_x._1); return true; @@ -311,7 +323,7 @@ public bool TryMatch(global::System.Action value) /// Variant does not contain a value of type . public void Match(out T? value) { - if (_n == 1) + if (this.Index == 1) { value = _x._1; return; @@ -328,7 +340,7 @@ public void Match(out T? value) /// Any exception thrown from is rethrown. public void Match(global::System.Action value) { - if (_n == 1) + if (this.Index == 1) { value(_x._1); return; @@ -345,7 +357,7 @@ public void Match(global::System.Action value) /// Any exception thrown from or is rethrown. public void Match(global::System.Action value, global::System.Action _) { - if (_n == 1) + if (this.Index == 1) { value(_x._1); } @@ -365,7 +377,7 @@ public void Match(global::System.Action value, global::System.Action _) /// Any exception thrown from is rethrown. public TResult Match(global::System.Func value) { - if (_n == 1) + if (this.Index == 1) { return value(_x._1); } @@ -382,7 +394,7 @@ public TResult Match(global::System.Func value) /// Any exception thrown from or is rethrown. public TResult Match(global::System.Func value, TResult _) { - return _n == 1 ? value(_x._1) : _; + return this.Index == 1 ? value(_x._1) : _; } /// @@ -394,7 +406,7 @@ public TResult Match(global::System.Func value, TResult _) /// Any exception thrown from or is rethrown. public TResult Match(global::System.Func value, global::System.Func _) { - return _n == 1 ? value(_x._1) : _(); + return this.Index == 1 ? value(_x._1) : _(); } /// @@ -406,7 +418,7 @@ public TResult Match(global::System.Func value, global::Sys /// Any exception thrown from a delegate is rethrown. public void Visit(global::System.Action value, global::System.Action _) { - switch (_n) + switch (this.Index) { case 0: _(); @@ -429,7 +441,7 @@ public void Visit(global::System.Action value, global::System.Action _) /// Any exception thrown from a delegate is rethrown. public void Visit(global::System.Action value) { - switch (_n) + switch (this.Index) { case 0: global::dotVariant.GeneratorSupport.Errors.ThrowEmptyError("Foo.Variant"); @@ -453,7 +465,7 @@ public void Visit(global::System.Action value) /// The return type of all delegates, and by extension the return type of this function. public TResult Visit(global::System.Func value, global::System.Func _) { - switch (_n) + switch (this.Index) { case 0: return _(); @@ -474,7 +486,7 @@ public TResult Visit(global::System.Func value, global::Sys /// The return type of all delegates, and by extension the return type of this function. public TResult Visit(global::System.Func value) { - switch (_n) + switch (this.Index) { case 0: return global::dotVariant.GeneratorSupport.Errors.ThrowEmptyError("Foo.Variant"); @@ -509,9 +521,9 @@ public static partial class VariantEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 1) + if (variant.Index == 1) { - yield return value(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return value(variant.UnsafeGet(new global::dotVariant.Accessor._1())); } } } @@ -535,9 +547,9 @@ public static partial class VariantEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 1) + if (variant.Index == 1) { - yield return value(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return value(variant.UnsafeGet(new global::dotVariant.Accessor._1())); } else { @@ -565,9 +577,9 @@ public static partial class VariantEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 1) + if (variant.Index == 1) { - yield return value(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return value(variant.UnsafeGet(new global::dotVariant.Accessor._1())); } else { @@ -595,13 +607,13 @@ public static partial class VariantEx { foreach (var variant in source) { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant)) + switch (variant.Index) { case 0: global::dotVariant.GeneratorSupport.Errors.ThrowEmptyError("Foo.Variant"); yield break; case 1: - yield return value(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return value(variant.UnsafeGet(new global::dotVariant.Accessor._1())); break; default: global::dotVariant.GeneratorSupport.Errors.ThrowInternalError("Foo.Variant"); @@ -629,13 +641,13 @@ public static partial class VariantEx { foreach (var variant in source) { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant)) + switch (variant.Index) { case 0: yield return _(); break; case 1: - yield return value(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return value(variant.UnsafeGet(new global::dotVariant.Accessor._1())); break; default: global::dotVariant.GeneratorSupport.Errors.ThrowInternalError("Foo.Variant"); @@ -664,8 +676,8 @@ public static partial class VariantEx where T : class? { return global::System.Reactive.Linq.Observable.Select( - global::System.Reactive.Linq.Observable.Where(source, _variant => ((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 1), - _variant => value(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value)); + global::System.Reactive.Linq.Observable.Where(source, _variant => _variant.Index == 1), + _variant => value(_variant.UnsafeGet(new global::dotVariant.Accessor._1()))); } /// @@ -686,9 +698,9 @@ public static partial class VariantEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 1) + if (_variant.Index == 1) { - return value(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + return value(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); } else { @@ -715,9 +727,9 @@ public static partial class VariantEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 1) + if (_variant.Index == 1) { - return value(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + return value(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); } else { @@ -742,12 +754,12 @@ public static partial class VariantEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant)) + switch (_variant.Index) { case 0: return global::dotVariant.GeneratorSupport.Errors.ThrowEmptyError("Foo.Variant"); case 1: - return value(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + return value(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); default: return global::dotVariant.GeneratorSupport.Errors.ThrowInternalError("Foo.Variant"); } @@ -772,12 +784,12 @@ public static partial class VariantEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant)) + switch (_variant.Index) { case 0: return _(); case 1: - return value(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + return value(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); default: return global::dotVariant.GeneratorSupport.Errors.ThrowInternalError("Foo.Variant"); } @@ -903,7 +915,7 @@ public void Dispose() public void OnNext(global::Foo.Variant _variant) { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant)) + switch (_variant.Index) { case 0: if (_accept0) @@ -916,7 +928,7 @@ public void OnNext(global::Foo.Variant _variant) } break; case 1: - Subject1.OnNext(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + Subject1.OnNext(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); break; default: OnError(global::dotVariant.GeneratorSupport.Errors.MakeInternalError("Foo.Variant")); diff --git a/src/dotVariant.Generator.Test/samples/Variant-generic-class.out.cs b/src/dotVariant.Generator.Test/samples/Variant-generic-class.out.cs index eb9b8c8..5b05edb 100644 --- a/src/dotVariant.Generator.Test/samples/Variant-generic-class.out.cs +++ b/src/dotVariant.Generator.Test/samples/Variant-generic-class.out.cs @@ -44,6 +44,11 @@ public static Variant Create(T value) public bool IsEmpty => _variant.IsEmpty; + /// + [global::System.Diagnostics.DebuggerNonUserCode] + public byte Index + => _variant.Index; + /// [global::System.Diagnostics.DebuggerNonUserCode] public override bool Equals(object? other) @@ -71,6 +76,11 @@ public override int GetHashCode() public override string ToString() => _variant.ToString(); + /// + [global::System.Diagnostics.DebuggerNonUserCode] + public T UnsafeGet(global::dotVariant.Accessor._1 accessor) + => _variant.UnsafeGet(accessor); + /// [global::System.Diagnostics.DebuggerNonUserCode] public bool TryMatch([global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out T? value) @@ -144,15 +154,6 @@ public __DebuggerTypeProxy(Variant v) #pragma warning restore 8604, 8625 } } - - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - [global::System.Diagnostics.DebuggerNonUserCode] - public static explicit operator global::dotVariant.GeneratorSupport.Discriminator(Variant v) - => (global::dotVariant.GeneratorSupport.Discriminator)v._variant; - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - [global::System.Diagnostics.DebuggerNonUserCode] - public static explicit operator global::dotVariant.GeneratorSupport.Accessor_1(Variant v) - => (global::dotVariant.GeneratorSupport.Accessor_1)v._variant; } } @@ -173,24 +174,25 @@ public Union(T value) } private readonly Union _x; - private readonly byte _n; + + /// + /// The 1-based index of the currently stored type, + /// counted left-ro-right from the parameter list. + /// 0 if the variant is empty. + /// + public readonly byte Index; public Variant(T value) { - _n = 1; + Index = 1; _x = new Union(value); } - public static explicit operator global::dotVariant.GeneratorSupport.Discriminator(in Variant v) - => (global::dotVariant.GeneratorSupport.Discriminator)v._n; - public static explicit operator global::dotVariant.GeneratorSupport.Accessor_1(in Variant v) - => new global::dotVariant.GeneratorSupport.Accessor_1(v._x._1); - /// /// if Variant was constructed without a value. /// - public bool IsEmpty => _n == 0; + public bool IsEmpty => this.Index == 0; /// /// The string representation of the stored value's type. @@ -199,7 +201,7 @@ public string TypeString { get { - switch (_n) + switch (this.Index) { case 0: return ""; @@ -216,7 +218,7 @@ public string TypeString /// public override string ToString() { - switch (_n) + switch (this.Index) { case 0: return ""; @@ -234,7 +236,7 @@ public object? AsObject { get { - switch (_n) + switch (this.Index) { case 0: return null; @@ -248,11 +250,11 @@ public object? AsObject public bool Equals(in Variant other) { - if (_n != other._n) + if (this.Index != other.Index) { return false; } - switch (_n) + switch (Index) { case 0: return true; @@ -265,7 +267,7 @@ public bool Equals(in Variant other) public override int GetHashCode() { - switch (_n) + switch (this.Index) { case 0: return 0; @@ -276,6 +278,16 @@ public override int GetHashCode() } } + /// + /// Retrieve the stored value assuming it is of type . + /// + /// Only call this if you have ensured that Index == 1, + /// otherwise the correctness of the returned value is not guaranteed, + /// nor that any value is returned at all. + /// + public T UnsafeGet(global::dotVariant.Accessor._1 _) + => _x._1; + /// /// Retrieve the value stored within Variant if it is of type . /// @@ -283,8 +295,8 @@ public override int GetHashCode() /// if Variant contained a value of type . public bool TryMatch([global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out T? value) { - value = _n == 1 ? _x._1 : default; - return _n == 1; + value = this.Index == 1 ? _x._1 : default; + return this.Index == 1; } /// @@ -295,7 +307,7 @@ public bool TryMatch([global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] /// Any exception thrown from is rethrown. public bool TryMatch(global::System.Action value) { - if (_n == 1) + if (this.Index == 1) { value(_x._1); return true; @@ -311,7 +323,7 @@ public bool TryMatch(global::System.Action value) /// Variant does not contain a value of type . public void Match([global::System.Diagnostics.CodeAnalysis.NotNull] out T? value) { - if (_n == 1) + if (this.Index == 1) { value = _x._1; return; @@ -328,7 +340,7 @@ public void Match([global::System.Diagnostics.CodeAnalysis.NotNull] out T? value /// Any exception thrown from is rethrown. public void Match(global::System.Action value) { - if (_n == 1) + if (this.Index == 1) { value(_x._1); return; @@ -345,7 +357,7 @@ public void Match(global::System.Action value) /// Any exception thrown from or is rethrown. public void Match(global::System.Action value, global::System.Action _) { - if (_n == 1) + if (this.Index == 1) { value(_x._1); } @@ -365,7 +377,7 @@ public void Match(global::System.Action value, global::System.Action _) /// Any exception thrown from is rethrown. public TResult Match(global::System.Func value) { - if (_n == 1) + if (this.Index == 1) { return value(_x._1); } @@ -382,7 +394,7 @@ public TResult Match(global::System.Func value) /// Any exception thrown from or is rethrown. public TResult Match(global::System.Func value, TResult _) { - return _n == 1 ? value(_x._1) : _; + return this.Index == 1 ? value(_x._1) : _; } /// @@ -394,7 +406,7 @@ public TResult Match(global::System.Func value, TResult _) /// Any exception thrown from or is rethrown. public TResult Match(global::System.Func value, global::System.Func _) { - return _n == 1 ? value(_x._1) : _(); + return this.Index == 1 ? value(_x._1) : _(); } /// @@ -406,7 +418,7 @@ public TResult Match(global::System.Func value, global::Sys /// Any exception thrown from a delegate is rethrown. public void Visit(global::System.Action value, global::System.Action _) { - switch (_n) + switch (this.Index) { case 0: _(); @@ -429,7 +441,7 @@ public void Visit(global::System.Action value, global::System.Action _) /// Any exception thrown from a delegate is rethrown. public void Visit(global::System.Action value) { - switch (_n) + switch (this.Index) { case 0: global::dotVariant.GeneratorSupport.Errors.ThrowEmptyError("Foo.Variant"); @@ -453,7 +465,7 @@ public void Visit(global::System.Action value) /// The return type of all delegates, and by extension the return type of this function. public TResult Visit(global::System.Func value, global::System.Func _) { - switch (_n) + switch (this.Index) { case 0: return _(); @@ -474,7 +486,7 @@ public TResult Visit(global::System.Func value, global::Sys /// The return type of all delegates, and by extension the return type of this function. public TResult Visit(global::System.Func value) { - switch (_n) + switch (this.Index) { case 0: return global::dotVariant.GeneratorSupport.Errors.ThrowEmptyError("Foo.Variant"); @@ -509,9 +521,9 @@ public static partial class VariantEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 1) + if (variant.Index == 1) { - yield return value(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return value(variant.UnsafeGet(new global::dotVariant.Accessor._1())); } } } @@ -535,9 +547,9 @@ public static partial class VariantEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 1) + if (variant.Index == 1) { - yield return value(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return value(variant.UnsafeGet(new global::dotVariant.Accessor._1())); } else { @@ -565,9 +577,9 @@ public static partial class VariantEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 1) + if (variant.Index == 1) { - yield return value(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return value(variant.UnsafeGet(new global::dotVariant.Accessor._1())); } else { @@ -595,13 +607,13 @@ public static partial class VariantEx { foreach (var variant in source) { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant)) + switch (variant.Index) { case 0: global::dotVariant.GeneratorSupport.Errors.ThrowEmptyError("Foo.Variant"); yield break; case 1: - yield return value(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return value(variant.UnsafeGet(new global::dotVariant.Accessor._1())); break; default: global::dotVariant.GeneratorSupport.Errors.ThrowInternalError("Foo.Variant"); @@ -629,13 +641,13 @@ public static partial class VariantEx { foreach (var variant in source) { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant)) + switch (variant.Index) { case 0: yield return _(); break; case 1: - yield return value(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return value(variant.UnsafeGet(new global::dotVariant.Accessor._1())); break; default: global::dotVariant.GeneratorSupport.Errors.ThrowInternalError("Foo.Variant"); @@ -664,8 +676,8 @@ public static partial class VariantEx where T : class { return global::System.Reactive.Linq.Observable.Select( - global::System.Reactive.Linq.Observable.Where(source, _variant => ((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 1), - _variant => value(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value)); + global::System.Reactive.Linq.Observable.Where(source, _variant => _variant.Index == 1), + _variant => value(_variant.UnsafeGet(new global::dotVariant.Accessor._1()))); } /// @@ -686,9 +698,9 @@ public static partial class VariantEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 1) + if (_variant.Index == 1) { - return value(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + return value(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); } else { @@ -715,9 +727,9 @@ public static partial class VariantEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 1) + if (_variant.Index == 1) { - return value(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + return value(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); } else { @@ -742,12 +754,12 @@ public static partial class VariantEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant)) + switch (_variant.Index) { case 0: return global::dotVariant.GeneratorSupport.Errors.ThrowEmptyError("Foo.Variant"); case 1: - return value(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + return value(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); default: return global::dotVariant.GeneratorSupport.Errors.ThrowInternalError("Foo.Variant"); } @@ -772,12 +784,12 @@ public static partial class VariantEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant)) + switch (_variant.Index) { case 0: return _(); case 1: - return value(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + return value(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); default: return global::dotVariant.GeneratorSupport.Errors.ThrowInternalError("Foo.Variant"); } @@ -903,7 +915,7 @@ public void Dispose() public void OnNext(global::Foo.Variant _variant) { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant)) + switch (_variant.Index) { case 0: if (_accept0) @@ -916,7 +928,7 @@ public void OnNext(global::Foo.Variant _variant) } break; case 1: - Subject1.OnNext(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + Subject1.OnNext(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); break; default: OnError(global::dotVariant.GeneratorSupport.Errors.MakeInternalError("Foo.Variant")); diff --git a/src/dotVariant.Generator.Test/samples/Variant-generic-multiple.out.cs b/src/dotVariant.Generator.Test/samples/Variant-generic-multiple.out.cs index d25259a..3240a79 100644 --- a/src/dotVariant.Generator.Test/samples/Variant-generic-multiple.out.cs +++ b/src/dotVariant.Generator.Test/samples/Variant-generic-multiple.out.cs @@ -94,6 +94,11 @@ public void Dispose() public bool IsEmpty => _variant.IsEmpty; + /// + [global::System.Diagnostics.DebuggerNonUserCode] + public byte Index + => _variant.Index; + /// [global::System.Diagnostics.DebuggerNonUserCode] public override bool Equals(object? other) @@ -121,6 +126,11 @@ public override int GetHashCode() public override string ToString() => _variant.ToString(); + /// + [global::System.Diagnostics.DebuggerNonUserCode] + public T1 UnsafeGet(global::dotVariant.Accessor._1 accessor) + => _variant.UnsafeGet(accessor); + /// [global::System.Diagnostics.DebuggerNonUserCode] public bool TryMatch([global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out T1? a) @@ -161,6 +171,11 @@ public TResult Match(global::System.Func a, TResult _) public TResult Match(global::System.Func a, global::System.Func _) => _variant.Match(a, _); + /// + [global::System.Diagnostics.DebuggerNonUserCode] + public T2 UnsafeGet(global::dotVariant.Accessor._2 accessor) + => _variant.UnsafeGet(accessor); + /// [global::System.Diagnostics.DebuggerNonUserCode] public bool TryMatch([global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out T2? b) @@ -201,6 +216,11 @@ public TResult Match(global::System.Func b, TResult _) public TResult Match(global::System.Func b, global::System.Func _) => _variant.Match(b, _); + /// + [global::System.Diagnostics.DebuggerNonUserCode] + public T3 UnsafeGet(global::dotVariant.Accessor._3 accessor) + => _variant.UnsafeGet(accessor); + /// [global::System.Diagnostics.DebuggerNonUserCode] public bool TryMatch([global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out T3 c) @@ -274,23 +294,6 @@ public __DebuggerTypeProxy(Variant v) #pragma warning restore 8604, 8625 } } - - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - [global::System.Diagnostics.DebuggerNonUserCode] - public static explicit operator global::dotVariant.GeneratorSupport.Discriminator(Variant v) - => (global::dotVariant.GeneratorSupport.Discriminator)v._variant; - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - [global::System.Diagnostics.DebuggerNonUserCode] - public static explicit operator global::dotVariant.GeneratorSupport.Accessor_1(Variant v) - => (global::dotVariant.GeneratorSupport.Accessor_1)v._variant; - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - [global::System.Diagnostics.DebuggerNonUserCode] - public static explicit operator global::dotVariant.GeneratorSupport.Accessor_2(Variant v) - => (global::dotVariant.GeneratorSupport.Accessor_2)v._variant; - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - [global::System.Diagnostics.DebuggerNonUserCode] - public static explicit operator global::dotVariant.GeneratorSupport.Accessor_3(Variant v) - => (global::dotVariant.GeneratorSupport.Accessor_3)v._variant; } } @@ -330,21 +333,27 @@ public Union(T3 value) } private readonly Union _x; - private readonly byte _n; + + /// + /// The 1-based index of the currently stored type, + /// counted left-ro-right from the parameter list. + /// 0 if the variant is empty. + /// + public readonly byte Index; public Variant(T1 a) { - _n = 1; + Index = 1; _x = new Union(a); } public Variant(T2 b) { - _n = 2; + Index = 2; _x = new Union(b); } public Variant(T3 c) { - _n = 3; + Index = 3; _x = new Union(c); } @@ -354,7 +363,7 @@ public Variant(T3 c) /// public void Dispose() { - switch (_n) + switch (this.Index) { case 0: break; @@ -371,19 +380,10 @@ public void Dispose() } } - public static explicit operator global::dotVariant.GeneratorSupport.Discriminator(in Variant v) - => (global::dotVariant.GeneratorSupport.Discriminator)v._n; - public static explicit operator global::dotVariant.GeneratorSupport.Accessor_1(in Variant v) - => new global::dotVariant.GeneratorSupport.Accessor_1(v._x._1); - public static explicit operator global::dotVariant.GeneratorSupport.Accessor_2(in Variant v) - => new global::dotVariant.GeneratorSupport.Accessor_2(v._x._2); - public static explicit operator global::dotVariant.GeneratorSupport.Accessor_3(in Variant v) - => new global::dotVariant.GeneratorSupport.Accessor_3(v._x._3); - /// /// if Variant was constructed without a value. /// - public bool IsEmpty => _n == 0; + public bool IsEmpty => this.Index == 0; /// /// The string representation of the stored value's type. @@ -392,7 +392,7 @@ public string TypeString { get { - switch (_n) + switch (this.Index) { case 0: return ""; @@ -413,7 +413,7 @@ public string TypeString /// public override string ToString() { - switch (_n) + switch (this.Index) { case 0: return ""; @@ -435,7 +435,7 @@ public object? AsObject { get { - switch (_n) + switch (this.Index) { case 0: return null; @@ -453,11 +453,11 @@ public object? AsObject public bool Equals(in Variant other) { - if (_n != other._n) + if (this.Index != other.Index) { return false; } - switch (_n) + switch (Index) { case 0: return true; @@ -474,7 +474,7 @@ public bool Equals(in Variant other) public override int GetHashCode() { - switch (_n) + switch (this.Index) { case 0: return 0; @@ -489,6 +489,16 @@ public override int GetHashCode() } } + /// + /// Retrieve the stored value assuming it is of type . + /// + /// Only call this if you have ensured that Index == 1, + /// otherwise the correctness of the returned value is not guaranteed, + /// nor that any value is returned at all. + /// + public T1 UnsafeGet(global::dotVariant.Accessor._1 _) + => _x._1; + /// /// Retrieve the value stored within Variant if it is of type . /// @@ -496,8 +506,8 @@ public override int GetHashCode() /// if Variant contained a value of type . public bool TryMatch([global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out T1? a) { - a = _n == 1 ? _x._1 : default; - return _n == 1; + a = this.Index == 1 ? _x._1 : default; + return this.Index == 1; } /// @@ -508,7 +518,7 @@ public bool TryMatch([global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] /// Any exception thrown from is rethrown. public bool TryMatch(global::System.Action a) { - if (_n == 1) + if (this.Index == 1) { a(_x._1); return true; @@ -524,7 +534,7 @@ public bool TryMatch(global::System.Action a) /// Variant does not contain a value of type . public void Match([global::System.Diagnostics.CodeAnalysis.NotNull] out T1? a) { - if (_n == 1) + if (this.Index == 1) { a = _x._1; return; @@ -541,7 +551,7 @@ public void Match([global::System.Diagnostics.CodeAnalysis.NotNull] out T1? a) /// Any exception thrown from is rethrown. public void Match(global::System.Action a) { - if (_n == 1) + if (this.Index == 1) { a(_x._1); return; @@ -558,7 +568,7 @@ public void Match(global::System.Action a) /// Any exception thrown from or is rethrown. public void Match(global::System.Action a, global::System.Action _) { - if (_n == 1) + if (this.Index == 1) { a(_x._1); } @@ -578,7 +588,7 @@ public void Match(global::System.Action a, global::System.Action _) /// Any exception thrown from is rethrown. public TResult Match(global::System.Func a) { - if (_n == 1) + if (this.Index == 1) { return a(_x._1); } @@ -595,7 +605,7 @@ public TResult Match(global::System.Func a) /// Any exception thrown from or is rethrown. public TResult Match(global::System.Func a, TResult _) { - return _n == 1 ? a(_x._1) : _; + return this.Index == 1 ? a(_x._1) : _; } /// @@ -607,8 +617,18 @@ public TResult Match(global::System.Func a, TResult _) /// Any exception thrown from or is rethrown. public TResult Match(global::System.Func a, global::System.Func _) { - return _n == 1 ? a(_x._1) : _(); + return this.Index == 1 ? a(_x._1) : _(); } + /// + /// Retrieve the stored value assuming it is of type . + /// + /// Only call this if you have ensured that Index == 2, + /// otherwise the correctness of the returned value is not guaranteed, + /// nor that any value is returned at all. + /// + public T2 UnsafeGet(global::dotVariant.Accessor._2 _) + => _x._2; + /// /// Retrieve the value stored within Variant if it is of type . /// @@ -616,8 +636,8 @@ public TResult Match(global::System.Func a, global::System /// if Variant contained a value of type . public bool TryMatch([global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out T2? b) { - b = _n == 2 ? _x._2 : default; - return _n == 2; + b = this.Index == 2 ? _x._2 : default; + return this.Index == 2; } /// @@ -628,7 +648,7 @@ public bool TryMatch([global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] /// Any exception thrown from is rethrown. public bool TryMatch(global::System.Action b) { - if (_n == 2) + if (this.Index == 2) { b(_x._2); return true; @@ -644,7 +664,7 @@ public bool TryMatch(global::System.Action b) /// Variant does not contain a value of type . public void Match([global::System.Diagnostics.CodeAnalysis.NotNull] out T2? b) { - if (_n == 2) + if (this.Index == 2) { b = _x._2; return; @@ -661,7 +681,7 @@ public void Match([global::System.Diagnostics.CodeAnalysis.NotNull] out T2? b) /// Any exception thrown from is rethrown. public void Match(global::System.Action b) { - if (_n == 2) + if (this.Index == 2) { b(_x._2); return; @@ -678,7 +698,7 @@ public void Match(global::System.Action b) /// Any exception thrown from or is rethrown. public void Match(global::System.Action b, global::System.Action _) { - if (_n == 2) + if (this.Index == 2) { b(_x._2); } @@ -698,7 +718,7 @@ public void Match(global::System.Action b, global::System.Action _) /// Any exception thrown from is rethrown. public TResult Match(global::System.Func b) { - if (_n == 2) + if (this.Index == 2) { return b(_x._2); } @@ -715,7 +735,7 @@ public TResult Match(global::System.Func b) /// Any exception thrown from or is rethrown. public TResult Match(global::System.Func b, TResult _) { - return _n == 2 ? b(_x._2) : _; + return this.Index == 2 ? b(_x._2) : _; } /// @@ -727,8 +747,18 @@ public TResult Match(global::System.Func b, TResult _) /// Any exception thrown from or is rethrown. public TResult Match(global::System.Func b, global::System.Func _) { - return _n == 2 ? b(_x._2) : _(); + return this.Index == 2 ? b(_x._2) : _(); } + /// + /// Retrieve the stored value assuming it is of type . + /// + /// Only call this if you have ensured that Index == 3, + /// otherwise the correctness of the returned value is not guaranteed, + /// nor that any value is returned at all. + /// + public T3 UnsafeGet(global::dotVariant.Accessor._3 _) + => _x._3; + /// /// Retrieve the value stored within Variant if it is of type . /// @@ -736,8 +766,8 @@ public TResult Match(global::System.Func b, global::System /// if Variant contained a value of type . public bool TryMatch([global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out T3 c) { - c = _n == 3 ? _x._3 : default; - return _n == 3; + c = this.Index == 3 ? _x._3 : default; + return this.Index == 3; } /// @@ -748,7 +778,7 @@ public bool TryMatch([global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] /// Any exception thrown from is rethrown. public bool TryMatch(global::System.Action c) { - if (_n == 3) + if (this.Index == 3) { c(_x._3); return true; @@ -764,7 +794,7 @@ public bool TryMatch(global::System.Action c) /// Variant does not contain a value of type . public void Match([global::System.Diagnostics.CodeAnalysis.NotNull] out T3 c) { - if (_n == 3) + if (this.Index == 3) { c = _x._3; return; @@ -781,7 +811,7 @@ public void Match([global::System.Diagnostics.CodeAnalysis.NotNull] out T3 c) /// Any exception thrown from is rethrown. public void Match(global::System.Action c) { - if (_n == 3) + if (this.Index == 3) { c(_x._3); return; @@ -798,7 +828,7 @@ public void Match(global::System.Action c) /// Any exception thrown from or is rethrown. public void Match(global::System.Action c, global::System.Action _) { - if (_n == 3) + if (this.Index == 3) { c(_x._3); } @@ -818,7 +848,7 @@ public void Match(global::System.Action c, global::System.Action _) /// Any exception thrown from is rethrown. public TResult Match(global::System.Func c) { - if (_n == 3) + if (this.Index == 3) { return c(_x._3); } @@ -835,7 +865,7 @@ public TResult Match(global::System.Func c) /// Any exception thrown from or is rethrown. public TResult Match(global::System.Func c, TResult _) { - return _n == 3 ? c(_x._3) : _; + return this.Index == 3 ? c(_x._3) : _; } /// @@ -847,7 +877,7 @@ public TResult Match(global::System.Func c, TResult _) /// Any exception thrown from or is rethrown. public TResult Match(global::System.Func c, global::System.Func _) { - return _n == 3 ? c(_x._3) : _(); + return this.Index == 3 ? c(_x._3) : _(); } /// @@ -861,7 +891,7 @@ public TResult Match(global::System.Func c, global::System /// Any exception thrown from a delegate is rethrown. public void Visit(global::System.Action a, global::System.Action b, global::System.Action c, global::System.Action _) { - switch (_n) + switch (this.Index) { case 0: _(); @@ -892,7 +922,7 @@ public void Visit(global::System.Action a, global::System.Action b, glob /// Any exception thrown from a delegate is rethrown. public void Visit(global::System.Action a, global::System.Action b, global::System.Action c) { - switch (_n) + switch (this.Index) { case 0: global::dotVariant.GeneratorSupport.Errors.ThrowEmptyError("Foo.Variant"); @@ -924,7 +954,7 @@ public void Visit(global::System.Action a, global::System.Action b, glob /// The return type of all delegates, and by extension the return type of this function. public TResult Visit(global::System.Func a, global::System.Func b, global::System.Func c, global::System.Func _) { - switch (_n) + switch (this.Index) { case 0: return _(); @@ -951,7 +981,7 @@ public TResult Visit(global::System.Func a, global::System /// The return type of all delegates, and by extension the return type of this function. public TResult Visit(global::System.Func a, global::System.Func b, global::System.Func c) { - switch (_n) + switch (this.Index) { case 0: return global::dotVariant.GeneratorSupport.Errors.ThrowEmptyError("Foo.Variant"); @@ -992,9 +1022,9 @@ public static partial class VariantEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 1) + if (variant.Index == 1) { - yield return a(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return a(variant.UnsafeGet(new global::dotVariant.Accessor._1())); } } } @@ -1017,9 +1047,9 @@ public static partial class VariantEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 2) + if (variant.Index == 2) { - yield return b(((global::dotVariant.GeneratorSupport.Accessor_2)variant).Value); + yield return b(variant.UnsafeGet(new global::dotVariant.Accessor._2())); } } } @@ -1042,9 +1072,9 @@ public static partial class VariantEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 3) + if (variant.Index == 3) { - yield return c(((global::dotVariant.GeneratorSupport.Accessor_3)variant).Value); + yield return c(variant.UnsafeGet(new global::dotVariant.Accessor._3())); } } } @@ -1070,9 +1100,9 @@ public static partial class VariantEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 1) + if (variant.Index == 1) { - yield return a(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return a(variant.UnsafeGet(new global::dotVariant.Accessor._1())); } else { @@ -1101,9 +1131,9 @@ public static partial class VariantEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 2) + if (variant.Index == 2) { - yield return b(((global::dotVariant.GeneratorSupport.Accessor_2)variant).Value); + yield return b(variant.UnsafeGet(new global::dotVariant.Accessor._2())); } else { @@ -1132,9 +1162,9 @@ public static partial class VariantEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 3) + if (variant.Index == 3) { - yield return c(((global::dotVariant.GeneratorSupport.Accessor_3)variant).Value); + yield return c(variant.UnsafeGet(new global::dotVariant.Accessor._3())); } else { @@ -1164,9 +1194,9 @@ public static partial class VariantEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 1) + if (variant.Index == 1) { - yield return a(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return a(variant.UnsafeGet(new global::dotVariant.Accessor._1())); } else { @@ -1195,9 +1225,9 @@ public static partial class VariantEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 2) + if (variant.Index == 2) { - yield return b(((global::dotVariant.GeneratorSupport.Accessor_2)variant).Value); + yield return b(variant.UnsafeGet(new global::dotVariant.Accessor._2())); } else { @@ -1226,9 +1256,9 @@ public static partial class VariantEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 3) + if (variant.Index == 3) { - yield return c(((global::dotVariant.GeneratorSupport.Accessor_3)variant).Value); + yield return c(variant.UnsafeGet(new global::dotVariant.Accessor._3())); } else { @@ -1260,19 +1290,19 @@ public static partial class VariantEx { foreach (var variant in source) { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant)) + switch (variant.Index) { case 0: global::dotVariant.GeneratorSupport.Errors.ThrowEmptyError("Foo.Variant"); yield break; case 1: - yield return a(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return a(variant.UnsafeGet(new global::dotVariant.Accessor._1())); break; case 2: - yield return b(((global::dotVariant.GeneratorSupport.Accessor_2)variant).Value); + yield return b(variant.UnsafeGet(new global::dotVariant.Accessor._2())); break; case 3: - yield return c(((global::dotVariant.GeneratorSupport.Accessor_3)variant).Value); + yield return c(variant.UnsafeGet(new global::dotVariant.Accessor._3())); break; default: global::dotVariant.GeneratorSupport.Errors.ThrowInternalError("Foo.Variant"); @@ -1304,19 +1334,19 @@ public static partial class VariantEx { foreach (var variant in source) { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant)) + switch (variant.Index) { case 0: yield return _(); break; case 1: - yield return a(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return a(variant.UnsafeGet(new global::dotVariant.Accessor._1())); break; case 2: - yield return b(((global::dotVariant.GeneratorSupport.Accessor_2)variant).Value); + yield return b(variant.UnsafeGet(new global::dotVariant.Accessor._2())); break; case 3: - yield return c(((global::dotVariant.GeneratorSupport.Accessor_3)variant).Value); + yield return c(variant.UnsafeGet(new global::dotVariant.Accessor._3())); break; default: global::dotVariant.GeneratorSupport.Errors.ThrowInternalError("Foo.Variant"); @@ -1347,8 +1377,8 @@ public static partial class VariantEx where T3 : struct { return global::System.Reactive.Linq.Observable.Select( - global::System.Reactive.Linq.Observable.Where(source, _variant => ((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 1), - _variant => a(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value)); + global::System.Reactive.Linq.Observable.Where(source, _variant => _variant.Index == 1), + _variant => a(_variant.UnsafeGet(new global::dotVariant.Accessor._1()))); } /// /// Projects each element of an observable sequence @@ -1367,8 +1397,8 @@ public static partial class VariantEx where T3 : struct { return global::System.Reactive.Linq.Observable.Select( - global::System.Reactive.Linq.Observable.Where(source, _variant => ((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 2), - _variant => b(((global::dotVariant.GeneratorSupport.Accessor_2)_variant).Value)); + global::System.Reactive.Linq.Observable.Where(source, _variant => _variant.Index == 2), + _variant => b(_variant.UnsafeGet(new global::dotVariant.Accessor._2()))); } /// /// Projects each element of an observable sequence @@ -1387,8 +1417,8 @@ public static partial class VariantEx where T3 : struct { return global::System.Reactive.Linq.Observable.Select( - global::System.Reactive.Linq.Observable.Where(source, _variant => ((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 3), - _variant => c(((global::dotVariant.GeneratorSupport.Accessor_3)_variant).Value)); + global::System.Reactive.Linq.Observable.Where(source, _variant => _variant.Index == 3), + _variant => c(_variant.UnsafeGet(new global::dotVariant.Accessor._3()))); } /// @@ -1411,9 +1441,9 @@ public static partial class VariantEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 1) + if (_variant.Index == 1) { - return a(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + return a(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); } else { @@ -1441,9 +1471,9 @@ public static partial class VariantEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 2) + if (_variant.Index == 2) { - return b(((global::dotVariant.GeneratorSupport.Accessor_2)_variant).Value); + return b(_variant.UnsafeGet(new global::dotVariant.Accessor._2())); } else { @@ -1471,9 +1501,9 @@ public static partial class VariantEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 3) + if (_variant.Index == 3) { - return c(((global::dotVariant.GeneratorSupport.Accessor_3)_variant).Value); + return c(_variant.UnsafeGet(new global::dotVariant.Accessor._3())); } else { @@ -1502,9 +1532,9 @@ public static partial class VariantEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 1) + if (_variant.Index == 1) { - return a(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + return a(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); } else { @@ -1532,9 +1562,9 @@ public static partial class VariantEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 2) + if (_variant.Index == 2) { - return b(((global::dotVariant.GeneratorSupport.Accessor_2)_variant).Value); + return b(_variant.UnsafeGet(new global::dotVariant.Accessor._2())); } else { @@ -1562,9 +1592,9 @@ public static partial class VariantEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 3) + if (_variant.Index == 3) { - return c(((global::dotVariant.GeneratorSupport.Accessor_3)_variant).Value); + return c(_variant.UnsafeGet(new global::dotVariant.Accessor._3())); } else { @@ -1593,16 +1623,16 @@ public static partial class VariantEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant)) + switch (_variant.Index) { case 0: return global::dotVariant.GeneratorSupport.Errors.ThrowEmptyError("Foo.Variant"); case 1: - return a(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + return a(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); case 2: - return b(((global::dotVariant.GeneratorSupport.Accessor_2)_variant).Value); + return b(_variant.UnsafeGet(new global::dotVariant.Accessor._2())); case 3: - return c(((global::dotVariant.GeneratorSupport.Accessor_3)_variant).Value); + return c(_variant.UnsafeGet(new global::dotVariant.Accessor._3())); default: return global::dotVariant.GeneratorSupport.Errors.ThrowInternalError("Foo.Variant"); } @@ -1631,16 +1661,16 @@ public static partial class VariantEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant)) + switch (_variant.Index) { case 0: return _(); case 1: - return a(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + return a(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); case 2: - return b(((global::dotVariant.GeneratorSupport.Accessor_2)_variant).Value); + return b(_variant.UnsafeGet(new global::dotVariant.Accessor._2())); case 3: - return c(((global::dotVariant.GeneratorSupport.Accessor_3)_variant).Value); + return c(_variant.UnsafeGet(new global::dotVariant.Accessor._3())); default: return global::dotVariant.GeneratorSupport.Errors.ThrowInternalError("Foo.Variant"); } @@ -1813,7 +1843,7 @@ public void Dispose() public void OnNext(global::Foo.Variant _variant) { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant)) + switch (_variant.Index) { case 0: if (_accept0) @@ -1826,13 +1856,13 @@ public void OnNext(global::Foo.Variant _variant) } break; case 1: - Subject1.OnNext(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + Subject1.OnNext(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); break; case 2: - Subject2.OnNext(((global::dotVariant.GeneratorSupport.Accessor_2)_variant).Value); + Subject2.OnNext(_variant.UnsafeGet(new global::dotVariant.Accessor._2())); break; case 3: - Subject3.OnNext(((global::dotVariant.GeneratorSupport.Accessor_3)_variant).Value); + Subject3.OnNext(_variant.UnsafeGet(new global::dotVariant.Accessor._3())); break; default: OnError(global::dotVariant.GeneratorSupport.Errors.MakeInternalError("Foo.Variant")); diff --git a/src/dotVariant.Generator.Test/samples/Variant-generic-notnull.out.cs b/src/dotVariant.Generator.Test/samples/Variant-generic-notnull.out.cs index 2a23292..8286751 100644 --- a/src/dotVariant.Generator.Test/samples/Variant-generic-notnull.out.cs +++ b/src/dotVariant.Generator.Test/samples/Variant-generic-notnull.out.cs @@ -44,6 +44,11 @@ public static Variant Create(T value) public bool IsEmpty => _variant.IsEmpty; + /// + [global::System.Diagnostics.DebuggerNonUserCode] + public byte Index + => _variant.Index; + /// [global::System.Diagnostics.DebuggerNonUserCode] public override bool Equals(object? other) @@ -71,6 +76,11 @@ public override int GetHashCode() public override string ToString() => _variant.ToString(); + /// + [global::System.Diagnostics.DebuggerNonUserCode] + public T UnsafeGet(global::dotVariant.Accessor._1 accessor) + => _variant.UnsafeGet(accessor); + /// [global::System.Diagnostics.DebuggerNonUserCode] public bool TryMatch([global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out T? value) @@ -144,15 +154,6 @@ public __DebuggerTypeProxy(Variant v) #pragma warning restore 8604, 8625 } } - - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - [global::System.Diagnostics.DebuggerNonUserCode] - public static explicit operator global::dotVariant.GeneratorSupport.Discriminator(Variant v) - => (global::dotVariant.GeneratorSupport.Discriminator)v._variant; - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - [global::System.Diagnostics.DebuggerNonUserCode] - public static explicit operator global::dotVariant.GeneratorSupport.Accessor_1(Variant v) - => (global::dotVariant.GeneratorSupport.Accessor_1)v._variant; } } @@ -173,24 +174,25 @@ public Union(T value) } private readonly Union _x; - private readonly byte _n; + + /// + /// The 1-based index of the currently stored type, + /// counted left-ro-right from the parameter list. + /// 0 if the variant is empty. + /// + public readonly byte Index; public Variant(T value) { - _n = 1; + Index = 1; _x = new Union(value); } - public static explicit operator global::dotVariant.GeneratorSupport.Discriminator(in Variant v) - => (global::dotVariant.GeneratorSupport.Discriminator)v._n; - public static explicit operator global::dotVariant.GeneratorSupport.Accessor_1(in Variant v) - => new global::dotVariant.GeneratorSupport.Accessor_1(v._x._1); - /// /// if Variant was constructed without a value. /// - public bool IsEmpty => _n == 0; + public bool IsEmpty => this.Index == 0; /// /// The string representation of the stored value's type. @@ -199,7 +201,7 @@ public string TypeString { get { - switch (_n) + switch (this.Index) { case 0: return ""; @@ -216,7 +218,7 @@ public string TypeString /// public override string ToString() { - switch (_n) + switch (this.Index) { case 0: return ""; @@ -234,7 +236,7 @@ public object? AsObject { get { - switch (_n) + switch (this.Index) { case 0: return null; @@ -248,11 +250,11 @@ public object? AsObject public bool Equals(in Variant other) { - if (_n != other._n) + if (this.Index != other.Index) { return false; } - switch (_n) + switch (Index) { case 0: return true; @@ -265,7 +267,7 @@ public bool Equals(in Variant other) public override int GetHashCode() { - switch (_n) + switch (this.Index) { case 0: return 0; @@ -276,6 +278,16 @@ public override int GetHashCode() } } + /// + /// Retrieve the stored value assuming it is of type . + /// + /// Only call this if you have ensured that Index == 1, + /// otherwise the correctness of the returned value is not guaranteed, + /// nor that any value is returned at all. + /// + public T UnsafeGet(global::dotVariant.Accessor._1 _) + => _x._1; + /// /// Retrieve the value stored within Variant if it is of type . /// @@ -283,8 +295,8 @@ public override int GetHashCode() /// if Variant contained a value of type . public bool TryMatch([global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out T? value) { - value = _n == 1 ? _x._1 : default; - return _n == 1; + value = this.Index == 1 ? _x._1 : default; + return this.Index == 1; } /// @@ -295,7 +307,7 @@ public bool TryMatch([global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] /// Any exception thrown from is rethrown. public bool TryMatch(global::System.Action value) { - if (_n == 1) + if (this.Index == 1) { value(_x._1); return true; @@ -311,7 +323,7 @@ public bool TryMatch(global::System.Action value) /// Variant does not contain a value of type . public void Match([global::System.Diagnostics.CodeAnalysis.NotNull] out T? value) { - if (_n == 1) + if (this.Index == 1) { value = _x._1; return; @@ -328,7 +340,7 @@ public void Match([global::System.Diagnostics.CodeAnalysis.NotNull] out T? value /// Any exception thrown from is rethrown. public void Match(global::System.Action value) { - if (_n == 1) + if (this.Index == 1) { value(_x._1); return; @@ -345,7 +357,7 @@ public void Match(global::System.Action value) /// Any exception thrown from or is rethrown. public void Match(global::System.Action value, global::System.Action _) { - if (_n == 1) + if (this.Index == 1) { value(_x._1); } @@ -365,7 +377,7 @@ public void Match(global::System.Action value, global::System.Action _) /// Any exception thrown from is rethrown. public TResult Match(global::System.Func value) { - if (_n == 1) + if (this.Index == 1) { return value(_x._1); } @@ -382,7 +394,7 @@ public TResult Match(global::System.Func value) /// Any exception thrown from or is rethrown. public TResult Match(global::System.Func value, TResult _) { - return _n == 1 ? value(_x._1) : _; + return this.Index == 1 ? value(_x._1) : _; } /// @@ -394,7 +406,7 @@ public TResult Match(global::System.Func value, TResult _) /// Any exception thrown from or is rethrown. public TResult Match(global::System.Func value, global::System.Func _) { - return _n == 1 ? value(_x._1) : _(); + return this.Index == 1 ? value(_x._1) : _(); } /// @@ -406,7 +418,7 @@ public TResult Match(global::System.Func value, global::Sys /// Any exception thrown from a delegate is rethrown. public void Visit(global::System.Action value, global::System.Action _) { - switch (_n) + switch (this.Index) { case 0: _(); @@ -429,7 +441,7 @@ public void Visit(global::System.Action value, global::System.Action _) /// Any exception thrown from a delegate is rethrown. public void Visit(global::System.Action value) { - switch (_n) + switch (this.Index) { case 0: global::dotVariant.GeneratorSupport.Errors.ThrowEmptyError("Foo.Variant"); @@ -453,7 +465,7 @@ public void Visit(global::System.Action value) /// The return type of all delegates, and by extension the return type of this function. public TResult Visit(global::System.Func value, global::System.Func _) { - switch (_n) + switch (this.Index) { case 0: return _(); @@ -474,7 +486,7 @@ public TResult Visit(global::System.Func value, global::Sys /// The return type of all delegates, and by extension the return type of this function. public TResult Visit(global::System.Func value) { - switch (_n) + switch (this.Index) { case 0: return global::dotVariant.GeneratorSupport.Errors.ThrowEmptyError("Foo.Variant"); @@ -509,9 +521,9 @@ public static partial class VariantEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 1) + if (variant.Index == 1) { - yield return value(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return value(variant.UnsafeGet(new global::dotVariant.Accessor._1())); } } } @@ -535,9 +547,9 @@ public static partial class VariantEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 1) + if (variant.Index == 1) { - yield return value(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return value(variant.UnsafeGet(new global::dotVariant.Accessor._1())); } else { @@ -565,9 +577,9 @@ public static partial class VariantEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 1) + if (variant.Index == 1) { - yield return value(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return value(variant.UnsafeGet(new global::dotVariant.Accessor._1())); } else { @@ -595,13 +607,13 @@ public static partial class VariantEx { foreach (var variant in source) { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant)) + switch (variant.Index) { case 0: global::dotVariant.GeneratorSupport.Errors.ThrowEmptyError("Foo.Variant"); yield break; case 1: - yield return value(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return value(variant.UnsafeGet(new global::dotVariant.Accessor._1())); break; default: global::dotVariant.GeneratorSupport.Errors.ThrowInternalError("Foo.Variant"); @@ -629,13 +641,13 @@ public static partial class VariantEx { foreach (var variant in source) { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant)) + switch (variant.Index) { case 0: yield return _(); break; case 1: - yield return value(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return value(variant.UnsafeGet(new global::dotVariant.Accessor._1())); break; default: global::dotVariant.GeneratorSupport.Errors.ThrowInternalError("Foo.Variant"); @@ -664,8 +676,8 @@ public static partial class VariantEx where T : notnull { return global::System.Reactive.Linq.Observable.Select( - global::System.Reactive.Linq.Observable.Where(source, _variant => ((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 1), - _variant => value(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value)); + global::System.Reactive.Linq.Observable.Where(source, _variant => _variant.Index == 1), + _variant => value(_variant.UnsafeGet(new global::dotVariant.Accessor._1()))); } /// @@ -686,9 +698,9 @@ public static partial class VariantEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 1) + if (_variant.Index == 1) { - return value(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + return value(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); } else { @@ -715,9 +727,9 @@ public static partial class VariantEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 1) + if (_variant.Index == 1) { - return value(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + return value(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); } else { @@ -742,12 +754,12 @@ public static partial class VariantEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant)) + switch (_variant.Index) { case 0: return global::dotVariant.GeneratorSupport.Errors.ThrowEmptyError("Foo.Variant"); case 1: - return value(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + return value(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); default: return global::dotVariant.GeneratorSupport.Errors.ThrowInternalError("Foo.Variant"); } @@ -772,12 +784,12 @@ public static partial class VariantEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant)) + switch (_variant.Index) { case 0: return _(); case 1: - return value(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + return value(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); default: return global::dotVariant.GeneratorSupport.Errors.ThrowInternalError("Foo.Variant"); } @@ -903,7 +915,7 @@ public void Dispose() public void OnNext(global::Foo.Variant _variant) { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant)) + switch (_variant.Index) { case 0: if (_accept0) @@ -916,7 +928,7 @@ public void OnNext(global::Foo.Variant _variant) } break; case 1: - Subject1.OnNext(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + Subject1.OnNext(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); break; default: OnError(global::dotVariant.GeneratorSupport.Errors.MakeInternalError("Foo.Variant")); diff --git a/src/dotVariant.Generator.Test/samples/Variant-generic-struct.out.cs b/src/dotVariant.Generator.Test/samples/Variant-generic-struct.out.cs index d091bf7..a71a00d 100644 --- a/src/dotVariant.Generator.Test/samples/Variant-generic-struct.out.cs +++ b/src/dotVariant.Generator.Test/samples/Variant-generic-struct.out.cs @@ -44,6 +44,11 @@ public static Variant Create(T value) public bool IsEmpty => _variant.IsEmpty; + /// + [global::System.Diagnostics.DebuggerNonUserCode] + public byte Index + => _variant.Index; + /// [global::System.Diagnostics.DebuggerNonUserCode] public override bool Equals(object? other) @@ -71,6 +76,11 @@ public override int GetHashCode() public override string ToString() => _variant.ToString(); + /// + [global::System.Diagnostics.DebuggerNonUserCode] + public T UnsafeGet(global::dotVariant.Accessor._1 accessor) + => _variant.UnsafeGet(accessor); + /// [global::System.Diagnostics.DebuggerNonUserCode] public bool TryMatch([global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out T value) @@ -144,15 +154,6 @@ public __DebuggerTypeProxy(Variant v) #pragma warning restore 8604, 8625 } } - - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - [global::System.Diagnostics.DebuggerNonUserCode] - public static explicit operator global::dotVariant.GeneratorSupport.Discriminator(Variant v) - => (global::dotVariant.GeneratorSupport.Discriminator)v._variant; - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - [global::System.Diagnostics.DebuggerNonUserCode] - public static explicit operator global::dotVariant.GeneratorSupport.Accessor_1(Variant v) - => (global::dotVariant.GeneratorSupport.Accessor_1)v._variant; } } @@ -173,24 +174,25 @@ public Union(T value) } private readonly Union _x; - private readonly byte _n; + + /// + /// The 1-based index of the currently stored type, + /// counted left-ro-right from the parameter list. + /// 0 if the variant is empty. + /// + public readonly byte Index; public Variant(T value) { - _n = 1; + Index = 1; _x = new Union(value); } - public static explicit operator global::dotVariant.GeneratorSupport.Discriminator(in Variant v) - => (global::dotVariant.GeneratorSupport.Discriminator)v._n; - public static explicit operator global::dotVariant.GeneratorSupport.Accessor_1(in Variant v) - => new global::dotVariant.GeneratorSupport.Accessor_1(v._x._1); - /// /// if Variant was constructed without a value. /// - public bool IsEmpty => _n == 0; + public bool IsEmpty => this.Index == 0; /// /// The string representation of the stored value's type. @@ -199,7 +201,7 @@ public string TypeString { get { - switch (_n) + switch (this.Index) { case 0: return ""; @@ -216,7 +218,7 @@ public string TypeString /// public override string ToString() { - switch (_n) + switch (this.Index) { case 0: return ""; @@ -234,7 +236,7 @@ public object? AsObject { get { - switch (_n) + switch (this.Index) { case 0: return null; @@ -248,11 +250,11 @@ public object? AsObject public bool Equals(in Variant other) { - if (_n != other._n) + if (this.Index != other.Index) { return false; } - switch (_n) + switch (Index) { case 0: return true; @@ -265,7 +267,7 @@ public bool Equals(in Variant other) public override int GetHashCode() { - switch (_n) + switch (this.Index) { case 0: return 0; @@ -276,6 +278,16 @@ public override int GetHashCode() } } + /// + /// Retrieve the stored value assuming it is of type . + /// + /// Only call this if you have ensured that Index == 1, + /// otherwise the correctness of the returned value is not guaranteed, + /// nor that any value is returned at all. + /// + public T UnsafeGet(global::dotVariant.Accessor._1 _) + => _x._1; + /// /// Retrieve the value stored within Variant if it is of type . /// @@ -283,8 +295,8 @@ public override int GetHashCode() /// if Variant contained a value of type . public bool TryMatch([global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out T value) { - value = _n == 1 ? _x._1 : default; - return _n == 1; + value = this.Index == 1 ? _x._1 : default; + return this.Index == 1; } /// @@ -295,7 +307,7 @@ public bool TryMatch([global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] /// Any exception thrown from is rethrown. public bool TryMatch(global::System.Action value) { - if (_n == 1) + if (this.Index == 1) { value(_x._1); return true; @@ -311,7 +323,7 @@ public bool TryMatch(global::System.Action value) /// Variant does not contain a value of type . public void Match([global::System.Diagnostics.CodeAnalysis.NotNull] out T value) { - if (_n == 1) + if (this.Index == 1) { value = _x._1; return; @@ -328,7 +340,7 @@ public void Match([global::System.Diagnostics.CodeAnalysis.NotNull] out T value) /// Any exception thrown from is rethrown. public void Match(global::System.Action value) { - if (_n == 1) + if (this.Index == 1) { value(_x._1); return; @@ -345,7 +357,7 @@ public void Match(global::System.Action value) /// Any exception thrown from or is rethrown. public void Match(global::System.Action value, global::System.Action _) { - if (_n == 1) + if (this.Index == 1) { value(_x._1); } @@ -365,7 +377,7 @@ public void Match(global::System.Action value, global::System.Action _) /// Any exception thrown from is rethrown. public TResult Match(global::System.Func value) { - if (_n == 1) + if (this.Index == 1) { return value(_x._1); } @@ -382,7 +394,7 @@ public TResult Match(global::System.Func value) /// Any exception thrown from or is rethrown. public TResult Match(global::System.Func value, TResult _) { - return _n == 1 ? value(_x._1) : _; + return this.Index == 1 ? value(_x._1) : _; } /// @@ -394,7 +406,7 @@ public TResult Match(global::System.Func value, TResult _) /// Any exception thrown from or is rethrown. public TResult Match(global::System.Func value, global::System.Func _) { - return _n == 1 ? value(_x._1) : _(); + return this.Index == 1 ? value(_x._1) : _(); } /// @@ -406,7 +418,7 @@ public TResult Match(global::System.Func value, global::Sys /// Any exception thrown from a delegate is rethrown. public void Visit(global::System.Action value, global::System.Action _) { - switch (_n) + switch (this.Index) { case 0: _(); @@ -429,7 +441,7 @@ public void Visit(global::System.Action value, global::System.Action _) /// Any exception thrown from a delegate is rethrown. public void Visit(global::System.Action value) { - switch (_n) + switch (this.Index) { case 0: global::dotVariant.GeneratorSupport.Errors.ThrowEmptyError("Foo.Variant"); @@ -453,7 +465,7 @@ public void Visit(global::System.Action value) /// The return type of all delegates, and by extension the return type of this function. public TResult Visit(global::System.Func value, global::System.Func _) { - switch (_n) + switch (this.Index) { case 0: return _(); @@ -474,7 +486,7 @@ public TResult Visit(global::System.Func value, global::Sys /// The return type of all delegates, and by extension the return type of this function. public TResult Visit(global::System.Func value) { - switch (_n) + switch (this.Index) { case 0: return global::dotVariant.GeneratorSupport.Errors.ThrowEmptyError("Foo.Variant"); @@ -509,9 +521,9 @@ public static partial class VariantEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 1) + if (variant.Index == 1) { - yield return value(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return value(variant.UnsafeGet(new global::dotVariant.Accessor._1())); } } } @@ -535,9 +547,9 @@ public static partial class VariantEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 1) + if (variant.Index == 1) { - yield return value(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return value(variant.UnsafeGet(new global::dotVariant.Accessor._1())); } else { @@ -565,9 +577,9 @@ public static partial class VariantEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 1) + if (variant.Index == 1) { - yield return value(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return value(variant.UnsafeGet(new global::dotVariant.Accessor._1())); } else { @@ -595,13 +607,13 @@ public static partial class VariantEx { foreach (var variant in source) { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant)) + switch (variant.Index) { case 0: global::dotVariant.GeneratorSupport.Errors.ThrowEmptyError("Foo.Variant"); yield break; case 1: - yield return value(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return value(variant.UnsafeGet(new global::dotVariant.Accessor._1())); break; default: global::dotVariant.GeneratorSupport.Errors.ThrowInternalError("Foo.Variant"); @@ -629,13 +641,13 @@ public static partial class VariantEx { foreach (var variant in source) { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant)) + switch (variant.Index) { case 0: yield return _(); break; case 1: - yield return value(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return value(variant.UnsafeGet(new global::dotVariant.Accessor._1())); break; default: global::dotVariant.GeneratorSupport.Errors.ThrowInternalError("Foo.Variant"); @@ -664,8 +676,8 @@ public static partial class VariantEx where T : struct { return global::System.Reactive.Linq.Observable.Select( - global::System.Reactive.Linq.Observable.Where(source, _variant => ((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 1), - _variant => value(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value)); + global::System.Reactive.Linq.Observable.Where(source, _variant => _variant.Index == 1), + _variant => value(_variant.UnsafeGet(new global::dotVariant.Accessor._1()))); } /// @@ -686,9 +698,9 @@ public static partial class VariantEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 1) + if (_variant.Index == 1) { - return value(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + return value(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); } else { @@ -715,9 +727,9 @@ public static partial class VariantEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 1) + if (_variant.Index == 1) { - return value(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + return value(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); } else { @@ -742,12 +754,12 @@ public static partial class VariantEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant)) + switch (_variant.Index) { case 0: return global::dotVariant.GeneratorSupport.Errors.ThrowEmptyError("Foo.Variant"); case 1: - return value(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + return value(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); default: return global::dotVariant.GeneratorSupport.Errors.ThrowInternalError("Foo.Variant"); } @@ -772,12 +784,12 @@ public static partial class VariantEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant)) + switch (_variant.Index) { case 0: return _(); case 1: - return value(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + return value(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); default: return global::dotVariant.GeneratorSupport.Errors.ThrowInternalError("Foo.Variant"); } @@ -903,7 +915,7 @@ public void Dispose() public void OnNext(global::Foo.Variant _variant) { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant)) + switch (_variant.Index) { case 0: if (_accept0) @@ -916,7 +928,7 @@ public void OnNext(global::Foo.Variant _variant) } break; case 1: - Subject1.OnNext(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + Subject1.OnNext(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); break; default: OnError(global::dotVariant.GeneratorSupport.Errors.MakeInternalError("Foo.Variant")); diff --git a/src/dotVariant.Generator.Test/samples/Variant-generic-unbounded.out.cs b/src/dotVariant.Generator.Test/samples/Variant-generic-unbounded.out.cs index 5fc416e..1de251b 100644 --- a/src/dotVariant.Generator.Test/samples/Variant-generic-unbounded.out.cs +++ b/src/dotVariant.Generator.Test/samples/Variant-generic-unbounded.out.cs @@ -44,6 +44,11 @@ public static Variant Create(T value) public bool IsEmpty => _variant.IsEmpty; + /// + [global::System.Diagnostics.DebuggerNonUserCode] + public byte Index + => _variant.Index; + /// [global::System.Diagnostics.DebuggerNonUserCode] public override bool Equals(object? other) @@ -71,6 +76,11 @@ public override int GetHashCode() public override string ToString() => _variant.ToString(); + /// + [global::System.Diagnostics.DebuggerNonUserCode] + public T UnsafeGet(global::dotVariant.Accessor._1 accessor) + => _variant.UnsafeGet(accessor); + /// [global::System.Diagnostics.DebuggerNonUserCode] public bool TryMatch(out T? value) @@ -144,15 +154,6 @@ public __DebuggerTypeProxy(Variant v) #pragma warning restore 8604, 8625 } } - - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - [global::System.Diagnostics.DebuggerNonUserCode] - public static explicit operator global::dotVariant.GeneratorSupport.Discriminator(Variant v) - => (global::dotVariant.GeneratorSupport.Discriminator)v._variant; - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - [global::System.Diagnostics.DebuggerNonUserCode] - public static explicit operator global::dotVariant.GeneratorSupport.Accessor_1(Variant v) - => (global::dotVariant.GeneratorSupport.Accessor_1)v._variant; } } @@ -172,24 +173,25 @@ public Union(T value) } private readonly Union _x; - private readonly byte _n; + + /// + /// The 1-based index of the currently stored type, + /// counted left-ro-right from the parameter list. + /// 0 if the variant is empty. + /// + public readonly byte Index; public Variant(T value) { - _n = 1; + Index = 1; _x = new Union(value); } - public static explicit operator global::dotVariant.GeneratorSupport.Discriminator(in Variant v) - => (global::dotVariant.GeneratorSupport.Discriminator)v._n; - public static explicit operator global::dotVariant.GeneratorSupport.Accessor_1(in Variant v) - => new global::dotVariant.GeneratorSupport.Accessor_1(v._x._1); - /// /// if Variant was constructed without a value. /// - public bool IsEmpty => _n == 0; + public bool IsEmpty => this.Index == 0; /// /// The string representation of the stored value's type. @@ -198,7 +200,7 @@ public string TypeString { get { - switch (_n) + switch (this.Index) { case 0: return ""; @@ -215,7 +217,7 @@ public string TypeString /// public override string ToString() { - switch (_n) + switch (this.Index) { case 0: return ""; @@ -233,7 +235,7 @@ public object? AsObject { get { - switch (_n) + switch (this.Index) { case 0: return null; @@ -247,11 +249,11 @@ public object? AsObject public bool Equals(in Variant other) { - if (_n != other._n) + if (this.Index != other.Index) { return false; } - switch (_n) + switch (Index) { case 0: return true; @@ -264,7 +266,7 @@ public bool Equals(in Variant other) public override int GetHashCode() { - switch (_n) + switch (this.Index) { case 0: return 0; @@ -275,6 +277,16 @@ public override int GetHashCode() } } + /// + /// Retrieve the stored value assuming it is of type . + /// + /// Only call this if you have ensured that Index == 1, + /// otherwise the correctness of the returned value is not guaranteed, + /// nor that any value is returned at all. + /// + public T UnsafeGet(global::dotVariant.Accessor._1 _) + => _x._1; + /// /// Retrieve the value stored within Variant if it is of type . /// @@ -282,8 +294,8 @@ public override int GetHashCode() /// if Variant contained a value of type . public bool TryMatch(out T? value) { - value = _n == 1 ? _x._1 : default; - return _n == 1; + value = this.Index == 1 ? _x._1 : default; + return this.Index == 1; } /// @@ -294,7 +306,7 @@ public bool TryMatch(out T? value) /// Any exception thrown from is rethrown. public bool TryMatch(global::System.Action value) { - if (_n == 1) + if (this.Index == 1) { value(_x._1); return true; @@ -310,7 +322,7 @@ public bool TryMatch(global::System.Action value) /// Variant does not contain a value of type . public void Match(out T? value) { - if (_n == 1) + if (this.Index == 1) { value = _x._1; return; @@ -327,7 +339,7 @@ public void Match(out T? value) /// Any exception thrown from is rethrown. public void Match(global::System.Action value) { - if (_n == 1) + if (this.Index == 1) { value(_x._1); return; @@ -344,7 +356,7 @@ public void Match(global::System.Action value) /// Any exception thrown from or is rethrown. public void Match(global::System.Action value, global::System.Action _) { - if (_n == 1) + if (this.Index == 1) { value(_x._1); } @@ -364,7 +376,7 @@ public void Match(global::System.Action value, global::System.Action _) /// Any exception thrown from is rethrown. public TResult Match(global::System.Func value) { - if (_n == 1) + if (this.Index == 1) { return value(_x._1); } @@ -381,7 +393,7 @@ public TResult Match(global::System.Func value) /// Any exception thrown from or is rethrown. public TResult Match(global::System.Func value, TResult _) { - return _n == 1 ? value(_x._1) : _; + return this.Index == 1 ? value(_x._1) : _; } /// @@ -393,7 +405,7 @@ public TResult Match(global::System.Func value, TResult _) /// Any exception thrown from or is rethrown. public TResult Match(global::System.Func value, global::System.Func _) { - return _n == 1 ? value(_x._1) : _(); + return this.Index == 1 ? value(_x._1) : _(); } /// @@ -405,7 +417,7 @@ public TResult Match(global::System.Func value, global::Sys /// Any exception thrown from a delegate is rethrown. public void Visit(global::System.Action value, global::System.Action _) { - switch (_n) + switch (this.Index) { case 0: _(); @@ -428,7 +440,7 @@ public void Visit(global::System.Action value, global::System.Action _) /// Any exception thrown from a delegate is rethrown. public void Visit(global::System.Action value) { - switch (_n) + switch (this.Index) { case 0: global::dotVariant.GeneratorSupport.Errors.ThrowEmptyError("Foo.Variant"); @@ -452,7 +464,7 @@ public void Visit(global::System.Action value) /// The return type of all delegates, and by extension the return type of this function. public TResult Visit(global::System.Func value, global::System.Func _) { - switch (_n) + switch (this.Index) { case 0: return _(); @@ -473,7 +485,7 @@ public TResult Visit(global::System.Func value, global::Sys /// The return type of all delegates, and by extension the return type of this function. public TResult Visit(global::System.Func value) { - switch (_n) + switch (this.Index) { case 0: return global::dotVariant.GeneratorSupport.Errors.ThrowEmptyError("Foo.Variant"); @@ -507,9 +519,9 @@ public static partial class VariantEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 1) + if (variant.Index == 1) { - yield return value(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return value(variant.UnsafeGet(new global::dotVariant.Accessor._1())); } } } @@ -532,9 +544,9 @@ public static partial class VariantEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 1) + if (variant.Index == 1) { - yield return value(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return value(variant.UnsafeGet(new global::dotVariant.Accessor._1())); } else { @@ -561,9 +573,9 @@ public static partial class VariantEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 1) + if (variant.Index == 1) { - yield return value(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return value(variant.UnsafeGet(new global::dotVariant.Accessor._1())); } else { @@ -590,13 +602,13 @@ public static partial class VariantEx { foreach (var variant in source) { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant)) + switch (variant.Index) { case 0: global::dotVariant.GeneratorSupport.Errors.ThrowEmptyError("Foo.Variant"); yield break; case 1: - yield return value(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return value(variant.UnsafeGet(new global::dotVariant.Accessor._1())); break; default: global::dotVariant.GeneratorSupport.Errors.ThrowInternalError("Foo.Variant"); @@ -623,13 +635,13 @@ public static partial class VariantEx { foreach (var variant in source) { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant)) + switch (variant.Index) { case 0: yield return _(); break; case 1: - yield return value(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return value(variant.UnsafeGet(new global::dotVariant.Accessor._1())); break; default: global::dotVariant.GeneratorSupport.Errors.ThrowInternalError("Foo.Variant"); @@ -657,8 +669,8 @@ public static partial class VariantEx global::System.Func value) { return global::System.Reactive.Linq.Observable.Select( - global::System.Reactive.Linq.Observable.Where(source, _variant => ((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 1), - _variant => value(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value)); + global::System.Reactive.Linq.Observable.Where(source, _variant => _variant.Index == 1), + _variant => value(_variant.UnsafeGet(new global::dotVariant.Accessor._1()))); } /// @@ -678,9 +690,9 @@ public static partial class VariantEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 1) + if (_variant.Index == 1) { - return value(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + return value(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); } else { @@ -706,9 +718,9 @@ public static partial class VariantEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 1) + if (_variant.Index == 1) { - return value(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + return value(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); } else { @@ -732,12 +744,12 @@ public static partial class VariantEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant)) + switch (_variant.Index) { case 0: return global::dotVariant.GeneratorSupport.Errors.ThrowEmptyError("Foo.Variant"); case 1: - return value(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + return value(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); default: return global::dotVariant.GeneratorSupport.Errors.ThrowInternalError("Foo.Variant"); } @@ -761,12 +773,12 @@ public static partial class VariantEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant)) + switch (_variant.Index) { case 0: return _(); case 1: - return value(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + return value(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); default: return global::dotVariant.GeneratorSupport.Errors.ThrowInternalError("Foo.Variant"); } @@ -888,7 +900,7 @@ public void Dispose() public void OnNext(global::Foo.Variant _variant) { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant)) + switch (_variant.Index) { case 0: if (_accept0) @@ -901,7 +913,7 @@ public void OnNext(global::Foo.Variant _variant) } break; case 1: - Subject1.OnNext(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + Subject1.OnNext(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); break; default: OnError(global::dotVariant.GeneratorSupport.Errors.MakeInternalError("Foo.Variant")); diff --git a/src/dotVariant.Generator.Test/samples/Variant-nullable-value-type.out.cs b/src/dotVariant.Generator.Test/samples/Variant-nullable-value-type.out.cs index 25c0aac..0aeb0b2 100644 --- a/src/dotVariant.Generator.Test/samples/Variant-nullable-value-type.out.cs +++ b/src/dotVariant.Generator.Test/samples/Variant-nullable-value-type.out.cs @@ -44,6 +44,11 @@ public static Variant_nullable_value_type Create(int? i) public bool IsEmpty => _variant.IsEmpty; + /// + [global::System.Diagnostics.DebuggerNonUserCode] + public byte Index + => _variant.Index; + /// [global::System.Diagnostics.DebuggerNonUserCode] public override bool Equals(object? other) @@ -71,6 +76,11 @@ public override int GetHashCode() public override string ToString() => _variant.ToString(); + /// + [global::System.Diagnostics.DebuggerNonUserCode] + public int? UnsafeGet(global::dotVariant.Accessor._1 accessor) + => _variant.UnsafeGet(accessor); + /// [global::System.Diagnostics.DebuggerNonUserCode] public bool TryMatch(out int? i) @@ -144,15 +154,6 @@ public __DebuggerTypeProxy(Variant_nullable_value_type v) #pragma warning restore 8604, 8625 } } - - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - [global::System.Diagnostics.DebuggerNonUserCode] - public static explicit operator global::dotVariant.GeneratorSupport.Discriminator(Variant_nullable_value_type v) - => (global::dotVariant.GeneratorSupport.Discriminator)v._variant; - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - [global::System.Diagnostics.DebuggerNonUserCode] - public static explicit operator global::dotVariant.GeneratorSupport.Accessor_1(Variant_nullable_value_type v) - => (global::dotVariant.GeneratorSupport.Accessor_1)v._variant; } } @@ -172,24 +173,25 @@ public Union(int? value) } private readonly Union _x; - private readonly byte _n; + + /// + /// The 1-based index of the currently stored type, + /// counted left-ro-right from the parameter list. + /// 0 if the variant is empty. + /// + public readonly byte Index; public Variant_nullable_value_type(int? i) { - _n = 1; + Index = 1; _x = new Union(i); } - public static explicit operator global::dotVariant.GeneratorSupport.Discriminator(in Variant_nullable_value_type v) - => (global::dotVariant.GeneratorSupport.Discriminator)v._n; - public static explicit operator global::dotVariant.GeneratorSupport.Accessor_1(in Variant_nullable_value_type v) - => new global::dotVariant.GeneratorSupport.Accessor_1(v._x._1); - /// /// if Variant_nullable_value_type was constructed without a value. /// - public bool IsEmpty => _n == 0; + public bool IsEmpty => this.Index == 0; /// /// The string representation of the stored value's type. @@ -198,7 +200,7 @@ public string TypeString { get { - switch (_n) + switch (this.Index) { case 0: return ""; @@ -215,7 +217,7 @@ public string TypeString /// public override string ToString() { - switch (_n) + switch (this.Index) { case 0: return ""; @@ -233,7 +235,7 @@ public object? AsObject { get { - switch (_n) + switch (this.Index) { case 0: return null; @@ -247,11 +249,11 @@ public object? AsObject public bool Equals(in Variant_nullable_value_type other) { - if (_n != other._n) + if (this.Index != other.Index) { return false; } - switch (_n) + switch (Index) { case 0: return true; @@ -264,7 +266,7 @@ public bool Equals(in Variant_nullable_value_type other) public override int GetHashCode() { - switch (_n) + switch (this.Index) { case 0: return 0; @@ -275,6 +277,16 @@ public override int GetHashCode() } } + /// + /// Retrieve the stored value assuming it is of type . + /// + /// Only call this if you have ensured that Index == 1, + /// otherwise the correctness of the returned value is not guaranteed, + /// nor that any value is returned at all. + /// + public int? UnsafeGet(global::dotVariant.Accessor._1 _) + => _x._1; + /// /// Retrieve the value stored within Variant_nullable_value_type if it is of type . /// @@ -282,8 +294,8 @@ public override int GetHashCode() /// if Variant_nullable_value_type contained a value of type . public bool TryMatch(out int? i) { - i = _n == 1 ? _x._1 : default; - return _n == 1; + i = this.Index == 1 ? _x._1 : default; + return this.Index == 1; } /// @@ -294,7 +306,7 @@ public bool TryMatch(out int? i) /// Any exception thrown from is rethrown. public bool TryMatch(global::System.Action i) { - if (_n == 1) + if (this.Index == 1) { i(_x._1); return true; @@ -310,7 +322,7 @@ public bool TryMatch(global::System.Action i) /// Variant_nullable_value_type does not contain a value of type . public void Match(out int? i) { - if (_n == 1) + if (this.Index == 1) { i = _x._1; return; @@ -327,7 +339,7 @@ public void Match(out int? i) /// Any exception thrown from is rethrown. public void Match(global::System.Action i) { - if (_n == 1) + if (this.Index == 1) { i(_x._1); return; @@ -344,7 +356,7 @@ public void Match(global::System.Action i) /// Any exception thrown from or is rethrown. public void Match(global::System.Action i, global::System.Action _) { - if (_n == 1) + if (this.Index == 1) { i(_x._1); } @@ -364,7 +376,7 @@ public void Match(global::System.Action i, global::System.Action _) /// Any exception thrown from is rethrown. public TResult Match(global::System.Func i) { - if (_n == 1) + if (this.Index == 1) { return i(_x._1); } @@ -381,7 +393,7 @@ public TResult Match(global::System.Func i) /// Any exception thrown from or is rethrown. public TResult Match(global::System.Func i, TResult _) { - return _n == 1 ? i(_x._1) : _; + return this.Index == 1 ? i(_x._1) : _; } /// @@ -393,7 +405,7 @@ public TResult Match(global::System.Func i, TResult _) /// Any exception thrown from or is rethrown. public TResult Match(global::System.Func i, global::System.Func _) { - return _n == 1 ? i(_x._1) : _(); + return this.Index == 1 ? i(_x._1) : _(); } /// @@ -405,7 +417,7 @@ public TResult Match(global::System.Func i, global::Syst /// Any exception thrown from a delegate is rethrown. public void Visit(global::System.Action i, global::System.Action _) { - switch (_n) + switch (this.Index) { case 0: _(); @@ -428,7 +440,7 @@ public void Visit(global::System.Action i, global::System.Action _) /// Any exception thrown from a delegate is rethrown. public void Visit(global::System.Action i) { - switch (_n) + switch (this.Index) { case 0: global::dotVariant.GeneratorSupport.Errors.ThrowEmptyError("Foo.Variant_nullable_value_type"); @@ -452,7 +464,7 @@ public void Visit(global::System.Action i) /// The return type of all delegates, and by extension the return type of this function. public TResult Visit(global::System.Func i, global::System.Func _) { - switch (_n) + switch (this.Index) { case 0: return _(); @@ -473,7 +485,7 @@ public TResult Visit(global::System.Func i, global::Syst /// The return type of all delegates, and by extension the return type of this function. public TResult Visit(global::System.Func i) { - switch (_n) + switch (this.Index) { case 0: return global::dotVariant.GeneratorSupport.Errors.ThrowEmptyError("Foo.Variant_nullable_value_type"); @@ -507,9 +519,9 @@ public static partial class Variant_nullable_value_typeEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 1) + if (variant.Index == 1) { - yield return i(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return i(variant.UnsafeGet(new global::dotVariant.Accessor._1())); } } } @@ -532,9 +544,9 @@ public static partial class Variant_nullable_value_typeEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 1) + if (variant.Index == 1) { - yield return i(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return i(variant.UnsafeGet(new global::dotVariant.Accessor._1())); } else { @@ -561,9 +573,9 @@ public static partial class Variant_nullable_value_typeEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 1) + if (variant.Index == 1) { - yield return i(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return i(variant.UnsafeGet(new global::dotVariant.Accessor._1())); } else { @@ -590,13 +602,13 @@ public static partial class Variant_nullable_value_typeEx { foreach (var variant in source) { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant)) + switch (variant.Index) { case 0: global::dotVariant.GeneratorSupport.Errors.ThrowEmptyError("Foo.Variant_nullable_value_type"); yield break; case 1: - yield return i(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return i(variant.UnsafeGet(new global::dotVariant.Accessor._1())); break; default: global::dotVariant.GeneratorSupport.Errors.ThrowInternalError("Foo.Variant_nullable_value_type"); @@ -623,13 +635,13 @@ public static partial class Variant_nullable_value_typeEx { foreach (var variant in source) { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant)) + switch (variant.Index) { case 0: yield return _(); break; case 1: - yield return i(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return i(variant.UnsafeGet(new global::dotVariant.Accessor._1())); break; default: global::dotVariant.GeneratorSupport.Errors.ThrowInternalError("Foo.Variant_nullable_value_type"); @@ -657,8 +669,8 @@ public static partial class Variant_nullable_value_typeEx global::System.Func i) { return global::System.Reactive.Linq.Observable.Select( - global::System.Reactive.Linq.Observable.Where(source, _variant => ((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 1), - _variant => i(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value)); + global::System.Reactive.Linq.Observable.Where(source, _variant => _variant.Index == 1), + _variant => i(_variant.UnsafeGet(new global::dotVariant.Accessor._1()))); } /// @@ -678,9 +690,9 @@ public static partial class Variant_nullable_value_typeEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 1) + if (_variant.Index == 1) { - return i(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + return i(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); } else { @@ -706,9 +718,9 @@ public static partial class Variant_nullable_value_typeEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 1) + if (_variant.Index == 1) { - return i(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + return i(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); } else { @@ -732,12 +744,12 @@ public static partial class Variant_nullable_value_typeEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant)) + switch (_variant.Index) { case 0: return global::dotVariant.GeneratorSupport.Errors.ThrowEmptyError("Foo.Variant_nullable_value_type"); case 1: - return i(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + return i(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); default: return global::dotVariant.GeneratorSupport.Errors.ThrowInternalError("Foo.Variant_nullable_value_type"); } @@ -761,12 +773,12 @@ public static partial class Variant_nullable_value_typeEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant)) + switch (_variant.Index) { case 0: return _(); case 1: - return i(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + return i(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); default: return global::dotVariant.GeneratorSupport.Errors.ThrowInternalError("Foo.Variant_nullable_value_type"); } @@ -888,7 +900,7 @@ public void Dispose() public void OnNext(global::Foo.Variant_nullable_value_type _variant) { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant)) + switch (_variant.Index) { case 0: if (_accept0) @@ -901,7 +913,7 @@ public void OnNext(global::Foo.Variant_nullable_value_type _variant) } break; case 1: - Subject1.OnNext(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + Subject1.OnNext(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); break; default: OnError(global::dotVariant.GeneratorSupport.Errors.MakeInternalError("Foo.Variant_nullable_value_type")); diff --git a/src/dotVariant.Generator.Test/samples/Variant-public.out.cs b/src/dotVariant.Generator.Test/samples/Variant-public.out.cs index e7392d9..b259acc 100644 --- a/src/dotVariant.Generator.Test/samples/Variant-public.out.cs +++ b/src/dotVariant.Generator.Test/samples/Variant-public.out.cs @@ -65,6 +65,11 @@ public static Variant_public Create(string s) public bool IsEmpty => _variant.IsEmpty; + /// + [global::System.Diagnostics.DebuggerNonUserCode] + public byte Index + => _variant.Index; + /// [global::System.Diagnostics.DebuggerNonUserCode] public override bool Equals(object other) @@ -92,6 +97,11 @@ public override int GetHashCode() public override string ToString() => _variant.ToString(); + /// + [global::System.Diagnostics.DebuggerNonUserCode] + public int UnsafeGet(global::dotVariant.Accessor._1 accessor) + => _variant.UnsafeGet(accessor); + /// [global::System.Diagnostics.DebuggerNonUserCode] public bool TryMatch(out int i) @@ -132,6 +142,11 @@ public TResult Match(global::System.Func i, TResult _) public TResult Match(global::System.Func i, global::System.Func _) => _variant.Match(i, _); + /// + [global::System.Diagnostics.DebuggerNonUserCode] + public string UnsafeGet(global::dotVariant.Accessor._2 accessor) + => _variant.UnsafeGet(accessor); + /// [global::System.Diagnostics.DebuggerNonUserCode] public bool TryMatch(out string s) @@ -205,19 +220,6 @@ public __DebuggerTypeProxy(Variant_public v) #pragma warning restore 8604, 8625 } } - - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - [global::System.Diagnostics.DebuggerNonUserCode] - public static explicit operator global::dotVariant.GeneratorSupport.Discriminator(Variant_public v) - => (global::dotVariant.GeneratorSupport.Discriminator)v._variant; - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - [global::System.Diagnostics.DebuggerNonUserCode] - public static explicit operator global::dotVariant.GeneratorSupport.Accessor_1(Variant_public v) - => (global::dotVariant.GeneratorSupport.Accessor_1)v._variant; - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - [global::System.Diagnostics.DebuggerNonUserCode] - public static explicit operator global::dotVariant.GeneratorSupport.Accessor_2(Variant_public v) - => (global::dotVariant.GeneratorSupport.Accessor_2)v._variant; } } @@ -244,31 +246,30 @@ public Union(string value) } private readonly Union _x; - private readonly byte _n; + + /// + /// The 1-based index of the currently stored type, + /// counted left-ro-right from the parameter list. + /// 0 if the variant is empty. + /// + public readonly byte Index; public Variant_public(int i) { - _n = 1; + Index = 1; _x = new Union(i); } public Variant_public(string s) { - _n = 2; + Index = 2; _x = new Union(s); } - public static explicit operator global::dotVariant.GeneratorSupport.Discriminator(in Variant_public v) - => (global::dotVariant.GeneratorSupport.Discriminator)v._n; - public static explicit operator global::dotVariant.GeneratorSupport.Accessor_1(in Variant_public v) - => new global::dotVariant.GeneratorSupport.Accessor_1(v._x._1); - public static explicit operator global::dotVariant.GeneratorSupport.Accessor_2(in Variant_public v) - => new global::dotVariant.GeneratorSupport.Accessor_2(v._x._2); - /// /// if Variant_public was constructed without a value. /// - public bool IsEmpty => _n == 0; + public bool IsEmpty => this.Index == 0; /// /// The string representation of the stored value's type. @@ -277,7 +278,7 @@ public string TypeString { get { - switch (_n) + switch (this.Index) { case 0: return ""; @@ -296,7 +297,7 @@ public string TypeString /// public override string ToString() { - switch (_n) + switch (this.Index) { case 0: return ""; @@ -316,7 +317,7 @@ public object AsObject { get { - switch (_n) + switch (this.Index) { case 0: return null; @@ -332,11 +333,11 @@ public object AsObject public bool Equals(in Variant_public other) { - if (_n != other._n) + if (this.Index != other.Index) { return false; } - switch (_n) + switch (Index) { case 0: return true; @@ -351,7 +352,7 @@ public bool Equals(in Variant_public other) public override int GetHashCode() { - switch (_n) + switch (this.Index) { case 0: return 0; @@ -364,6 +365,16 @@ public override int GetHashCode() } } + /// + /// Retrieve the stored value assuming it is of type . + /// + /// Only call this if you have ensured that Index == 1, + /// otherwise the correctness of the returned value is not guaranteed, + /// nor that any value is returned at all. + /// + public int UnsafeGet(global::dotVariant.Accessor._1 _) + => _x._1; + /// /// Retrieve the value stored within Variant_public if it is of type . /// @@ -371,8 +382,8 @@ public override int GetHashCode() /// if Variant_public contained a value of type . public bool TryMatch(out int i) { - i = _n == 1 ? _x._1 : default; - return _n == 1; + i = this.Index == 1 ? _x._1 : default; + return this.Index == 1; } /// @@ -383,7 +394,7 @@ public bool TryMatch(out int i) /// Any exception thrown from is rethrown. public bool TryMatch(global::System.Action i) { - if (_n == 1) + if (this.Index == 1) { i(_x._1); return true; @@ -399,7 +410,7 @@ public bool TryMatch(global::System.Action i) /// Variant_public does not contain a value of type . public void Match(out int i) { - if (_n == 1) + if (this.Index == 1) { i = _x._1; return; @@ -416,7 +427,7 @@ public void Match(out int i) /// Any exception thrown from is rethrown. public void Match(global::System.Action i) { - if (_n == 1) + if (this.Index == 1) { i(_x._1); return; @@ -433,7 +444,7 @@ public void Match(global::System.Action i) /// Any exception thrown from or is rethrown. public void Match(global::System.Action i, global::System.Action _) { - if (_n == 1) + if (this.Index == 1) { i(_x._1); } @@ -453,7 +464,7 @@ public void Match(global::System.Action i, global::System.Action _) /// Any exception thrown from is rethrown. public TResult Match(global::System.Func i) { - if (_n == 1) + if (this.Index == 1) { return i(_x._1); } @@ -470,7 +481,7 @@ public TResult Match(global::System.Func i) /// Any exception thrown from or is rethrown. public TResult Match(global::System.Func i, TResult _) { - return _n == 1 ? i(_x._1) : _; + return this.Index == 1 ? i(_x._1) : _; } /// @@ -482,8 +493,18 @@ public TResult Match(global::System.Func i, TResult _) /// Any exception thrown from or is rethrown. public TResult Match(global::System.Func i, global::System.Func _) { - return _n == 1 ? i(_x._1) : _(); + return this.Index == 1 ? i(_x._1) : _(); } + /// + /// Retrieve the stored value assuming it is of type . + /// + /// Only call this if you have ensured that Index == 2, + /// otherwise the correctness of the returned value is not guaranteed, + /// nor that any value is returned at all. + /// + public string UnsafeGet(global::dotVariant.Accessor._2 _) + => _x._2; + /// /// Retrieve the value stored within Variant_public if it is of type . /// @@ -491,8 +512,8 @@ public TResult Match(global::System.Func i, global::Syste /// if Variant_public contained a value of type . public bool TryMatch(out string s) { - s = _n == 2 ? _x._2 : default; - return _n == 2; + s = this.Index == 2 ? _x._2 : default; + return this.Index == 2; } /// @@ -503,7 +524,7 @@ public bool TryMatch(out string s) /// Any exception thrown from is rethrown. public bool TryMatch(global::System.Action s) { - if (_n == 2) + if (this.Index == 2) { s(_x._2); return true; @@ -519,7 +540,7 @@ public bool TryMatch(global::System.Action s) /// Variant_public does not contain a value of type . public void Match(out string s) { - if (_n == 2) + if (this.Index == 2) { s = _x._2; return; @@ -536,7 +557,7 @@ public void Match(out string s) /// Any exception thrown from is rethrown. public void Match(global::System.Action s) { - if (_n == 2) + if (this.Index == 2) { s(_x._2); return; @@ -553,7 +574,7 @@ public void Match(global::System.Action s) /// Any exception thrown from or is rethrown. public void Match(global::System.Action s, global::System.Action _) { - if (_n == 2) + if (this.Index == 2) { s(_x._2); } @@ -573,7 +594,7 @@ public void Match(global::System.Action s, global::System.Action _) /// Any exception thrown from is rethrown. public TResult Match(global::System.Func s) { - if (_n == 2) + if (this.Index == 2) { return s(_x._2); } @@ -590,7 +611,7 @@ public TResult Match(global::System.Func s) /// Any exception thrown from or is rethrown. public TResult Match(global::System.Func s, TResult _) { - return _n == 2 ? s(_x._2) : _; + return this.Index == 2 ? s(_x._2) : _; } /// @@ -602,7 +623,7 @@ public TResult Match(global::System.Func s, TResult _) /// Any exception thrown from or is rethrown. public TResult Match(global::System.Func s, global::System.Func _) { - return _n == 2 ? s(_x._2) : _(); + return this.Index == 2 ? s(_x._2) : _(); } /// @@ -615,7 +636,7 @@ public TResult Match(global::System.Func s, global::Sy /// Any exception thrown from a delegate is rethrown. public void Visit(global::System.Action i, global::System.Action s, global::System.Action _) { - switch (_n) + switch (this.Index) { case 0: _(); @@ -642,7 +663,7 @@ public void Visit(global::System.Action i, global::System.Action s, /// Any exception thrown from a delegate is rethrown. public void Visit(global::System.Action i, global::System.Action s) { - switch (_n) + switch (this.Index) { case 0: global::dotVariant.GeneratorSupport.Errors.ThrowEmptyError("Foo.Variant_public"); @@ -670,7 +691,7 @@ public void Visit(global::System.Action i, global::System.Action s) /// The return type of all delegates, and by extension the return type of this function. public TResult Visit(global::System.Func i, global::System.Func s, global::System.Func _) { - switch (_n) + switch (this.Index) { case 0: return _(); @@ -694,7 +715,7 @@ public TResult Visit(global::System.Func i, global::Syste /// The return type of all delegates, and by extension the return type of this function. public TResult Visit(global::System.Func i, global::System.Func s) { - switch (_n) + switch (this.Index) { case 0: return global::dotVariant.GeneratorSupport.Errors.ThrowEmptyError("Foo.Variant_public"); @@ -730,9 +751,9 @@ public static partial class Variant_publicEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 1) + if (variant.Index == 1) { - yield return i(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return i(variant.UnsafeGet(new global::dotVariant.Accessor._1())); } } } @@ -752,9 +773,9 @@ public static partial class Variant_publicEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 2) + if (variant.Index == 2) { - yield return s(((global::dotVariant.GeneratorSupport.Accessor_2)variant).Value); + yield return s(variant.UnsafeGet(new global::dotVariant.Accessor._2())); } } } @@ -777,9 +798,9 @@ public static partial class Variant_publicEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 1) + if (variant.Index == 1) { - yield return i(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return i(variant.UnsafeGet(new global::dotVariant.Accessor._1())); } else { @@ -805,9 +826,9 @@ public static partial class Variant_publicEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 2) + if (variant.Index == 2) { - yield return s(((global::dotVariant.GeneratorSupport.Accessor_2)variant).Value); + yield return s(variant.UnsafeGet(new global::dotVariant.Accessor._2())); } else { @@ -834,9 +855,9 @@ public static partial class Variant_publicEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 1) + if (variant.Index == 1) { - yield return i(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return i(variant.UnsafeGet(new global::dotVariant.Accessor._1())); } else { @@ -862,9 +883,9 @@ public static partial class Variant_publicEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 2) + if (variant.Index == 2) { - yield return s(((global::dotVariant.GeneratorSupport.Accessor_2)variant).Value); + yield return s(variant.UnsafeGet(new global::dotVariant.Accessor._2())); } else { @@ -892,16 +913,16 @@ public static partial class Variant_publicEx { foreach (var variant in source) { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant)) + switch (variant.Index) { case 0: global::dotVariant.GeneratorSupport.Errors.ThrowEmptyError("Foo.Variant_public"); yield break; case 1: - yield return i(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return i(variant.UnsafeGet(new global::dotVariant.Accessor._1())); break; case 2: - yield return s(((global::dotVariant.GeneratorSupport.Accessor_2)variant).Value); + yield return s(variant.UnsafeGet(new global::dotVariant.Accessor._2())); break; default: global::dotVariant.GeneratorSupport.Errors.ThrowInternalError("Foo.Variant_public"); @@ -929,16 +950,16 @@ public static partial class Variant_publicEx { foreach (var variant in source) { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant)) + switch (variant.Index) { case 0: yield return _(); break; case 1: - yield return i(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return i(variant.UnsafeGet(new global::dotVariant.Accessor._1())); break; case 2: - yield return s(((global::dotVariant.GeneratorSupport.Accessor_2)variant).Value); + yield return s(variant.UnsafeGet(new global::dotVariant.Accessor._2())); break; default: global::dotVariant.GeneratorSupport.Errors.ThrowInternalError("Foo.Variant_public"); @@ -966,8 +987,8 @@ public static partial class Variant_publicEx global::System.Func i) { return global::System.Reactive.Linq.Observable.Select( - global::System.Reactive.Linq.Observable.Where(source, _variant => ((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 1), - _variant => i(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value)); + global::System.Reactive.Linq.Observable.Where(source, _variant => _variant.Index == 1), + _variant => i(_variant.UnsafeGet(new global::dotVariant.Accessor._1()))); } /// /// Projects each element of an observable sequence @@ -983,8 +1004,8 @@ public static partial class Variant_publicEx global::System.Func s) { return global::System.Reactive.Linq.Observable.Select( - global::System.Reactive.Linq.Observable.Where(source, _variant => ((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 2), - _variant => s(((global::dotVariant.GeneratorSupport.Accessor_2)_variant).Value)); + global::System.Reactive.Linq.Observable.Where(source, _variant => _variant.Index == 2), + _variant => s(_variant.UnsafeGet(new global::dotVariant.Accessor._2()))); } /// @@ -1004,9 +1025,9 @@ public static partial class Variant_publicEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 1) + if (_variant.Index == 1) { - return i(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + return i(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); } else { @@ -1031,9 +1052,9 @@ public static partial class Variant_publicEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 2) + if (_variant.Index == 2) { - return s(((global::dotVariant.GeneratorSupport.Accessor_2)_variant).Value); + return s(_variant.UnsafeGet(new global::dotVariant.Accessor._2())); } else { @@ -1059,9 +1080,9 @@ public static partial class Variant_publicEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 1) + if (_variant.Index == 1) { - return i(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + return i(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); } else { @@ -1086,9 +1107,9 @@ public static partial class Variant_publicEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 2) + if (_variant.Index == 2) { - return s(((global::dotVariant.GeneratorSupport.Accessor_2)_variant).Value); + return s(_variant.UnsafeGet(new global::dotVariant.Accessor._2())); } else { @@ -1113,14 +1134,14 @@ public static partial class Variant_publicEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant)) + switch (_variant.Index) { case 0: return global::dotVariant.GeneratorSupport.Errors.ThrowEmptyError("Foo.Variant_public"); case 1: - return i(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + return i(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); case 2: - return s(((global::dotVariant.GeneratorSupport.Accessor_2)_variant).Value); + return s(_variant.UnsafeGet(new global::dotVariant.Accessor._2())); default: return global::dotVariant.GeneratorSupport.Errors.ThrowInternalError("Foo.Variant_public"); } @@ -1145,14 +1166,14 @@ public static partial class Variant_publicEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant)) + switch (_variant.Index) { case 0: return _(); case 1: - return i(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + return i(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); case 2: - return s(((global::dotVariant.GeneratorSupport.Accessor_2)_variant).Value); + return s(_variant.UnsafeGet(new global::dotVariant.Accessor._2())); default: return global::dotVariant.GeneratorSupport.Errors.ThrowInternalError("Foo.Variant_public"); } @@ -1306,7 +1327,7 @@ public void Dispose() public void OnNext(global::Foo.Variant_public _variant) { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant)) + switch (_variant.Index) { case 0: if (_accept0) @@ -1319,10 +1340,10 @@ public void OnNext(global::Foo.Variant_public _variant) } break; case 1: - Subject1.OnNext(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + Subject1.OnNext(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); break; case 2: - Subject2.OnNext(((global::dotVariant.GeneratorSupport.Accessor_2)_variant).Value); + Subject2.OnNext(_variant.UnsafeGet(new global::dotVariant.Accessor._2())); break; default: OnError(global::dotVariant.GeneratorSupport.Errors.MakeInternalError("Foo.Variant_public")); diff --git a/src/dotVariant.Generator.Test/samples/Variant-struct-nullable-disable.out.cs b/src/dotVariant.Generator.Test/samples/Variant-struct-nullable-disable.out.cs index a01d460..ca72652 100644 --- a/src/dotVariant.Generator.Test/samples/Variant-struct-nullable-disable.out.cs +++ b/src/dotVariant.Generator.Test/samples/Variant-struct-nullable-disable.out.cs @@ -79,6 +79,11 @@ public static Variant_struct_nullable_disable Create(object o) public readonly bool IsEmpty => _variant.IsEmpty; + /// + [global::System.Diagnostics.DebuggerNonUserCode] + public readonly byte Index + => _variant.Index; + /// [global::System.Diagnostics.DebuggerNonUserCode] public readonly override bool Equals(object other) @@ -106,6 +111,11 @@ public readonly override int GetHashCode() public readonly override string ToString() => _variant.ToString(); + /// + [global::System.Diagnostics.DebuggerNonUserCode] + public readonly long UnsafeGet(global::dotVariant.Accessor._1 accessor) + => _variant.UnsafeGet(accessor); + /// [global::System.Diagnostics.DebuggerNonUserCode] public readonly bool TryMatch(out long l) @@ -146,6 +156,11 @@ public readonly TResult Match(global::System.Func l, TRe public readonly TResult Match(global::System.Func l, global::System.Func _) => _variant.Match(l, _); + /// + [global::System.Diagnostics.DebuggerNonUserCode] + public readonly double UnsafeGet(global::dotVariant.Accessor._2 accessor) + => _variant.UnsafeGet(accessor); + /// [global::System.Diagnostics.DebuggerNonUserCode] public readonly bool TryMatch(out double d) @@ -186,6 +201,11 @@ public readonly TResult Match(global::System.Func d, T public readonly TResult Match(global::System.Func d, global::System.Func _) => _variant.Match(d, _); + /// + [global::System.Diagnostics.DebuggerNonUserCode] + public readonly object UnsafeGet(global::dotVariant.Accessor._3 accessor) + => _variant.UnsafeGet(accessor); + /// [global::System.Diagnostics.DebuggerNonUserCode] public readonly bool TryMatch(out object o) @@ -259,23 +279,6 @@ public __DebuggerTypeProxy(Variant_struct_nullable_disable v) #pragma warning restore 8604, 8625 } } - - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - [global::System.Diagnostics.DebuggerNonUserCode] - public static explicit operator global::dotVariant.GeneratorSupport.Discriminator(Variant_struct_nullable_disable v) - => (global::dotVariant.GeneratorSupport.Discriminator)v._variant; - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - [global::System.Diagnostics.DebuggerNonUserCode] - public static explicit operator global::dotVariant.GeneratorSupport.Accessor_1(Variant_struct_nullable_disable v) - => (global::dotVariant.GeneratorSupport.Accessor_1)v._variant; - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - [global::System.Diagnostics.DebuggerNonUserCode] - public static explicit operator global::dotVariant.GeneratorSupport.Accessor_2(Variant_struct_nullable_disable v) - => (global::dotVariant.GeneratorSupport.Accessor_2)v._variant; - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - [global::System.Diagnostics.DebuggerNonUserCode] - public static explicit operator global::dotVariant.GeneratorSupport.Accessor_3(Variant_struct_nullable_disable v) - => (global::dotVariant.GeneratorSupport.Accessor_3)v._variant; } } @@ -311,34 +314,31 @@ public Union(object value) } private readonly Union _x; - private readonly byte _n; + + /// + /// The 1-based index of the currently stored type, + /// counted left-ro-right from the parameter list. + /// 0 if the variant is empty. + /// + public readonly byte Index; public Variant_struct_nullable_disable(long l) { - _n = 1; + Index = 1; _x = new Union(l); } public Variant_struct_nullable_disable(double d) { - _n = 2; + Index = 2; _x = new Union(d); } public Variant_struct_nullable_disable(object o) { - _n = 3; + Index = 3; _x = new Union(o); } - public static explicit operator global::dotVariant.GeneratorSupport.Discriminator(in Variant_struct_nullable_disable v) - => (global::dotVariant.GeneratorSupport.Discriminator)v._n; - public static explicit operator global::dotVariant.GeneratorSupport.Accessor_1(in Variant_struct_nullable_disable v) - => new global::dotVariant.GeneratorSupport.Accessor_1(v._x._1); - public static explicit operator global::dotVariant.GeneratorSupport.Accessor_2(in Variant_struct_nullable_disable v) - => new global::dotVariant.GeneratorSupport.Accessor_2(v._x._2); - public static explicit operator global::dotVariant.GeneratorSupport.Accessor_3(in Variant_struct_nullable_disable v) - => new global::dotVariant.GeneratorSupport.Accessor_3(v._x._3); - /// /// if Variant_struct_nullable_disable was constructed without a value. /// @@ -347,7 +347,7 @@ public Variant_struct_nullable_disable(object o) /// A default-constructed Variant_struct_nullable_disable will always have a IsEmpty value of /// and never satisfy any matching attempts except for the wildcard _ parameter. /// - public bool IsEmpty => _n == 0; + public bool IsEmpty => this.Index == 0; /// /// The string representation of the stored value's type. @@ -356,7 +356,7 @@ public string TypeString { get { - switch (_n) + switch (this.Index) { case 0: return ""; @@ -377,7 +377,7 @@ public string TypeString /// public override string ToString() { - switch (_n) + switch (this.Index) { case 0: return ""; @@ -399,7 +399,7 @@ public object AsObject { get { - switch (_n) + switch (this.Index) { case 0: return null; @@ -417,11 +417,11 @@ public object AsObject public bool Equals(in Variant_struct_nullable_disable other) { - if (_n != other._n) + if (this.Index != other.Index) { return false; } - switch (_n) + switch (Index) { case 0: return true; @@ -438,7 +438,7 @@ public bool Equals(in Variant_struct_nullable_disable other) public override int GetHashCode() { - switch (_n) + switch (this.Index) { case 0: return 0; @@ -453,6 +453,16 @@ public override int GetHashCode() } } + /// + /// Retrieve the stored value assuming it is of type . + /// + /// Only call this if you have ensured that Index == 1, + /// otherwise the correctness of the returned value is not guaranteed, + /// nor that any value is returned at all. + /// + public long UnsafeGet(global::dotVariant.Accessor._1 _) + => _x._1; + /// /// Retrieve the value stored within Variant_struct_nullable_disable if it is of type . /// @@ -460,8 +470,8 @@ public override int GetHashCode() /// if Variant_struct_nullable_disable contained a value of type . public bool TryMatch(out long l) { - l = _n == 1 ? _x._1 : default; - return _n == 1; + l = this.Index == 1 ? _x._1 : default; + return this.Index == 1; } /// @@ -472,7 +482,7 @@ public bool TryMatch(out long l) /// Any exception thrown from is rethrown. public bool TryMatch(global::System.Action l) { - if (_n == 1) + if (this.Index == 1) { l(_x._1); return true; @@ -488,7 +498,7 @@ public bool TryMatch(global::System.Action l) /// Variant_struct_nullable_disable does not contain a value of type . public void Match(out long l) { - if (_n == 1) + if (this.Index == 1) { l = _x._1; return; @@ -505,7 +515,7 @@ public void Match(out long l) /// Any exception thrown from is rethrown. public void Match(global::System.Action l) { - if (_n == 1) + if (this.Index == 1) { l(_x._1); return; @@ -522,7 +532,7 @@ public void Match(global::System.Action l) /// Any exception thrown from or is rethrown. public void Match(global::System.Action l, global::System.Action _) { - if (_n == 1) + if (this.Index == 1) { l(_x._1); } @@ -542,7 +552,7 @@ public void Match(global::System.Action l, global::System.Action _) /// Any exception thrown from is rethrown. public TResult Match(global::System.Func l) { - if (_n == 1) + if (this.Index == 1) { return l(_x._1); } @@ -559,7 +569,7 @@ public TResult Match(global::System.Func l) /// Any exception thrown from or is rethrown. public TResult Match(global::System.Func l, TResult _) { - return _n == 1 ? l(_x._1) : _; + return this.Index == 1 ? l(_x._1) : _; } /// @@ -571,8 +581,18 @@ public TResult Match(global::System.Func l, TResult _) /// Any exception thrown from or is rethrown. public TResult Match(global::System.Func l, global::System.Func _) { - return _n == 1 ? l(_x._1) : _(); + return this.Index == 1 ? l(_x._1) : _(); } + /// + /// Retrieve the stored value assuming it is of type . + /// + /// Only call this if you have ensured that Index == 2, + /// otherwise the correctness of the returned value is not guaranteed, + /// nor that any value is returned at all. + /// + public double UnsafeGet(global::dotVariant.Accessor._2 _) + => _x._2; + /// /// Retrieve the value stored within Variant_struct_nullable_disable if it is of type . /// @@ -580,8 +600,8 @@ public TResult Match(global::System.Func l, global::Syst /// if Variant_struct_nullable_disable contained a value of type . public bool TryMatch(out double d) { - d = _n == 2 ? _x._2 : default; - return _n == 2; + d = this.Index == 2 ? _x._2 : default; + return this.Index == 2; } /// @@ -592,7 +612,7 @@ public bool TryMatch(out double d) /// Any exception thrown from is rethrown. public bool TryMatch(global::System.Action d) { - if (_n == 2) + if (this.Index == 2) { d(_x._2); return true; @@ -608,7 +628,7 @@ public bool TryMatch(global::System.Action d) /// Variant_struct_nullable_disable does not contain a value of type . public void Match(out double d) { - if (_n == 2) + if (this.Index == 2) { d = _x._2; return; @@ -625,7 +645,7 @@ public void Match(out double d) /// Any exception thrown from is rethrown. public void Match(global::System.Action d) { - if (_n == 2) + if (this.Index == 2) { d(_x._2); return; @@ -642,7 +662,7 @@ public void Match(global::System.Action d) /// Any exception thrown from or is rethrown. public void Match(global::System.Action d, global::System.Action _) { - if (_n == 2) + if (this.Index == 2) { d(_x._2); } @@ -662,7 +682,7 @@ public void Match(global::System.Action d, global::System.Action _) /// Any exception thrown from is rethrown. public TResult Match(global::System.Func d) { - if (_n == 2) + if (this.Index == 2) { return d(_x._2); } @@ -679,7 +699,7 @@ public TResult Match(global::System.Func d) /// Any exception thrown from or is rethrown. public TResult Match(global::System.Func d, TResult _) { - return _n == 2 ? d(_x._2) : _; + return this.Index == 2 ? d(_x._2) : _; } /// @@ -691,8 +711,18 @@ public TResult Match(global::System.Func d, TResult _) /// Any exception thrown from or is rethrown. public TResult Match(global::System.Func d, global::System.Func _) { - return _n == 2 ? d(_x._2) : _(); + return this.Index == 2 ? d(_x._2) : _(); } + /// + /// Retrieve the stored value assuming it is of type . + /// + /// Only call this if you have ensured that Index == 3, + /// otherwise the correctness of the returned value is not guaranteed, + /// nor that any value is returned at all. + /// + public object UnsafeGet(global::dotVariant.Accessor._3 _) + => _x._3; + /// /// Retrieve the value stored within Variant_struct_nullable_disable if it is of type . /// @@ -700,8 +730,8 @@ public TResult Match(global::System.Func d, global::Sy /// if Variant_struct_nullable_disable contained a value of type . public bool TryMatch(out object o) { - o = _n == 3 ? _x._3 : default; - return _n == 3; + o = this.Index == 3 ? _x._3 : default; + return this.Index == 3; } /// @@ -712,7 +742,7 @@ public bool TryMatch(out object o) /// Any exception thrown from is rethrown. public bool TryMatch(global::System.Action o) { - if (_n == 3) + if (this.Index == 3) { o(_x._3); return true; @@ -728,7 +758,7 @@ public bool TryMatch(global::System.Action o) /// Variant_struct_nullable_disable does not contain a value of type . public void Match(out object o) { - if (_n == 3) + if (this.Index == 3) { o = _x._3; return; @@ -745,7 +775,7 @@ public void Match(out object o) /// Any exception thrown from is rethrown. public void Match(global::System.Action o) { - if (_n == 3) + if (this.Index == 3) { o(_x._3); return; @@ -762,7 +792,7 @@ public void Match(global::System.Action o) /// Any exception thrown from or is rethrown. public void Match(global::System.Action o, global::System.Action _) { - if (_n == 3) + if (this.Index == 3) { o(_x._3); } @@ -782,7 +812,7 @@ public void Match(global::System.Action o, global::System.Action _) /// Any exception thrown from is rethrown. public TResult Match(global::System.Func o) { - if (_n == 3) + if (this.Index == 3) { return o(_x._3); } @@ -799,7 +829,7 @@ public TResult Match(global::System.Func o) /// Any exception thrown from or is rethrown. public TResult Match(global::System.Func o, TResult _) { - return _n == 3 ? o(_x._3) : _; + return this.Index == 3 ? o(_x._3) : _; } /// @@ -811,7 +841,7 @@ public TResult Match(global::System.Func o, TResult _) /// Any exception thrown from or is rethrown. public TResult Match(global::System.Func o, global::System.Func _) { - return _n == 3 ? o(_x._3) : _(); + return this.Index == 3 ? o(_x._3) : _(); } /// @@ -825,7 +855,7 @@ public TResult Match(global::System.Func o, global::Sy /// Any exception thrown from a delegate is rethrown. public void Visit(global::System.Action l, global::System.Action d, global::System.Action o, global::System.Action _) { - switch (_n) + switch (this.Index) { case 0: _(); @@ -856,7 +886,7 @@ public void Visit(global::System.Action l, global::System.Action d /// Any exception thrown from a delegate is rethrown. public void Visit(global::System.Action l, global::System.Action d, global::System.Action o) { - switch (_n) + switch (this.Index) { case 0: global::dotVariant.GeneratorSupport.Errors.ThrowEmptyError("Foo.Variant_struct_nullable_disable"); @@ -888,7 +918,7 @@ public void Visit(global::System.Action l, global::System.Action d /// The return type of all delegates, and by extension the return type of this function. public TResult Visit(global::System.Func l, global::System.Func d, global::System.Func o, global::System.Func _) { - switch (_n) + switch (this.Index) { case 0: return _(); @@ -915,7 +945,7 @@ public TResult Visit(global::System.Func l, global::Syst /// The return type of all delegates, and by extension the return type of this function. public TResult Visit(global::System.Func l, global::System.Func d, global::System.Func o) { - switch (_n) + switch (this.Index) { case 0: return global::dotVariant.GeneratorSupport.Errors.ThrowEmptyError("Foo.Variant_struct_nullable_disable"); @@ -953,9 +983,9 @@ public static partial class Variant_struct_nullable_disableEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 1) + if (variant.Index == 1) { - yield return l(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return l(variant.UnsafeGet(new global::dotVariant.Accessor._1())); } } } @@ -975,9 +1005,9 @@ public static partial class Variant_struct_nullable_disableEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 2) + if (variant.Index == 2) { - yield return d(((global::dotVariant.GeneratorSupport.Accessor_2)variant).Value); + yield return d(variant.UnsafeGet(new global::dotVariant.Accessor._2())); } } } @@ -997,9 +1027,9 @@ public static partial class Variant_struct_nullable_disableEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 3) + if (variant.Index == 3) { - yield return o(((global::dotVariant.GeneratorSupport.Accessor_3)variant).Value); + yield return o(variant.UnsafeGet(new global::dotVariant.Accessor._3())); } } } @@ -1022,9 +1052,9 @@ public static partial class Variant_struct_nullable_disableEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 1) + if (variant.Index == 1) { - yield return l(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return l(variant.UnsafeGet(new global::dotVariant.Accessor._1())); } else { @@ -1050,9 +1080,9 @@ public static partial class Variant_struct_nullable_disableEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 2) + if (variant.Index == 2) { - yield return d(((global::dotVariant.GeneratorSupport.Accessor_2)variant).Value); + yield return d(variant.UnsafeGet(new global::dotVariant.Accessor._2())); } else { @@ -1078,9 +1108,9 @@ public static partial class Variant_struct_nullable_disableEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 3) + if (variant.Index == 3) { - yield return o(((global::dotVariant.GeneratorSupport.Accessor_3)variant).Value); + yield return o(variant.UnsafeGet(new global::dotVariant.Accessor._3())); } else { @@ -1107,9 +1137,9 @@ public static partial class Variant_struct_nullable_disableEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 1) + if (variant.Index == 1) { - yield return l(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return l(variant.UnsafeGet(new global::dotVariant.Accessor._1())); } else { @@ -1135,9 +1165,9 @@ public static partial class Variant_struct_nullable_disableEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 2) + if (variant.Index == 2) { - yield return d(((global::dotVariant.GeneratorSupport.Accessor_2)variant).Value); + yield return d(variant.UnsafeGet(new global::dotVariant.Accessor._2())); } else { @@ -1163,9 +1193,9 @@ public static partial class Variant_struct_nullable_disableEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 3) + if (variant.Index == 3) { - yield return o(((global::dotVariant.GeneratorSupport.Accessor_3)variant).Value); + yield return o(variant.UnsafeGet(new global::dotVariant.Accessor._3())); } else { @@ -1194,19 +1224,19 @@ public static partial class Variant_struct_nullable_disableEx { foreach (var variant in source) { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant)) + switch (variant.Index) { case 0: global::dotVariant.GeneratorSupport.Errors.ThrowEmptyError("Foo.Variant_struct_nullable_disable"); yield break; case 1: - yield return l(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return l(variant.UnsafeGet(new global::dotVariant.Accessor._1())); break; case 2: - yield return d(((global::dotVariant.GeneratorSupport.Accessor_2)variant).Value); + yield return d(variant.UnsafeGet(new global::dotVariant.Accessor._2())); break; case 3: - yield return o(((global::dotVariant.GeneratorSupport.Accessor_3)variant).Value); + yield return o(variant.UnsafeGet(new global::dotVariant.Accessor._3())); break; default: global::dotVariant.GeneratorSupport.Errors.ThrowInternalError("Foo.Variant_struct_nullable_disable"); @@ -1235,19 +1265,19 @@ public static partial class Variant_struct_nullable_disableEx { foreach (var variant in source) { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant)) + switch (variant.Index) { case 0: yield return _(); break; case 1: - yield return l(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return l(variant.UnsafeGet(new global::dotVariant.Accessor._1())); break; case 2: - yield return d(((global::dotVariant.GeneratorSupport.Accessor_2)variant).Value); + yield return d(variant.UnsafeGet(new global::dotVariant.Accessor._2())); break; case 3: - yield return o(((global::dotVariant.GeneratorSupport.Accessor_3)variant).Value); + yield return o(variant.UnsafeGet(new global::dotVariant.Accessor._3())); break; default: global::dotVariant.GeneratorSupport.Errors.ThrowInternalError("Foo.Variant_struct_nullable_disable"); @@ -1275,8 +1305,8 @@ public static partial class Variant_struct_nullable_disableEx global::System.Func l) { return global::System.Reactive.Linq.Observable.Select( - global::System.Reactive.Linq.Observable.Where(source, _variant => ((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 1), - _variant => l(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value)); + global::System.Reactive.Linq.Observable.Where(source, _variant => _variant.Index == 1), + _variant => l(_variant.UnsafeGet(new global::dotVariant.Accessor._1()))); } /// /// Projects each element of an observable sequence @@ -1292,8 +1322,8 @@ public static partial class Variant_struct_nullable_disableEx global::System.Func d) { return global::System.Reactive.Linq.Observable.Select( - global::System.Reactive.Linq.Observable.Where(source, _variant => ((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 2), - _variant => d(((global::dotVariant.GeneratorSupport.Accessor_2)_variant).Value)); + global::System.Reactive.Linq.Observable.Where(source, _variant => _variant.Index == 2), + _variant => d(_variant.UnsafeGet(new global::dotVariant.Accessor._2()))); } /// /// Projects each element of an observable sequence @@ -1309,8 +1339,8 @@ public static partial class Variant_struct_nullable_disableEx global::System.Func o) { return global::System.Reactive.Linq.Observable.Select( - global::System.Reactive.Linq.Observable.Where(source, _variant => ((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 3), - _variant => o(((global::dotVariant.GeneratorSupport.Accessor_3)_variant).Value)); + global::System.Reactive.Linq.Observable.Where(source, _variant => _variant.Index == 3), + _variant => o(_variant.UnsafeGet(new global::dotVariant.Accessor._3()))); } /// @@ -1330,9 +1360,9 @@ public static partial class Variant_struct_nullable_disableEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 1) + if (_variant.Index == 1) { - return l(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + return l(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); } else { @@ -1357,9 +1387,9 @@ public static partial class Variant_struct_nullable_disableEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 2) + if (_variant.Index == 2) { - return d(((global::dotVariant.GeneratorSupport.Accessor_2)_variant).Value); + return d(_variant.UnsafeGet(new global::dotVariant.Accessor._2())); } else { @@ -1384,9 +1414,9 @@ public static partial class Variant_struct_nullable_disableEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 3) + if (_variant.Index == 3) { - return o(((global::dotVariant.GeneratorSupport.Accessor_3)_variant).Value); + return o(_variant.UnsafeGet(new global::dotVariant.Accessor._3())); } else { @@ -1412,9 +1442,9 @@ public static partial class Variant_struct_nullable_disableEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 1) + if (_variant.Index == 1) { - return l(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + return l(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); } else { @@ -1439,9 +1469,9 @@ public static partial class Variant_struct_nullable_disableEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 2) + if (_variant.Index == 2) { - return d(((global::dotVariant.GeneratorSupport.Accessor_2)_variant).Value); + return d(_variant.UnsafeGet(new global::dotVariant.Accessor._2())); } else { @@ -1466,9 +1496,9 @@ public static partial class Variant_struct_nullable_disableEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 3) + if (_variant.Index == 3) { - return o(((global::dotVariant.GeneratorSupport.Accessor_3)_variant).Value); + return o(_variant.UnsafeGet(new global::dotVariant.Accessor._3())); } else { @@ -1494,16 +1524,16 @@ public static partial class Variant_struct_nullable_disableEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant)) + switch (_variant.Index) { case 0: return global::dotVariant.GeneratorSupport.Errors.ThrowEmptyError("Foo.Variant_struct_nullable_disable"); case 1: - return l(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + return l(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); case 2: - return d(((global::dotVariant.GeneratorSupport.Accessor_2)_variant).Value); + return d(_variant.UnsafeGet(new global::dotVariant.Accessor._2())); case 3: - return o(((global::dotVariant.GeneratorSupport.Accessor_3)_variant).Value); + return o(_variant.UnsafeGet(new global::dotVariant.Accessor._3())); default: return global::dotVariant.GeneratorSupport.Errors.ThrowInternalError("Foo.Variant_struct_nullable_disable"); } @@ -1529,16 +1559,16 @@ public static partial class Variant_struct_nullable_disableEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant)) + switch (_variant.Index) { case 0: return _(); case 1: - return l(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + return l(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); case 2: - return d(((global::dotVariant.GeneratorSupport.Accessor_2)_variant).Value); + return d(_variant.UnsafeGet(new global::dotVariant.Accessor._2())); case 3: - return o(((global::dotVariant.GeneratorSupport.Accessor_3)_variant).Value); + return o(_variant.UnsafeGet(new global::dotVariant.Accessor._3())); default: return global::dotVariant.GeneratorSupport.Errors.ThrowInternalError("Foo.Variant_struct_nullable_disable"); } @@ -1696,7 +1726,7 @@ public void Dispose() public void OnNext(global::Foo.Variant_struct_nullable_disable _variant) { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant)) + switch (_variant.Index) { case 0: if (_accept0) @@ -1709,13 +1739,13 @@ public void OnNext(global::Foo.Variant_struct_nullable_disable _variant) } break; case 1: - Subject1.OnNext(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + Subject1.OnNext(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); break; case 2: - Subject2.OnNext(((global::dotVariant.GeneratorSupport.Accessor_2)_variant).Value); + Subject2.OnNext(_variant.UnsafeGet(new global::dotVariant.Accessor._2())); break; case 3: - Subject3.OnNext(((global::dotVariant.GeneratorSupport.Accessor_3)_variant).Value); + Subject3.OnNext(_variant.UnsafeGet(new global::dotVariant.Accessor._3())); break; default: OnError(global::dotVariant.GeneratorSupport.Errors.MakeInternalError("Foo.Variant_struct_nullable_disable")); diff --git a/src/dotVariant.Generator.Test/samples/Variant-struct-nullable-enable.out.cs b/src/dotVariant.Generator.Test/samples/Variant-struct-nullable-enable.out.cs index 3722f72..d568e8f 100644 --- a/src/dotVariant.Generator.Test/samples/Variant-struct-nullable-enable.out.cs +++ b/src/dotVariant.Generator.Test/samples/Variant-struct-nullable-enable.out.cs @@ -79,6 +79,11 @@ public static Variant_struct_nullable_enable Create(object o) public readonly bool IsEmpty => _variant.IsEmpty; + /// + [global::System.Diagnostics.DebuggerNonUserCode] + public readonly byte Index + => _variant.Index; + /// [global::System.Diagnostics.DebuggerNonUserCode] public readonly override bool Equals(object? other) @@ -106,6 +111,11 @@ public readonly override int GetHashCode() public readonly override string ToString() => _variant.ToString(); + /// + [global::System.Diagnostics.DebuggerNonUserCode] + public readonly long UnsafeGet(global::dotVariant.Accessor._1 accessor) + => _variant.UnsafeGet(accessor); + /// [global::System.Diagnostics.DebuggerNonUserCode] public readonly bool TryMatch([global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out long l) @@ -146,6 +156,11 @@ public readonly TResult Match(global::System.Func l, TRe public readonly TResult Match(global::System.Func l, global::System.Func _) => _variant.Match(l, _); + /// + [global::System.Diagnostics.DebuggerNonUserCode] + public readonly double UnsafeGet(global::dotVariant.Accessor._2 accessor) + => _variant.UnsafeGet(accessor); + /// [global::System.Diagnostics.DebuggerNonUserCode] public readonly bool TryMatch([global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out double d) @@ -186,6 +201,11 @@ public readonly TResult Match(global::System.Func d, T public readonly TResult Match(global::System.Func d, global::System.Func _) => _variant.Match(d, _); + /// + [global::System.Diagnostics.DebuggerNonUserCode] + public readonly object UnsafeGet(global::dotVariant.Accessor._3 accessor) + => _variant.UnsafeGet(accessor); + /// [global::System.Diagnostics.DebuggerNonUserCode] public readonly bool TryMatch([global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out object? o) @@ -259,23 +279,6 @@ public __DebuggerTypeProxy(Variant_struct_nullable_enable v) #pragma warning restore 8604, 8625 } } - - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - [global::System.Diagnostics.DebuggerNonUserCode] - public static explicit operator global::dotVariant.GeneratorSupport.Discriminator(Variant_struct_nullable_enable v) - => (global::dotVariant.GeneratorSupport.Discriminator)v._variant; - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - [global::System.Diagnostics.DebuggerNonUserCode] - public static explicit operator global::dotVariant.GeneratorSupport.Accessor_1(Variant_struct_nullable_enable v) - => (global::dotVariant.GeneratorSupport.Accessor_1)v._variant; - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - [global::System.Diagnostics.DebuggerNonUserCode] - public static explicit operator global::dotVariant.GeneratorSupport.Accessor_2(Variant_struct_nullable_enable v) - => (global::dotVariant.GeneratorSupport.Accessor_2)v._variant; - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - [global::System.Diagnostics.DebuggerNonUserCode] - public static explicit operator global::dotVariant.GeneratorSupport.Accessor_3(Variant_struct_nullable_enable v) - => (global::dotVariant.GeneratorSupport.Accessor_3)v._variant; } } @@ -311,34 +314,31 @@ public Union(object value) } private readonly Union _x; - private readonly byte _n; + + /// + /// The 1-based index of the currently stored type, + /// counted left-ro-right from the parameter list. + /// 0 if the variant is empty. + /// + public readonly byte Index; public Variant_struct_nullable_enable(long l) { - _n = 1; + Index = 1; _x = new Union(l); } public Variant_struct_nullable_enable(double d) { - _n = 2; + Index = 2; _x = new Union(d); } public Variant_struct_nullable_enable(object o) { - _n = 3; + Index = 3; _x = new Union(o); } - public static explicit operator global::dotVariant.GeneratorSupport.Discriminator(in Variant_struct_nullable_enable v) - => (global::dotVariant.GeneratorSupport.Discriminator)v._n; - public static explicit operator global::dotVariant.GeneratorSupport.Accessor_1(in Variant_struct_nullable_enable v) - => new global::dotVariant.GeneratorSupport.Accessor_1(v._x._1); - public static explicit operator global::dotVariant.GeneratorSupport.Accessor_2(in Variant_struct_nullable_enable v) - => new global::dotVariant.GeneratorSupport.Accessor_2(v._x._2); - public static explicit operator global::dotVariant.GeneratorSupport.Accessor_3(in Variant_struct_nullable_enable v) - => new global::dotVariant.GeneratorSupport.Accessor_3(v._x._3); - /// /// if Variant_struct_nullable_enable was constructed without a value. /// @@ -347,7 +347,7 @@ public Variant_struct_nullable_enable(object o) /// A default-constructed Variant_struct_nullable_enable will always have a IsEmpty value of /// and never satisfy any matching attempts except for the wildcard _ parameter. /// - public bool IsEmpty => _n == 0; + public bool IsEmpty => this.Index == 0; /// /// The string representation of the stored value's type. @@ -356,7 +356,7 @@ public string TypeString { get { - switch (_n) + switch (this.Index) { case 0: return ""; @@ -377,7 +377,7 @@ public string TypeString /// public override string ToString() { - switch (_n) + switch (this.Index) { case 0: return ""; @@ -399,7 +399,7 @@ public object? AsObject { get { - switch (_n) + switch (this.Index) { case 0: return null; @@ -417,11 +417,11 @@ public object? AsObject public bool Equals(in Variant_struct_nullable_enable other) { - if (_n != other._n) + if (this.Index != other.Index) { return false; } - switch (_n) + switch (Index) { case 0: return true; @@ -438,7 +438,7 @@ public bool Equals(in Variant_struct_nullable_enable other) public override int GetHashCode() { - switch (_n) + switch (this.Index) { case 0: return 0; @@ -453,6 +453,16 @@ public override int GetHashCode() } } + /// + /// Retrieve the stored value assuming it is of type . + /// + /// Only call this if you have ensured that Index == 1, + /// otherwise the correctness of the returned value is not guaranteed, + /// nor that any value is returned at all. + /// + public long UnsafeGet(global::dotVariant.Accessor._1 _) + => _x._1; + /// /// Retrieve the value stored within Variant_struct_nullable_enable if it is of type . /// @@ -460,8 +470,8 @@ public override int GetHashCode() /// if Variant_struct_nullable_enable contained a value of type . public bool TryMatch([global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out long l) { - l = _n == 1 ? _x._1 : default; - return _n == 1; + l = this.Index == 1 ? _x._1 : default; + return this.Index == 1; } /// @@ -472,7 +482,7 @@ public bool TryMatch([global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] /// Any exception thrown from is rethrown. public bool TryMatch(global::System.Action l) { - if (_n == 1) + if (this.Index == 1) { l(_x._1); return true; @@ -488,7 +498,7 @@ public bool TryMatch(global::System.Action l) /// Variant_struct_nullable_enable does not contain a value of type . public void Match([global::System.Diagnostics.CodeAnalysis.NotNull] out long l) { - if (_n == 1) + if (this.Index == 1) { l = _x._1; return; @@ -505,7 +515,7 @@ public void Match([global::System.Diagnostics.CodeAnalysis.NotNull] out long l) /// Any exception thrown from is rethrown. public void Match(global::System.Action l) { - if (_n == 1) + if (this.Index == 1) { l(_x._1); return; @@ -522,7 +532,7 @@ public void Match(global::System.Action l) /// Any exception thrown from or is rethrown. public void Match(global::System.Action l, global::System.Action _) { - if (_n == 1) + if (this.Index == 1) { l(_x._1); } @@ -542,7 +552,7 @@ public void Match(global::System.Action l, global::System.Action _) /// Any exception thrown from is rethrown. public TResult Match(global::System.Func l) { - if (_n == 1) + if (this.Index == 1) { return l(_x._1); } @@ -559,7 +569,7 @@ public TResult Match(global::System.Func l) /// Any exception thrown from or is rethrown. public TResult Match(global::System.Func l, TResult _) { - return _n == 1 ? l(_x._1) : _; + return this.Index == 1 ? l(_x._1) : _; } /// @@ -571,8 +581,18 @@ public TResult Match(global::System.Func l, TResult _) /// Any exception thrown from or is rethrown. public TResult Match(global::System.Func l, global::System.Func _) { - return _n == 1 ? l(_x._1) : _(); + return this.Index == 1 ? l(_x._1) : _(); } + /// + /// Retrieve the stored value assuming it is of type . + /// + /// Only call this if you have ensured that Index == 2, + /// otherwise the correctness of the returned value is not guaranteed, + /// nor that any value is returned at all. + /// + public double UnsafeGet(global::dotVariant.Accessor._2 _) + => _x._2; + /// /// Retrieve the value stored within Variant_struct_nullable_enable if it is of type . /// @@ -580,8 +600,8 @@ public TResult Match(global::System.Func l, global::Syst /// if Variant_struct_nullable_enable contained a value of type . public bool TryMatch([global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out double d) { - d = _n == 2 ? _x._2 : default; - return _n == 2; + d = this.Index == 2 ? _x._2 : default; + return this.Index == 2; } /// @@ -592,7 +612,7 @@ public bool TryMatch([global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] /// Any exception thrown from is rethrown. public bool TryMatch(global::System.Action d) { - if (_n == 2) + if (this.Index == 2) { d(_x._2); return true; @@ -608,7 +628,7 @@ public bool TryMatch(global::System.Action d) /// Variant_struct_nullable_enable does not contain a value of type . public void Match([global::System.Diagnostics.CodeAnalysis.NotNull] out double d) { - if (_n == 2) + if (this.Index == 2) { d = _x._2; return; @@ -625,7 +645,7 @@ public void Match([global::System.Diagnostics.CodeAnalysis.NotNull] out double d /// Any exception thrown from is rethrown. public void Match(global::System.Action d) { - if (_n == 2) + if (this.Index == 2) { d(_x._2); return; @@ -642,7 +662,7 @@ public void Match(global::System.Action d) /// Any exception thrown from or is rethrown. public void Match(global::System.Action d, global::System.Action _) { - if (_n == 2) + if (this.Index == 2) { d(_x._2); } @@ -662,7 +682,7 @@ public void Match(global::System.Action d, global::System.Action _) /// Any exception thrown from is rethrown. public TResult Match(global::System.Func d) { - if (_n == 2) + if (this.Index == 2) { return d(_x._2); } @@ -679,7 +699,7 @@ public TResult Match(global::System.Func d) /// Any exception thrown from or is rethrown. public TResult Match(global::System.Func d, TResult _) { - return _n == 2 ? d(_x._2) : _; + return this.Index == 2 ? d(_x._2) : _; } /// @@ -691,8 +711,18 @@ public TResult Match(global::System.Func d, TResult _) /// Any exception thrown from or is rethrown. public TResult Match(global::System.Func d, global::System.Func _) { - return _n == 2 ? d(_x._2) : _(); + return this.Index == 2 ? d(_x._2) : _(); } + /// + /// Retrieve the stored value assuming it is of type . + /// + /// Only call this if you have ensured that Index == 3, + /// otherwise the correctness of the returned value is not guaranteed, + /// nor that any value is returned at all. + /// + public object UnsafeGet(global::dotVariant.Accessor._3 _) + => _x._3; + /// /// Retrieve the value stored within Variant_struct_nullable_enable if it is of type . /// @@ -700,8 +730,8 @@ public TResult Match(global::System.Func d, global::Sy /// if Variant_struct_nullable_enable contained a value of type . public bool TryMatch([global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out object? o) { - o = _n == 3 ? _x._3 : default; - return _n == 3; + o = this.Index == 3 ? _x._3 : default; + return this.Index == 3; } /// @@ -712,7 +742,7 @@ public bool TryMatch([global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] /// Any exception thrown from is rethrown. public bool TryMatch(global::System.Action o) { - if (_n == 3) + if (this.Index == 3) { o(_x._3); return true; @@ -728,7 +758,7 @@ public bool TryMatch(global::System.Action o) /// Variant_struct_nullable_enable does not contain a value of type . public void Match([global::System.Diagnostics.CodeAnalysis.NotNull] out object? o) { - if (_n == 3) + if (this.Index == 3) { o = _x._3; return; @@ -745,7 +775,7 @@ public void Match([global::System.Diagnostics.CodeAnalysis.NotNull] out object? /// Any exception thrown from is rethrown. public void Match(global::System.Action o) { - if (_n == 3) + if (this.Index == 3) { o(_x._3); return; @@ -762,7 +792,7 @@ public void Match(global::System.Action o) /// Any exception thrown from or is rethrown. public void Match(global::System.Action o, global::System.Action _) { - if (_n == 3) + if (this.Index == 3) { o(_x._3); } @@ -782,7 +812,7 @@ public void Match(global::System.Action o, global::System.Action _) /// Any exception thrown from is rethrown. public TResult Match(global::System.Func o) { - if (_n == 3) + if (this.Index == 3) { return o(_x._3); } @@ -799,7 +829,7 @@ public TResult Match(global::System.Func o) /// Any exception thrown from or is rethrown. public TResult Match(global::System.Func o, TResult _) { - return _n == 3 ? o(_x._3) : _; + return this.Index == 3 ? o(_x._3) : _; } /// @@ -811,7 +841,7 @@ public TResult Match(global::System.Func o, TResult _) /// Any exception thrown from or is rethrown. public TResult Match(global::System.Func o, global::System.Func _) { - return _n == 3 ? o(_x._3) : _(); + return this.Index == 3 ? o(_x._3) : _(); } /// @@ -825,7 +855,7 @@ public TResult Match(global::System.Func o, global::Sy /// Any exception thrown from a delegate is rethrown. public void Visit(global::System.Action l, global::System.Action d, global::System.Action o, global::System.Action _) { - switch (_n) + switch (this.Index) { case 0: _(); @@ -856,7 +886,7 @@ public void Visit(global::System.Action l, global::System.Action d /// Any exception thrown from a delegate is rethrown. public void Visit(global::System.Action l, global::System.Action d, global::System.Action o) { - switch (_n) + switch (this.Index) { case 0: global::dotVariant.GeneratorSupport.Errors.ThrowEmptyError("Foo.Variant_struct_nullable_enable"); @@ -888,7 +918,7 @@ public void Visit(global::System.Action l, global::System.Action d /// The return type of all delegates, and by extension the return type of this function. public TResult Visit(global::System.Func l, global::System.Func d, global::System.Func o, global::System.Func _) { - switch (_n) + switch (this.Index) { case 0: return _(); @@ -915,7 +945,7 @@ public TResult Visit(global::System.Func l, global::Syst /// The return type of all delegates, and by extension the return type of this function. public TResult Visit(global::System.Func l, global::System.Func d, global::System.Func o) { - switch (_n) + switch (this.Index) { case 0: return global::dotVariant.GeneratorSupport.Errors.ThrowEmptyError("Foo.Variant_struct_nullable_enable"); @@ -953,9 +983,9 @@ public static partial class Variant_struct_nullable_enableEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 1) + if (variant.Index == 1) { - yield return l(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return l(variant.UnsafeGet(new global::dotVariant.Accessor._1())); } } } @@ -975,9 +1005,9 @@ public static partial class Variant_struct_nullable_enableEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 2) + if (variant.Index == 2) { - yield return d(((global::dotVariant.GeneratorSupport.Accessor_2)variant).Value); + yield return d(variant.UnsafeGet(new global::dotVariant.Accessor._2())); } } } @@ -997,9 +1027,9 @@ public static partial class Variant_struct_nullable_enableEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 3) + if (variant.Index == 3) { - yield return o(((global::dotVariant.GeneratorSupport.Accessor_3)variant).Value); + yield return o(variant.UnsafeGet(new global::dotVariant.Accessor._3())); } } } @@ -1022,9 +1052,9 @@ public static partial class Variant_struct_nullable_enableEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 1) + if (variant.Index == 1) { - yield return l(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return l(variant.UnsafeGet(new global::dotVariant.Accessor._1())); } else { @@ -1050,9 +1080,9 @@ public static partial class Variant_struct_nullable_enableEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 2) + if (variant.Index == 2) { - yield return d(((global::dotVariant.GeneratorSupport.Accessor_2)variant).Value); + yield return d(variant.UnsafeGet(new global::dotVariant.Accessor._2())); } else { @@ -1078,9 +1108,9 @@ public static partial class Variant_struct_nullable_enableEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 3) + if (variant.Index == 3) { - yield return o(((global::dotVariant.GeneratorSupport.Accessor_3)variant).Value); + yield return o(variant.UnsafeGet(new global::dotVariant.Accessor._3())); } else { @@ -1107,9 +1137,9 @@ public static partial class Variant_struct_nullable_enableEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 1) + if (variant.Index == 1) { - yield return l(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return l(variant.UnsafeGet(new global::dotVariant.Accessor._1())); } else { @@ -1135,9 +1165,9 @@ public static partial class Variant_struct_nullable_enableEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 2) + if (variant.Index == 2) { - yield return d(((global::dotVariant.GeneratorSupport.Accessor_2)variant).Value); + yield return d(variant.UnsafeGet(new global::dotVariant.Accessor._2())); } else { @@ -1163,9 +1193,9 @@ public static partial class Variant_struct_nullable_enableEx { foreach (var variant in source) { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant) == 3) + if (variant.Index == 3) { - yield return o(((global::dotVariant.GeneratorSupport.Accessor_3)variant).Value); + yield return o(variant.UnsafeGet(new global::dotVariant.Accessor._3())); } else { @@ -1194,19 +1224,19 @@ public static partial class Variant_struct_nullable_enableEx { foreach (var variant in source) { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant)) + switch (variant.Index) { case 0: global::dotVariant.GeneratorSupport.Errors.ThrowEmptyError("Foo.Variant_struct_nullable_enable"); yield break; case 1: - yield return l(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return l(variant.UnsafeGet(new global::dotVariant.Accessor._1())); break; case 2: - yield return d(((global::dotVariant.GeneratorSupport.Accessor_2)variant).Value); + yield return d(variant.UnsafeGet(new global::dotVariant.Accessor._2())); break; case 3: - yield return o(((global::dotVariant.GeneratorSupport.Accessor_3)variant).Value); + yield return o(variant.UnsafeGet(new global::dotVariant.Accessor._3())); break; default: global::dotVariant.GeneratorSupport.Errors.ThrowInternalError("Foo.Variant_struct_nullable_enable"); @@ -1235,19 +1265,19 @@ public static partial class Variant_struct_nullable_enableEx { foreach (var variant in source) { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)variant)) + switch (variant.Index) { case 0: yield return _(); break; case 1: - yield return l(((global::dotVariant.GeneratorSupport.Accessor_1)variant).Value); + yield return l(variant.UnsafeGet(new global::dotVariant.Accessor._1())); break; case 2: - yield return d(((global::dotVariant.GeneratorSupport.Accessor_2)variant).Value); + yield return d(variant.UnsafeGet(new global::dotVariant.Accessor._2())); break; case 3: - yield return o(((global::dotVariant.GeneratorSupport.Accessor_3)variant).Value); + yield return o(variant.UnsafeGet(new global::dotVariant.Accessor._3())); break; default: global::dotVariant.GeneratorSupport.Errors.ThrowInternalError("Foo.Variant_struct_nullable_enable"); @@ -1275,8 +1305,8 @@ public static partial class Variant_struct_nullable_enableEx global::System.Func l) { return global::System.Reactive.Linq.Observable.Select( - global::System.Reactive.Linq.Observable.Where(source, _variant => ((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 1), - _variant => l(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value)); + global::System.Reactive.Linq.Observable.Where(source, _variant => _variant.Index == 1), + _variant => l(_variant.UnsafeGet(new global::dotVariant.Accessor._1()))); } /// /// Projects each element of an observable sequence @@ -1292,8 +1322,8 @@ public static partial class Variant_struct_nullable_enableEx global::System.Func d) { return global::System.Reactive.Linq.Observable.Select( - global::System.Reactive.Linq.Observable.Where(source, _variant => ((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 2), - _variant => d(((global::dotVariant.GeneratorSupport.Accessor_2)_variant).Value)); + global::System.Reactive.Linq.Observable.Where(source, _variant => _variant.Index == 2), + _variant => d(_variant.UnsafeGet(new global::dotVariant.Accessor._2()))); } /// /// Projects each element of an observable sequence @@ -1309,8 +1339,8 @@ public static partial class Variant_struct_nullable_enableEx global::System.Func o) { return global::System.Reactive.Linq.Observable.Select( - global::System.Reactive.Linq.Observable.Where(source, _variant => ((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 3), - _variant => o(((global::dotVariant.GeneratorSupport.Accessor_3)_variant).Value)); + global::System.Reactive.Linq.Observable.Where(source, _variant => _variant.Index == 3), + _variant => o(_variant.UnsafeGet(new global::dotVariant.Accessor._3()))); } /// @@ -1330,9 +1360,9 @@ public static partial class Variant_struct_nullable_enableEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 1) + if (_variant.Index == 1) { - return l(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + return l(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); } else { @@ -1357,9 +1387,9 @@ public static partial class Variant_struct_nullable_enableEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 2) + if (_variant.Index == 2) { - return d(((global::dotVariant.GeneratorSupport.Accessor_2)_variant).Value); + return d(_variant.UnsafeGet(new global::dotVariant.Accessor._2())); } else { @@ -1384,9 +1414,9 @@ public static partial class Variant_struct_nullable_enableEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 3) + if (_variant.Index == 3) { - return o(((global::dotVariant.GeneratorSupport.Accessor_3)_variant).Value); + return o(_variant.UnsafeGet(new global::dotVariant.Accessor._3())); } else { @@ -1412,9 +1442,9 @@ public static partial class Variant_struct_nullable_enableEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 1) + if (_variant.Index == 1) { - return l(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + return l(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); } else { @@ -1439,9 +1469,9 @@ public static partial class Variant_struct_nullable_enableEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 2) + if (_variant.Index == 2) { - return d(((global::dotVariant.GeneratorSupport.Accessor_2)_variant).Value); + return d(_variant.UnsafeGet(new global::dotVariant.Accessor._2())); } else { @@ -1466,9 +1496,9 @@ public static partial class Variant_struct_nullable_enableEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - if (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant) == 3) + if (_variant.Index == 3) { - return o(((global::dotVariant.GeneratorSupport.Accessor_3)_variant).Value); + return o(_variant.UnsafeGet(new global::dotVariant.Accessor._3())); } else { @@ -1494,16 +1524,16 @@ public static partial class Variant_struct_nullable_enableEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant)) + switch (_variant.Index) { case 0: return global::dotVariant.GeneratorSupport.Errors.ThrowEmptyError("Foo.Variant_struct_nullable_enable"); case 1: - return l(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + return l(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); case 2: - return d(((global::dotVariant.GeneratorSupport.Accessor_2)_variant).Value); + return d(_variant.UnsafeGet(new global::dotVariant.Accessor._2())); case 3: - return o(((global::dotVariant.GeneratorSupport.Accessor_3)_variant).Value); + return o(_variant.UnsafeGet(new global::dotVariant.Accessor._3())); default: return global::dotVariant.GeneratorSupport.Errors.ThrowInternalError("Foo.Variant_struct_nullable_enable"); } @@ -1529,16 +1559,16 @@ public static partial class Variant_struct_nullable_enableEx { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant)) + switch (_variant.Index) { case 0: return _(); case 1: - return l(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + return l(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); case 2: - return d(((global::dotVariant.GeneratorSupport.Accessor_2)_variant).Value); + return d(_variant.UnsafeGet(new global::dotVariant.Accessor._2())); case 3: - return o(((global::dotVariant.GeneratorSupport.Accessor_3)_variant).Value); + return o(_variant.UnsafeGet(new global::dotVariant.Accessor._3())); default: return global::dotVariant.GeneratorSupport.Errors.ThrowInternalError("Foo.Variant_struct_nullable_enable"); } @@ -1696,7 +1726,7 @@ public void Dispose() public void OnNext(global::Foo.Variant_struct_nullable_enable _variant) { - switch (((int)(global::dotVariant.GeneratorSupport.Discriminator)_variant)) + switch (_variant.Index) { case 0: if (_accept0) @@ -1709,13 +1739,13 @@ public void OnNext(global::Foo.Variant_struct_nullable_enable _variant) } break; case 1: - Subject1.OnNext(((global::dotVariant.GeneratorSupport.Accessor_1)_variant).Value); + Subject1.OnNext(_variant.UnsafeGet(new global::dotVariant.Accessor._1())); break; case 2: - Subject2.OnNext(((global::dotVariant.GeneratorSupport.Accessor_2)_variant).Value); + Subject2.OnNext(_variant.UnsafeGet(new global::dotVariant.Accessor._2())); break; case 3: - Subject3.OnNext(((global::dotVariant.GeneratorSupport.Accessor_3)_variant).Value); + Subject3.OnNext(_variant.UnsafeGet(new global::dotVariant.Accessor._3())); break; default: OnError(global::dotVariant.GeneratorSupport.Errors.MakeInternalError("Foo.Variant_struct_nullable_enable")); diff --git a/src/dotVariant.Generator/templates/IObservable.scriban-cs b/src/dotVariant.Generator/templates/IObservable.scriban-cs index b26704b..55f82f5 100644 --- a/src/dotVariant.Generator/templates/IObservable.scriban-cs +++ b/src/dotVariant.Generator/templates/IObservable.scriban-cs @@ -3,6 +3,14 @@ # Distributed under the Boost Software License, Version 1.0. # (See accompanying file LICENSE.txt or copy at https://www.boost.org/LICENSE_1_0.txt) ~}} +{{~ +func $get_n() + ret get_n "_variant" +end +func $get_value(param) + ret get_value param "_variant" +end +~}} {{~ if Options.ExtensionClassNamespace ~}} namespace {{ Options.ExtensionClassNamespace }} { @@ -28,8 +36,8 @@ namespace {{ Options.ExtensionClassNamespace }} {{~ end ~}} { return global::System.Reactive.Linq.Observable.Select( - global::System.Reactive.Linq.Observable.Where(source, _variant => {{ get_n }} == {{ $p.Index }}), - _variant => {{ $p.Identifier }}({{ get_value $p }})); + global::System.Reactive.Linq.Observable.Where(source, _variant => {{ $get_n }} == {{ $p.Index }}), + _variant => {{ $p.Identifier }}({{ $get_value $p }})); } {{~ end ~}} @@ -55,9 +63,9 @@ namespace {{ Options.ExtensionClassNamespace }} { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - if ({{ get_n }} == {{ $p.Index }}) + if ({{ $get_n }} == {{ $p.Index }}) { - return {{ $p.Identifier }}({{ get_value $p }}); + return {{ $p.Identifier }}({{ $get_value $p }}); } else { @@ -89,9 +97,9 @@ namespace {{ Options.ExtensionClassNamespace }} { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - if ({{ get_n }} == {{ $p.Index }}) + if ({{ $get_n }} == {{ $p.Index }}) { - return {{ $p.Identifier }}({{ get_value $p }}); + return {{ $p.Identifier }}({{ $get_value $p }}); } else { @@ -122,13 +130,13 @@ namespace {{ Options.ExtensionClassNamespace }} { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - switch ({{ get_n }}) + switch ({{ $get_n }}) { case 0: return {{ throw_empty_error "TResult" }}; {{~ for $p in Params ~}} case {{ $p.Index }}: - return {{ $p.Identifier }}({{ get_value $p }}); + return {{ $p.Identifier }}({{ $get_value $p }}); {{~ end ~}} default: return {{ throw_internal_error "TResult" }}; @@ -159,13 +167,13 @@ namespace {{ Options.ExtensionClassNamespace }} { return global::System.Reactive.Linq.Observable.Select(source, _variant => { - switch ({{ get_n }}) + switch ({{ $get_n }}) { case 0: return _(); {{~ for $p in Params ~}} case {{ $p.Index }}: - return {{ $p.Identifier }}({{ get_value $p }}); + return {{ $p.Identifier }}({{ $get_value $p }}); {{~ end ~}} default: return {{ throw_internal_error "TResult" }}; @@ -345,7 +353,7 @@ namespace {{ Options.ExtensionClassNamespace }} public void OnNext({{ Variant.QualifiedType }} _variant) { - switch ({{ get_n }}) + switch ({{ $get_n }}) { case 0: if (_accept0) @@ -359,7 +367,7 @@ namespace {{ Options.ExtensionClassNamespace }} break; {{~ for $p in Params ~}} case {{ $p.Index }}: - Subject{{ $p.Index }}.OnNext({{ get_value $p }}); + Subject{{ $p.Index }}.OnNext({{ $get_value $p }}); break; {{~ end ~}} default: diff --git a/src/dotVariant.Generator/templates/Union.scriban-cs b/src/dotVariant.Generator/templates/Union.scriban-cs index 39b1a96..2b6f40b 100644 --- a/src/dotVariant.Generator/templates/Union.scriban-cs +++ b/src/dotVariant.Generator/templates/Union.scriban-cs @@ -114,6 +114,9 @@ for value types and still consumes *much* less memory than if it had to store all values side-by-side. ## ~}} {{~ +func $get_n() + ret get_n "this" +end func $storage(param) #ret is_generic ? "_x._" + param.Index : "_x._" + param.Index + ".Value"; ret "_x._" + param.Index; @@ -192,13 +195,19 @@ namespace dotVariant._G{{ if Variant.Namespace; "." + Variant.Namespace; end }} {{~ end ~}} private readonly Union _x; - private readonly byte _n; + + /// + /// The 1-based index of the currently stored type, + /// counted left-ro-right from the parameter list. + /// 0 if the variant is empty. + /// + public readonly byte Index; {{~ ## STORAGE CONSTRUCTORS ## ~}} {{~ for $p in Params ~}} public {{ Variant.Identifier }}({{ $p.Type }} {{ $p.Identifier }}) { - _n = {{ $p.Index }}; + Index = {{ $p.Index }}; _x = new Union({{ $p.Identifier }}); } {{~ end ~}} @@ -210,7 +219,7 @@ namespace dotVariant._G{{ if Variant.Namespace; "." + Variant.Namespace; end }} /// public void Dispose() { - switch (_n) + switch ({{ $get_n }}) { case 0: break; @@ -228,14 +237,6 @@ namespace dotVariant._G{{ if Variant.Namespace; "." + Variant.Namespace; end }} } {{~ end ~}} - {{~ ## INTERNAL ACCESS ## ~}} - public static explicit operator {{ discriminator }}(in {{ Variant.Type }} v) - => ({{ discriminator }})v._n; - {{~ for $p in Params ~}} - public static explicit operator {{ accessor $p.Index $p.Type }}(in {{ Variant.Type }} v) - => new {{ accessor $p.Index $p.Type }}(v.{{ $storage $p }}); - {{~ end ~}} - /// /// if {{ Variant.Name }} was constructed without a value. /// @@ -246,7 +247,7 @@ namespace dotVariant._G{{ if Variant.Namespace; "." + Variant.Namespace; end }} /// and never satisfy any matching attempts except for the wildcard _ parameter. /// {{~ end ~}} - public bool IsEmpty => _n == 0; + public bool IsEmpty => {{ $get_n }} == 0; /// /// The string representation of the stored value's type. @@ -255,7 +256,7 @@ namespace dotVariant._G{{ if Variant.Namespace; "." + Variant.Namespace; end }} { get { - switch (_n) + switch ({{ $get_n }}) { case 0: return ""; @@ -274,7 +275,7 @@ namespace dotVariant._G{{ if Variant.Namespace; "." + Variant.Namespace; end }} /// public override string ToString() { - switch (_n) + switch ({{ $get_n }}) { case 0: return ""; @@ -294,7 +295,7 @@ namespace dotVariant._G{{ if Variant.Namespace; "." + Variant.Namespace; end }} { get { - switch (_n) + switch ({{ $get_n }}) { case 0: return null; @@ -310,11 +311,11 @@ namespace dotVariant._G{{ if Variant.Namespace; "." + Variant.Namespace; end }} public bool Equals(in {{ Variant.Type }} other) { - if (_n != other._n) + if ({{ $get_n }} != {{ get_n "other" }}) { return false; } - switch (_n) + switch (Index) { case 0: return true; @@ -330,7 +331,7 @@ namespace dotVariant._G{{ if Variant.Namespace; "." + Variant.Namespace; end }} public override int GetHashCode() { - switch (_n) + switch ({{ $get_n }}) { case 0: return 0; @@ -349,6 +350,16 @@ namespace dotVariant._G{{ if Variant.Namespace; "." + Variant.Namespace; end }} } {{~ for $p in Params ~}} + /// + /// Retrieve the stored value assuming it is of type . + /// + /// Only call this if you have ensured that Index == {{ $p.Index }}, + /// otherwise the correctness of the returned value is not guaranteed, + /// nor that any value is returned at all. + /// + public {{ $p.Type }} UnsafeGet({{ accessor $p }} _) + => {{ $storage $p }}; + {{~ ## UNION TryMatch ## ~}} /// /// Retrieve the value stored within {{ Variant.Name }} if it is of type . @@ -357,8 +368,8 @@ namespace dotVariant._G{{ if Variant.Namespace; "." + Variant.Namespace; end }} /// if {{ Variant.Name }} contained a value of type . public bool TryMatch({{ annotate_NotNullWhen $p }}out {{ $p.OutType }} {{ $p.Identifier }}) { - {{ $p.Identifier }} = _n == {{ $p.Index }} ? {{ $storage $p }} : default; - return _n == {{ $p.Index }}; + {{ $p.Identifier }} = {{ $get_n }} == {{ $p.Index }} ? {{ $storage $p }} : default; + return {{ $get_n }} == {{ $p.Index }}; } /// @@ -369,7 +380,7 @@ namespace dotVariant._G{{ if Variant.Namespace; "." + Variant.Namespace; end }} /// Any exception thrown from is rethrown. public bool TryMatch({{ action_type $p }} {{ $p.Identifier }}) { - if (_n == {{ $p.Index }}) + if ({{ $get_n }} == {{ $p.Index }}) { {{ $p.Identifier }}({{ $storage $p }}); return true; @@ -386,7 +397,7 @@ namespace dotVariant._G{{ if Variant.Namespace; "." + Variant.Namespace; end }} /// {{ Variant.Name }} does not contain a value of type . public void Match({{ annotate_NotNull $p }}out {{ $p.OutType }} {{ $p.Identifier }}) { - if (_n == {{ $p.Index }}) + if ({{ $get_n }} == {{ $p.Index }}) { {{ $p.Identifier }} = {{ $storage $p }}; return; @@ -403,7 +414,7 @@ namespace dotVariant._G{{ if Variant.Namespace; "." + Variant.Namespace; end }} /// Any exception thrown from is rethrown. public void Match({{ action_type $p }} {{ $p.Identifier }}) { - if (_n == {{ $p.Index }}) + if ({{ $get_n }} == {{ $p.Index }}) { {{ $p.Identifier }}({{ $storage $p }}); return; @@ -420,7 +431,7 @@ namespace dotVariant._G{{ if Variant.Namespace; "." + Variant.Namespace; end }} /// Any exception thrown from or is rethrown. public void Match({{ action_type $p }} {{ $p.Identifier }}, global::System.Action _) { - if (_n == {{ $p.Index }}) + if ({{ $get_n }} == {{ $p.Index }}) { {{ $p.Identifier }}({{ $storage $p }}); } @@ -440,7 +451,7 @@ namespace dotVariant._G{{ if Variant.Namespace; "." + Variant.Namespace; end }} /// Any exception thrown from is rethrown. public TResult Match({{ func_type $p }} {{ $p.Identifier }}) { - if (_n == {{ $p.Index }}) + if ({{ $get_n }} == {{ $p.Index }}) { return {{ $p.Identifier }}({{ $storage $p }}); } @@ -457,7 +468,7 @@ namespace dotVariant._G{{ if Variant.Namespace; "." + Variant.Namespace; end }} /// Any exception thrown from or is rethrown. public TResult Match({{ func_type $p }} {{ $p.Identifier }}, TResult _) { - return _n == {{ $p.Index }} ? {{ $p.Identifier }}({{ $storage $p }}) : _; + return {{ $get_n }} == {{ $p.Index }} ? {{ $p.Identifier }}({{ $storage $p }}) : _; } /// @@ -469,7 +480,7 @@ namespace dotVariant._G{{ if Variant.Namespace; "." + Variant.Namespace; end }} /// Any exception thrown from or is rethrown. public TResult Match({{ func_type $p }} {{ $p.Identifier }}, global::System.Func _) { - return _n == {{ $p.Index }} ? {{ $p.Identifier }}({{ $storage $p }}) : _(); + return {{ $get_n }} == {{ $p.Index }} ? {{ $p.Identifier }}({{ $storage $p }}) : _(); } {{~ end ~}} @@ -485,7 +496,7 @@ namespace dotVariant._G{{ if Variant.Namespace; "." + Variant.Namespace; end }} /// Any exception thrown from a delegate is rethrown. public void Visit({{ action_params }}, global::System.Action _) { - switch (_n) + switch ({{ $get_n }}) { case 0: _(); @@ -513,7 +524,7 @@ namespace dotVariant._G{{ if Variant.Namespace; "." + Variant.Namespace; end }} /// Any exception thrown from a delegate is rethrown. public void Visit({{ action_params }}) { - switch (_n) + switch ({{ $get_n }}) { case 0: {{ throw_empty_error }}; @@ -542,7 +553,7 @@ namespace dotVariant._G{{ if Variant.Namespace; "." + Variant.Namespace; end }} /// The return type of all delegates, and by extension the return type of this function. public TResult Visit({{ func_params }}, global::System.Func _) { - switch (_n) + switch ({{ $get_n }}) { case 0: return _(); @@ -568,7 +579,7 @@ namespace dotVariant._G{{ if Variant.Namespace; "." + Variant.Namespace; end }} /// The return type of all delegates, and by extension the return type of this function. public TResult Visit({{ func_params }}) { - switch (_n) + switch ({{ $get_n }}) { case 0: return {{ throw_empty_error "TResult" }}; diff --git a/src/dotVariant.Generator/templates/Variant.scriban-cs b/src/dotVariant.Generator/templates/Variant.scriban-cs index 357fcce..6eee58d 100644 --- a/src/dotVariant.Generator/templates/Variant.scriban-cs +++ b/src/dotVariant.Generator/templates/Variant.scriban-cs @@ -80,6 +80,11 @@ namespace {{ Variant.Namespace }} public {{ method_modifiers }}bool IsEmpty => _variant.IsEmpty; + /// + [global::System.Diagnostics.DebuggerNonUserCode] + public {{ method_modifiers }}byte Index + => _variant.Index; + {{~ ## VARIANT Equals ## ~}} /// [global::System.Diagnostics.DebuggerNonUserCode] @@ -111,6 +116,12 @@ namespace {{ Variant.Namespace }} => _variant.ToString(); {{~ for $p in Params ~}} + {{~ ## VARIANT UnsafeGet ## ~}} + /// + [global::System.Diagnostics.DebuggerNonUserCode] + public {{ method_modifiers }}{{ $p.Type }} UnsafeGet({{ accessor $p }} accessor) + => _variant.UnsafeGet(accessor); + {{~ ## VARIANT TryMatch ## ~}} /// [global::System.Diagnostics.DebuggerNonUserCode] @@ -189,18 +200,6 @@ namespace {{ Variant.Namespace }} #pragma warning restore 8604, 8625 } } - - {{~ ## INTERNAL ACCESS ## ~}} - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - [global::System.Diagnostics.DebuggerNonUserCode] - public static explicit operator {{ discriminator }}({{ Variant.Type }} v) - => ({{ discriminator }})v._variant; - {{~ for $p in Params ~}} - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - [global::System.Diagnostics.DebuggerNonUserCode] - public static explicit operator {{ accessor $p.Index $p.Type }}({{ Variant.Type }} v) - => ({{ accessor $p.Index $p.Type }})v._variant; - {{~ end ~}} } {{~ if Variant.Namespace ~}} } diff --git a/src/dotVariant.Generator/templates/globals.scriban-cs b/src/dotVariant.Generator/templates/globals.scriban-cs index 569b24f..b1b57a3 100644 --- a/src/dotVariant.Generator/templates/globals.scriban-cs +++ b/src/dotVariant.Generator/templates/globals.scriban-cs @@ -102,13 +102,18 @@ readonly make_empty_error_error storage_type = "global::dotVariant._G." + (Variant.Namespace ? Variant.Namespace + "." : "") + Variant.Type readonly storage_type -func get_value(param, expression = "_variant") - ret "((global::dotVariant.GeneratorSupport.Accessor_" + param.Index + "<" + param.Type + ">)" + expression + ").Value" +func accessor(param) + ret "global::dotVariant.Accessor._" + param.Index +end +readonly accessor + +func get_value(param, expression) + ret expression + ".UnsafeGet(new global::dotVariant.Accessor._" + param.Index + "())" end readonly get_value -func get_n(expression = "_variant") - ret "((int)(global::dotVariant.GeneratorSupport.Discriminator)" + expression + ")" +func get_n(expression) + ret expression + ".Index" end readonly get_n @@ -117,11 +122,6 @@ func cref(name) end readonly cref -func accessor(index, type) - ret "global::dotVariant.GeneratorSupport.Accessor_" + index + "<" + type + ">" -end -readonly accessor - func_types = Params | array.each @(do; ret func_type $0; end) | array.join ", " func_params = Params | array.each @(do; ret (func_type $0) + " " + $0.Identifier; end) | array.join ", " action_types = Params | array.each @(do; ret action_type $0; end) | array.join ", " @@ -132,8 +132,6 @@ global_nullable = emit_nullability ? "?" : "" global_forgive = emit_nullability ? "!" : "" needs_dispose = (Params | array.filter @(do; ret $0.IsDisposable; end) | array.size) > 0 forward_params = Params | array.each @(do; ret $0.Identifier; end) | array.join ", " -discriminator = "global::dotVariant.GeneratorSupport.Discriminator" -object_accessor = "global::dotVariant.GeneratorSupport.ObjectAccessor" is_generic = Variant.Generics != empty readonly func_types diff --git a/src/dotVariant.Runtime/Accessor.cs b/src/dotVariant.Runtime/Accessor.cs new file mode 100644 index 0000000..7bc9640 --- /dev/null +++ b/src/dotVariant.Runtime/Accessor.cs @@ -0,0 +1,270 @@ +// +// Copyright Miro Knejp 2021. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.txt or copy at https://www.boost.org/LICENSE_1_0.txt) +// + +namespace dotVariant +{ + /// + /// Overload selectors for GetUnsafe() direct access. + /// + public static class Accessor + { + public readonly struct _1 { public static readonly _1 Default; } + public readonly struct _2 { public static readonly _2 Default; } + public readonly struct _3 { public static readonly _3 Default; } + public readonly struct _4 { public static readonly _4 Default; } + public readonly struct _5 { public static readonly _5 Default; } + public readonly struct _6 { public static readonly _6 Default; } + public readonly struct _7 { public static readonly _7 Default; } + public readonly struct _8 { public static readonly _8 Default; } + public readonly struct _9 { public static readonly _9 Default; } + public readonly struct _10 { public static readonly _10 Default; } + public readonly struct _11 { public static readonly _11 Default; } + public readonly struct _12 { public static readonly _12 Default; } + public readonly struct _13 { public static readonly _13 Default; } + public readonly struct _14 { public static readonly _14 Default; } + public readonly struct _15 { public static readonly _15 Default; } + public readonly struct _16 { public static readonly _16 Default; } + public readonly struct _17 { public static readonly _17 Default; } + public readonly struct _18 { public static readonly _18 Default; } + public readonly struct _19 { public static readonly _19 Default; } + public readonly struct _20 { public static readonly _20 Default; } + public readonly struct _21 { public static readonly _21 Default; } + public readonly struct _22 { public static readonly _22 Default; } + public readonly struct _23 { public static readonly _23 Default; } + public readonly struct _24 { public static readonly _24 Default; } + public readonly struct _25 { public static readonly _25 Default; } + public readonly struct _26 { public static readonly _26 Default; } + public readonly struct _27 { public static readonly _27 Default; } + public readonly struct _28 { public static readonly _28 Default; } + public readonly struct _29 { public static readonly _29 Default; } + public readonly struct _30 { public static readonly _30 Default; } + public readonly struct _31 { public static readonly _31 Default; } + public readonly struct _32 { public static readonly _32 Default; } + public readonly struct _33 { public static readonly _33 Default; } + public readonly struct _34 { public static readonly _34 Default; } + public readonly struct _35 { public static readonly _35 Default; } + public readonly struct _36 { public static readonly _36 Default; } + public readonly struct _37 { public static readonly _37 Default; } + public readonly struct _38 { public static readonly _38 Default; } + public readonly struct _39 { public static readonly _39 Default; } + public readonly struct _40 { public static readonly _40 Default; } + public readonly struct _41 { public static readonly _41 Default; } + public readonly struct _42 { public static readonly _42 Default; } + public readonly struct _43 { public static readonly _43 Default; } + public readonly struct _44 { public static readonly _44 Default; } + public readonly struct _45 { public static readonly _45 Default; } + public readonly struct _46 { public static readonly _46 Default; } + public readonly struct _47 { public static readonly _47 Default; } + public readonly struct _48 { public static readonly _48 Default; } + public readonly struct _49 { public static readonly _49 Default; } + public readonly struct _50 { public static readonly _50 Default; } + public readonly struct _51 { public static readonly _51 Default; } + public readonly struct _52 { public static readonly _52 Default; } + public readonly struct _53 { public static readonly _53 Default; } + public readonly struct _54 { public static readonly _54 Default; } + public readonly struct _55 { public static readonly _55 Default; } + public readonly struct _56 { public static readonly _56 Default; } + public readonly struct _57 { public static readonly _57 Default; } + public readonly struct _58 { public static readonly _58 Default; } + public readonly struct _59 { public static readonly _59 Default; } + public readonly struct _60 { public static readonly _60 Default; } + public readonly struct _61 { public static readonly _61 Default; } + public readonly struct _62 { public static readonly _62 Default; } + public readonly struct _63 { public static readonly _63 Default; } + public readonly struct _64 { public static readonly _64 Default; } + public readonly struct _65 { public static readonly _65 Default; } + public readonly struct _66 { public static readonly _66 Default; } + public readonly struct _67 { public static readonly _67 Default; } + public readonly struct _68 { public static readonly _68 Default; } + public readonly struct _69 { public static readonly _69 Default; } + public readonly struct _70 { public static readonly _70 Default; } + public readonly struct _71 { public static readonly _71 Default; } + public readonly struct _72 { public static readonly _72 Default; } + public readonly struct _73 { public static readonly _73 Default; } + public readonly struct _74 { public static readonly _74 Default; } + public readonly struct _75 { public static readonly _75 Default; } + public readonly struct _76 { public static readonly _76 Default; } + public readonly struct _77 { public static readonly _77 Default; } + public readonly struct _78 { public static readonly _78 Default; } + public readonly struct _79 { public static readonly _79 Default; } + public readonly struct _80 { public static readonly _80 Default; } + public readonly struct _81 { public static readonly _81 Default; } + public readonly struct _82 { public static readonly _82 Default; } + public readonly struct _83 { public static readonly _83 Default; } + public readonly struct _84 { public static readonly _84 Default; } + public readonly struct _85 { public static readonly _85 Default; } + public readonly struct _86 { public static readonly _86 Default; } + public readonly struct _87 { public static readonly _87 Default; } + public readonly struct _88 { public static readonly _88 Default; } + public readonly struct _89 { public static readonly _89 Default; } + public readonly struct _90 { public static readonly _90 Default; } + public readonly struct _91 { public static readonly _91 Default; } + public readonly struct _92 { public static readonly _92 Default; } + public readonly struct _93 { public static readonly _93 Default; } + public readonly struct _94 { public static readonly _94 Default; } + public readonly struct _95 { public static readonly _95 Default; } + public readonly struct _96 { public static readonly _96 Default; } + public readonly struct _97 { public static readonly _97 Default; } + public readonly struct _98 { public static readonly _98 Default; } + public readonly struct _99 { public static readonly _99 Default; } + public readonly struct _100 { public static readonly _100 Default; } + public readonly struct _101 { public static readonly _101 Default; } + public readonly struct _102 { public static readonly _102 Default; } + public readonly struct _103 { public static readonly _103 Default; } + public readonly struct _104 { public static readonly _104 Default; } + public readonly struct _105 { public static readonly _105 Default; } + public readonly struct _106 { public static readonly _106 Default; } + public readonly struct _107 { public static readonly _107 Default; } + public readonly struct _108 { public static readonly _108 Default; } + public readonly struct _109 { public static readonly _109 Default; } + public readonly struct _110 { public static readonly _110 Default; } + public readonly struct _111 { public static readonly _111 Default; } + public readonly struct _112 { public static readonly _112 Default; } + public readonly struct _113 { public static readonly _113 Default; } + public readonly struct _114 { public static readonly _114 Default; } + public readonly struct _115 { public static readonly _115 Default; } + public readonly struct _116 { public static readonly _116 Default; } + public readonly struct _117 { public static readonly _117 Default; } + public readonly struct _118 { public static readonly _118 Default; } + public readonly struct _119 { public static readonly _119 Default; } + public readonly struct _120 { public static readonly _120 Default; } + public readonly struct _121 { public static readonly _121 Default; } + public readonly struct _122 { public static readonly _122 Default; } + public readonly struct _123 { public static readonly _123 Default; } + public readonly struct _124 { public static readonly _124 Default; } + public readonly struct _125 { public static readonly _125 Default; } + public readonly struct _126 { public static readonly _126 Default; } + public readonly struct _127 { public static readonly _127 Default; } + public readonly struct _128 { public static readonly _128 Default; } + public readonly struct _129 { public static readonly _129 Default; } + public readonly struct _130 { public static readonly _130 Default; } + public readonly struct _131 { public static readonly _131 Default; } + public readonly struct _132 { public static readonly _132 Default; } + public readonly struct _133 { public static readonly _133 Default; } + public readonly struct _134 { public static readonly _134 Default; } + public readonly struct _135 { public static readonly _135 Default; } + public readonly struct _136 { public static readonly _136 Default; } + public readonly struct _137 { public static readonly _137 Default; } + public readonly struct _138 { public static readonly _138 Default; } + public readonly struct _139 { public static readonly _139 Default; } + public readonly struct _140 { public static readonly _140 Default; } + public readonly struct _141 { public static readonly _141 Default; } + public readonly struct _142 { public static readonly _142 Default; } + public readonly struct _143 { public static readonly _143 Default; } + public readonly struct _144 { public static readonly _144 Default; } + public readonly struct _145 { public static readonly _145 Default; } + public readonly struct _146 { public static readonly _146 Default; } + public readonly struct _147 { public static readonly _147 Default; } + public readonly struct _148 { public static readonly _148 Default; } + public readonly struct _149 { public static readonly _149 Default; } + public readonly struct _150 { public static readonly _150 Default; } + public readonly struct _151 { public static readonly _151 Default; } + public readonly struct _152 { public static readonly _152 Default; } + public readonly struct _153 { public static readonly _153 Default; } + public readonly struct _154 { public static readonly _154 Default; } + public readonly struct _155 { public static readonly _155 Default; } + public readonly struct _156 { public static readonly _156 Default; } + public readonly struct _157 { public static readonly _157 Default; } + public readonly struct _158 { public static readonly _158 Default; } + public readonly struct _159 { public static readonly _159 Default; } + public readonly struct _160 { public static readonly _160 Default; } + public readonly struct _161 { public static readonly _161 Default; } + public readonly struct _162 { public static readonly _162 Default; } + public readonly struct _163 { public static readonly _163 Default; } + public readonly struct _164 { public static readonly _164 Default; } + public readonly struct _165 { public static readonly _165 Default; } + public readonly struct _166 { public static readonly _166 Default; } + public readonly struct _167 { public static readonly _167 Default; } + public readonly struct _168 { public static readonly _168 Default; } + public readonly struct _169 { public static readonly _169 Default; } + public readonly struct _170 { public static readonly _170 Default; } + public readonly struct _171 { public static readonly _171 Default; } + public readonly struct _172 { public static readonly _172 Default; } + public readonly struct _173 { public static readonly _173 Default; } + public readonly struct _174 { public static readonly _174 Default; } + public readonly struct _175 { public static readonly _175 Default; } + public readonly struct _176 { public static readonly _176 Default; } + public readonly struct _177 { public static readonly _177 Default; } + public readonly struct _178 { public static readonly _178 Default; } + public readonly struct _179 { public static readonly _179 Default; } + public readonly struct _180 { public static readonly _180 Default; } + public readonly struct _181 { public static readonly _181 Default; } + public readonly struct _182 { public static readonly _182 Default; } + public readonly struct _183 { public static readonly _183 Default; } + public readonly struct _184 { public static readonly _184 Default; } + public readonly struct _185 { public static readonly _185 Default; } + public readonly struct _186 { public static readonly _186 Default; } + public readonly struct _187 { public static readonly _187 Default; } + public readonly struct _188 { public static readonly _188 Default; } + public readonly struct _189 { public static readonly _189 Default; } + public readonly struct _190 { public static readonly _190 Default; } + public readonly struct _191 { public static readonly _191 Default; } + public readonly struct _192 { public static readonly _192 Default; } + public readonly struct _193 { public static readonly _193 Default; } + public readonly struct _194 { public static readonly _194 Default; } + public readonly struct _195 { public static readonly _195 Default; } + public readonly struct _196 { public static readonly _196 Default; } + public readonly struct _197 { public static readonly _197 Default; } + public readonly struct _198 { public static readonly _198 Default; } + public readonly struct _199 { public static readonly _199 Default; } + public readonly struct _200 { public static readonly _200 Default; } + public readonly struct _201 { public static readonly _201 Default; } + public readonly struct _202 { public static readonly _202 Default; } + public readonly struct _203 { public static readonly _203 Default; } + public readonly struct _204 { public static readonly _204 Default; } + public readonly struct _205 { public static readonly _205 Default; } + public readonly struct _206 { public static readonly _206 Default; } + public readonly struct _207 { public static readonly _207 Default; } + public readonly struct _208 { public static readonly _208 Default; } + public readonly struct _209 { public static readonly _209 Default; } + public readonly struct _210 { public static readonly _210 Default; } + public readonly struct _211 { public static readonly _211 Default; } + public readonly struct _212 { public static readonly _212 Default; } + public readonly struct _213 { public static readonly _213 Default; } + public readonly struct _214 { public static readonly _214 Default; } + public readonly struct _215 { public static readonly _215 Default; } + public readonly struct _216 { public static readonly _216 Default; } + public readonly struct _217 { public static readonly _217 Default; } + public readonly struct _218 { public static readonly _218 Default; } + public readonly struct _219 { public static readonly _219 Default; } + public readonly struct _220 { public static readonly _220 Default; } + public readonly struct _221 { public static readonly _221 Default; } + public readonly struct _222 { public static readonly _222 Default; } + public readonly struct _223 { public static readonly _223 Default; } + public readonly struct _224 { public static readonly _224 Default; } + public readonly struct _225 { public static readonly _225 Default; } + public readonly struct _226 { public static readonly _226 Default; } + public readonly struct _227 { public static readonly _227 Default; } + public readonly struct _228 { public static readonly _228 Default; } + public readonly struct _229 { public static readonly _229 Default; } + public readonly struct _230 { public static readonly _230 Default; } + public readonly struct _231 { public static readonly _231 Default; } + public readonly struct _232 { public static readonly _232 Default; } + public readonly struct _233 { public static readonly _233 Default; } + public readonly struct _234 { public static readonly _234 Default; } + public readonly struct _235 { public static readonly _235 Default; } + public readonly struct _236 { public static readonly _236 Default; } + public readonly struct _237 { public static readonly _237 Default; } + public readonly struct _238 { public static readonly _238 Default; } + public readonly struct _239 { public static readonly _239 Default; } + public readonly struct _240 { public static readonly _240 Default; } + public readonly struct _241 { public static readonly _241 Default; } + public readonly struct _242 { public static readonly _242 Default; } + public readonly struct _243 { public static readonly _243 Default; } + public readonly struct _244 { public static readonly _244 Default; } + public readonly struct _245 { public static readonly _245 Default; } + public readonly struct _246 { public static readonly _246 Default; } + public readonly struct _247 { public static readonly _247 Default; } + public readonly struct _248 { public static readonly _248 Default; } + public readonly struct _249 { public static readonly _249 Default; } + public readonly struct _250 { public static readonly _250 Default; } + public readonly struct _251 { public static readonly _251 Default; } + public readonly struct _252 { public static readonly _252 Default; } + public readonly struct _253 { public static readonly _253 Default; } + public readonly struct _254 { public static readonly _254 Default; } + public readonly struct _255 { public static readonly _255 Default; } + } +} diff --git a/src/dotVariant.Runtime/GeneratorSupport/Accessor.cs b/src/dotVariant.Runtime/GeneratorSupport/Accessor.cs deleted file mode 100644 index 1be0238..0000000 --- a/src/dotVariant.Runtime/GeneratorSupport/Accessor.cs +++ /dev/null @@ -1,519 +0,0 @@ -// -// Copyright Miro Knejp 2021. -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE.txt or copy at https://www.boost.org/LICENSE_1_0.txt) -// - -namespace dotVariant.GeneratorSupport -{ - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_1 { public readonly T Value; public Accessor_1(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_2 { public readonly T Value; public Accessor_2(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_3 { public readonly T Value; public Accessor_3(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_4 { public readonly T Value; public Accessor_4(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_5 { public readonly T Value; public Accessor_5(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_6 { public readonly T Value; public Accessor_6(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_7 { public readonly T Value; public Accessor_7(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_8 { public readonly T Value; public Accessor_8(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_9 { public readonly T Value; public Accessor_9(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_10 { public readonly T Value; public Accessor_10(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_11 { public readonly T Value; public Accessor_11(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_12 { public readonly T Value; public Accessor_12(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_13 { public readonly T Value; public Accessor_13(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_14 { public readonly T Value; public Accessor_14(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_15 { public readonly T Value; public Accessor_15(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_16 { public readonly T Value; public Accessor_16(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_17 { public readonly T Value; public Accessor_17(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_18 { public readonly T Value; public Accessor_18(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_19 { public readonly T Value; public Accessor_19(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_20 { public readonly T Value; public Accessor_20(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_21 { public readonly T Value; public Accessor_21(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_22 { public readonly T Value; public Accessor_22(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_23 { public readonly T Value; public Accessor_23(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_24 { public readonly T Value; public Accessor_24(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_25 { public readonly T Value; public Accessor_25(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_26 { public readonly T Value; public Accessor_26(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_27 { public readonly T Value; public Accessor_27(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_28 { public readonly T Value; public Accessor_28(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_29 { public readonly T Value; public Accessor_29(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_30 { public readonly T Value; public Accessor_30(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_31 { public readonly T Value; public Accessor_31(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_32 { public readonly T Value; public Accessor_32(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_33 { public readonly T Value; public Accessor_33(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_34 { public readonly T Value; public Accessor_34(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_35 { public readonly T Value; public Accessor_35(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_36 { public readonly T Value; public Accessor_36(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_37 { public readonly T Value; public Accessor_37(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_38 { public readonly T Value; public Accessor_38(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_39 { public readonly T Value; public Accessor_39(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_40 { public readonly T Value; public Accessor_40(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_41 { public readonly T Value; public Accessor_41(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_42 { public readonly T Value; public Accessor_42(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_43 { public readonly T Value; public Accessor_43(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_44 { public readonly T Value; public Accessor_44(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_45 { public readonly T Value; public Accessor_45(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_46 { public readonly T Value; public Accessor_46(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_47 { public readonly T Value; public Accessor_47(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_48 { public readonly T Value; public Accessor_48(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_49 { public readonly T Value; public Accessor_49(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_50 { public readonly T Value; public Accessor_50(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_51 { public readonly T Value; public Accessor_51(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_52 { public readonly T Value; public Accessor_52(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_53 { public readonly T Value; public Accessor_53(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_54 { public readonly T Value; public Accessor_54(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_55 { public readonly T Value; public Accessor_55(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_56 { public readonly T Value; public Accessor_56(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_57 { public readonly T Value; public Accessor_57(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_58 { public readonly T Value; public Accessor_58(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_59 { public readonly T Value; public Accessor_59(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_60 { public readonly T Value; public Accessor_60(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_61 { public readonly T Value; public Accessor_61(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_62 { public readonly T Value; public Accessor_62(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_63 { public readonly T Value; public Accessor_63(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_64 { public readonly T Value; public Accessor_64(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_65 { public readonly T Value; public Accessor_65(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_66 { public readonly T Value; public Accessor_66(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_67 { public readonly T Value; public Accessor_67(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_68 { public readonly T Value; public Accessor_68(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_69 { public readonly T Value; public Accessor_69(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_70 { public readonly T Value; public Accessor_70(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_71 { public readonly T Value; public Accessor_71(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_72 { public readonly T Value; public Accessor_72(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_73 { public readonly T Value; public Accessor_73(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_74 { public readonly T Value; public Accessor_74(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_75 { public readonly T Value; public Accessor_75(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_76 { public readonly T Value; public Accessor_76(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_77 { public readonly T Value; public Accessor_77(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_78 { public readonly T Value; public Accessor_78(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_79 { public readonly T Value; public Accessor_79(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_80 { public readonly T Value; public Accessor_80(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_81 { public readonly T Value; public Accessor_81(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_82 { public readonly T Value; public Accessor_82(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_83 { public readonly T Value; public Accessor_83(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_84 { public readonly T Value; public Accessor_84(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_85 { public readonly T Value; public Accessor_85(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_86 { public readonly T Value; public Accessor_86(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_87 { public readonly T Value; public Accessor_87(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_88 { public readonly T Value; public Accessor_88(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_89 { public readonly T Value; public Accessor_89(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_90 { public readonly T Value; public Accessor_90(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_91 { public readonly T Value; public Accessor_91(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_92 { public readonly T Value; public Accessor_92(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_93 { public readonly T Value; public Accessor_93(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_94 { public readonly T Value; public Accessor_94(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_95 { public readonly T Value; public Accessor_95(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_96 { public readonly T Value; public Accessor_96(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_97 { public readonly T Value; public Accessor_97(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_98 { public readonly T Value; public Accessor_98(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_99 { public readonly T Value; public Accessor_99(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_100 { public readonly T Value; public Accessor_100(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_101 { public readonly T Value; public Accessor_101(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_102 { public readonly T Value; public Accessor_102(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_103 { public readonly T Value; public Accessor_103(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_104 { public readonly T Value; public Accessor_104(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_105 { public readonly T Value; public Accessor_105(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_106 { public readonly T Value; public Accessor_106(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_107 { public readonly T Value; public Accessor_107(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_108 { public readonly T Value; public Accessor_108(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_109 { public readonly T Value; public Accessor_109(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_110 { public readonly T Value; public Accessor_110(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_111 { public readonly T Value; public Accessor_111(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_112 { public readonly T Value; public Accessor_112(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_113 { public readonly T Value; public Accessor_113(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_114 { public readonly T Value; public Accessor_114(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_115 { public readonly T Value; public Accessor_115(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_116 { public readonly T Value; public Accessor_116(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_117 { public readonly T Value; public Accessor_117(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_118 { public readonly T Value; public Accessor_118(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_119 { public readonly T Value; public Accessor_119(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_120 { public readonly T Value; public Accessor_120(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_121 { public readonly T Value; public Accessor_121(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_122 { public readonly T Value; public Accessor_122(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_123 { public readonly T Value; public Accessor_123(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_124 { public readonly T Value; public Accessor_124(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_125 { public readonly T Value; public Accessor_125(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_126 { public readonly T Value; public Accessor_126(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_127 { public readonly T Value; public Accessor_127(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_128 { public readonly T Value; public Accessor_128(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_129 { public readonly T Value; public Accessor_129(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_130 { public readonly T Value; public Accessor_130(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_131 { public readonly T Value; public Accessor_131(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_132 { public readonly T Value; public Accessor_132(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_133 { public readonly T Value; public Accessor_133(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_134 { public readonly T Value; public Accessor_134(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_135 { public readonly T Value; public Accessor_135(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_136 { public readonly T Value; public Accessor_136(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_137 { public readonly T Value; public Accessor_137(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_138 { public readonly T Value; public Accessor_138(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_139 { public readonly T Value; public Accessor_139(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_140 { public readonly T Value; public Accessor_140(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_141 { public readonly T Value; public Accessor_141(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_142 { public readonly T Value; public Accessor_142(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_143 { public readonly T Value; public Accessor_143(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_144 { public readonly T Value; public Accessor_144(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_145 { public readonly T Value; public Accessor_145(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_146 { public readonly T Value; public Accessor_146(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_147 { public readonly T Value; public Accessor_147(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_148 { public readonly T Value; public Accessor_148(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_149 { public readonly T Value; public Accessor_149(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_150 { public readonly T Value; public Accessor_150(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_151 { public readonly T Value; public Accessor_151(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_152 { public readonly T Value; public Accessor_152(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_153 { public readonly T Value; public Accessor_153(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_154 { public readonly T Value; public Accessor_154(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_155 { public readonly T Value; public Accessor_155(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_156 { public readonly T Value; public Accessor_156(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_157 { public readonly T Value; public Accessor_157(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_158 { public readonly T Value; public Accessor_158(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_159 { public readonly T Value; public Accessor_159(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_160 { public readonly T Value; public Accessor_160(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_161 { public readonly T Value; public Accessor_161(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_162 { public readonly T Value; public Accessor_162(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_163 { public readonly T Value; public Accessor_163(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_164 { public readonly T Value; public Accessor_164(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_165 { public readonly T Value; public Accessor_165(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_166 { public readonly T Value; public Accessor_166(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_167 { public readonly T Value; public Accessor_167(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_168 { public readonly T Value; public Accessor_168(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_169 { public readonly T Value; public Accessor_169(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_170 { public readonly T Value; public Accessor_170(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_171 { public readonly T Value; public Accessor_171(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_172 { public readonly T Value; public Accessor_172(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_173 { public readonly T Value; public Accessor_173(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_174 { public readonly T Value; public Accessor_174(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_175 { public readonly T Value; public Accessor_175(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_176 { public readonly T Value; public Accessor_176(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_177 { public readonly T Value; public Accessor_177(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_178 { public readonly T Value; public Accessor_178(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_179 { public readonly T Value; public Accessor_179(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_180 { public readonly T Value; public Accessor_180(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_181 { public readonly T Value; public Accessor_181(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_182 { public readonly T Value; public Accessor_182(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_183 { public readonly T Value; public Accessor_183(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_184 { public readonly T Value; public Accessor_184(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_185 { public readonly T Value; public Accessor_185(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_186 { public readonly T Value; public Accessor_186(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_187 { public readonly T Value; public Accessor_187(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_188 { public readonly T Value; public Accessor_188(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_189 { public readonly T Value; public Accessor_189(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_190 { public readonly T Value; public Accessor_190(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_191 { public readonly T Value; public Accessor_191(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_192 { public readonly T Value; public Accessor_192(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_193 { public readonly T Value; public Accessor_193(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_194 { public readonly T Value; public Accessor_194(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_195 { public readonly T Value; public Accessor_195(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_196 { public readonly T Value; public Accessor_196(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_197 { public readonly T Value; public Accessor_197(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_198 { public readonly T Value; public Accessor_198(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_199 { public readonly T Value; public Accessor_199(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_200 { public readonly T Value; public Accessor_200(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_201 { public readonly T Value; public Accessor_201(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_202 { public readonly T Value; public Accessor_202(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_203 { public readonly T Value; public Accessor_203(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_204 { public readonly T Value; public Accessor_204(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_205 { public readonly T Value; public Accessor_205(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_206 { public readonly T Value; public Accessor_206(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_207 { public readonly T Value; public Accessor_207(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_208 { public readonly T Value; public Accessor_208(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_209 { public readonly T Value; public Accessor_209(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_210 { public readonly T Value; public Accessor_210(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_211 { public readonly T Value; public Accessor_211(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_212 { public readonly T Value; public Accessor_212(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_213 { public readonly T Value; public Accessor_213(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_214 { public readonly T Value; public Accessor_214(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_215 { public readonly T Value; public Accessor_215(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_216 { public readonly T Value; public Accessor_216(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_217 { public readonly T Value; public Accessor_217(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_218 { public readonly T Value; public Accessor_218(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_219 { public readonly T Value; public Accessor_219(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_220 { public readonly T Value; public Accessor_220(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_221 { public readonly T Value; public Accessor_221(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_222 { public readonly T Value; public Accessor_222(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_223 { public readonly T Value; public Accessor_223(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_224 { public readonly T Value; public Accessor_224(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_225 { public readonly T Value; public Accessor_225(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_226 { public readonly T Value; public Accessor_226(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_227 { public readonly T Value; public Accessor_227(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_228 { public readonly T Value; public Accessor_228(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_229 { public readonly T Value; public Accessor_229(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_230 { public readonly T Value; public Accessor_230(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_231 { public readonly T Value; public Accessor_231(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_232 { public readonly T Value; public Accessor_232(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_233 { public readonly T Value; public Accessor_233(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_234 { public readonly T Value; public Accessor_234(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_235 { public readonly T Value; public Accessor_235(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_236 { public readonly T Value; public Accessor_236(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_237 { public readonly T Value; public Accessor_237(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_238 { public readonly T Value; public Accessor_238(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_239 { public readonly T Value; public Accessor_239(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_240 { public readonly T Value; public Accessor_240(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_241 { public readonly T Value; public Accessor_241(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_242 { public readonly T Value; public Accessor_242(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_243 { public readonly T Value; public Accessor_243(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_244 { public readonly T Value; public Accessor_244(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_245 { public readonly T Value; public Accessor_245(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_246 { public readonly T Value; public Accessor_246(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_247 { public readonly T Value; public Accessor_247(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_248 { public readonly T Value; public Accessor_248(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_249 { public readonly T Value; public Accessor_249(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_250 { public readonly T Value; public Accessor_250(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_251 { public readonly T Value; public Accessor_251(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_252 { public readonly T Value; public Accessor_252(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_253 { public readonly T Value; public Accessor_253(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_254 { public readonly T Value; public Accessor_254(T value) => Value = value; } - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public readonly struct Accessor_255 { public readonly T Value; public Accessor_255(T value) => Value = value; } -} diff --git a/src/dotVariant.Runtime/GeneratorSupport/Discriminator.cs b/src/dotVariant.Runtime/GeneratorSupport/Discriminator.cs deleted file mode 100644 index cc9e82b..0000000 --- a/src/dotVariant.Runtime/GeneratorSupport/Discriminator.cs +++ /dev/null @@ -1,11 +0,0 @@ -// -// Copyright Miro Knejp 2021. -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE.txt or copy at https://www.boost.org/LICENSE_1_0.txt) -// - -namespace dotVariant.GeneratorSupport -{ - [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public enum Discriminator : byte { } -}