From 384da240f85e8508e6032c966c3599851ce1da10 Mon Sep 17 00:00:00 2001 From: Martin Zarate Date: Sat, 17 Feb 2024 00:34:52 -0500 Subject: [PATCH] add new method WithType to add types to a OneOf - also added the README to the solution --- Generator/Program.cs | 15 ++- OneOf.Extended/OneOfBaseT10.generated.cs | 8 +- OneOf.Extended/OneOfBaseT11.generated.cs | 8 +- OneOf.Extended/OneOfBaseT12.generated.cs | 8 +- OneOf.Extended/OneOfBaseT13.generated.cs | 8 +- OneOf.Extended/OneOfBaseT14.generated.cs | 8 +- OneOf.Extended/OneOfBaseT15.generated.cs | 8 +- OneOf.Extended/OneOfBaseT16.generated.cs | 8 +- OneOf.Extended/OneOfBaseT17.generated.cs | 8 +- OneOf.Extended/OneOfBaseT18.generated.cs | 8 +- OneOf.Extended/OneOfBaseT19.generated.cs | 8 +- OneOf.Extended/OneOfBaseT20.generated.cs | 8 +- OneOf.Extended/OneOfBaseT21.generated.cs | 8 +- OneOf.Extended/OneOfBaseT22.generated.cs | 8 +- OneOf.Extended/OneOfBaseT23.generated.cs | 8 +- OneOf.Extended/OneOfBaseT24.generated.cs | 8 +- OneOf.Extended/OneOfBaseT25.generated.cs | 8 +- OneOf.Extended/OneOfBaseT26.generated.cs | 8 +- OneOf.Extended/OneOfBaseT27.generated.cs | 8 +- OneOf.Extended/OneOfBaseT28.generated.cs | 8 +- OneOf.Extended/OneOfBaseT29.generated.cs | 8 +- OneOf.Extended/OneOfBaseT30.generated.cs | 8 +- OneOf.Extended/OneOfBaseT31.generated.cs | 8 +- OneOf.Extended/OneOfBaseT9.generated.cs | 8 +- OneOf.Extended/OneOfT10.generated.cs | 8 +- OneOf.Extended/OneOfT11.generated.cs | 8 +- OneOf.Extended/OneOfT12.generated.cs | 8 +- OneOf.Extended/OneOfT13.generated.cs | 8 +- OneOf.Extended/OneOfT14.generated.cs | 8 +- OneOf.Extended/OneOfT15.generated.cs | 8 +- OneOf.Extended/OneOfT16.generated.cs | 8 +- OneOf.Extended/OneOfT17.generated.cs | 8 +- OneOf.Extended/OneOfT18.generated.cs | 8 +- OneOf.Extended/OneOfT19.generated.cs | 8 +- OneOf.Extended/OneOfT20.generated.cs | 8 +- OneOf.Extended/OneOfT21.generated.cs | 8 +- OneOf.Extended/OneOfT22.generated.cs | 8 +- OneOf.Extended/OneOfT23.generated.cs | 8 +- OneOf.Extended/OneOfT24.generated.cs | 8 +- OneOf.Extended/OneOfT25.generated.cs | 8 +- OneOf.Extended/OneOfT26.generated.cs | 8 +- OneOf.Extended/OneOfT27.generated.cs | 8 +- OneOf.Extended/OneOfT28.generated.cs | 8 +- OneOf.Extended/OneOfT29.generated.cs | 8 +- OneOf.Extended/OneOfT30.generated.cs | 8 +- OneOf.Extended/OneOfT31.generated.cs | 8 +- OneOf.Extended/OneOfT9.generated.cs | 8 +- OneOf.Tests/WithTypeTests.cs | 51 ++++++++ OneOf.sln | 145 ++++++++++++----------- OneOf/OneOfBaseT0.generated.cs | 8 +- OneOf/OneOfBaseT1.generated.cs | 10 +- OneOf/OneOfBaseT2.generated.cs | 10 +- OneOf/OneOfBaseT3.generated.cs | 10 +- OneOf/OneOfBaseT4.generated.cs | 10 +- OneOf/OneOfBaseT5.generated.cs | 10 +- OneOf/OneOfBaseT6.generated.cs | 10 +- OneOf/OneOfBaseT7.generated.cs | 10 +- OneOf/OneOfBaseT8.generated.cs | 8 +- OneOf/OneOfT0.generated.cs | 8 +- OneOf/OneOfT1.generated.cs | 10 +- OneOf/OneOfT2.generated.cs | 10 +- OneOf/OneOfT3.generated.cs | 10 +- OneOf/OneOfT4.generated.cs | 10 +- OneOf/OneOfT5.generated.cs | 10 +- OneOf/OneOfT6.generated.cs | 10 +- OneOf/OneOfT7.generated.cs | 10 +- OneOf/OneOfT8.generated.cs | 8 +- README.md | 29 +++++ 68 files changed, 516 insertions(+), 264 deletions(-) create mode 100644 OneOf.Tests/WithTypeTests.cs diff --git a/Generator/Program.cs b/Generator/Program.cs index 4f04e2b..ee503a3 100644 --- a/Generator/Program.cs +++ b/Generator/Program.cs @@ -7,8 +7,9 @@ using System.Collections.Generic; var sourceRoot = GetFullPath(Combine(GetDirectoryName(GetExecutingAssembly().Location)!, @"..\..\..\..")); +const int extendedSizeLimit = 10; -for (var i = 1; i < 10; i++) { +for (var i = 1; i < extendedSizeLimit; i++) { var output = GetContent(true, i); var outpath = Combine(sourceRoot, $"OneOf\\OneOfT{i - 1}.generated.cs"); File.WriteAllText(outpath, output); @@ -18,7 +19,7 @@ File.WriteAllText(outpath2, output2); } -for (var i = 10; i < 33; i++) { +for (var i = extendedSizeLimit; i < 33; i++) { var output3 = GetContent(true, i); var outpath3 = Combine(sourceRoot, $"OneOf.Extended\\OneOfT{i - 1}.generated.cs"); File.WriteAllText(outpath3, output3); @@ -49,13 +50,13 @@ namespace OneOf readonly int _index; {IfStruct( // constructor - $@"OneOf(int index, {RangeJoined(", ", j => $"T{j} value{j} = default")}) + $@"internal OneOf(int index, {RangeJoined(", ", j => $"T{j} value{j} = default")}) {{ _index = index; {RangeJoined(@" ", j => $"_value{j} = value{j};")} }}", - $@"protected OneOfBase(OneOf<{genericArg}> input) + $@"protected internal OneOfBase(OneOf<{genericArg}> input) {{ _index = input.Index; switch (_index) @@ -77,6 +78,12 @@ namespace OneOf public int Index => _index; + {((i < extendedSizeLimit - 1) ? + // can go up to the limit before extended because OneOfT8 cannot see OneOfT9 + $@"public OneOf<{genericArg}, TNew> WithType() => + new OneOf<{genericArg}, TNew>(_index, {RangeJoined(", ", j => $"_value{j}")}, default); + ":"")} + {RangeJoined(@" ", j=> $"public bool IsT{j} => _index == {j};")} diff --git a/OneOf.Extended/OneOfBaseT10.generated.cs b/OneOf.Extended/OneOfBaseT10.generated.cs index 3c61780..3272957 100644 --- a/OneOf.Extended/OneOfBaseT10.generated.cs +++ b/OneOf.Extended/OneOfBaseT10.generated.cs @@ -18,7 +18,7 @@ public class OneOfBase : IOneOf readonly T10 _value10; readonly int _index; - protected OneOfBase(OneOf input) + protected internal OneOfBase(OneOf input) { _index = input.Index; switch (_index) @@ -57,6 +57,8 @@ protected OneOfBase(OneOf input) public int Index => _index; + + public bool IsT0 => _index == 0; public bool IsT1 => _index == 1; public bool IsT2 => _index == 2; @@ -458,7 +460,7 @@ public bool TryPickT10(out T10 value, out OneOf throw new InvalidOperationException() }; return this.IsT10; - } + } bool Equals(OneOfBase other) => _index == other._index && @@ -531,4 +533,4 @@ public override int GetHashCode() } } } -} +} diff --git a/OneOf.Extended/OneOfBaseT11.generated.cs b/OneOf.Extended/OneOfBaseT11.generated.cs index cc72a59..8d6c95a 100644 --- a/OneOf.Extended/OneOfBaseT11.generated.cs +++ b/OneOf.Extended/OneOfBaseT11.generated.cs @@ -19,7 +19,7 @@ public class OneOfBase : IOneO readonly T11 _value11; readonly int _index; - protected OneOfBase(OneOf input) + protected internal OneOfBase(OneOf input) { _index = input.Index; switch (_index) @@ -60,6 +60,8 @@ protected OneOfBase(OneOf inpu public int Index => _index; + + public bool IsT0 => _index == 0; public bool IsT1 => _index == 1; public bool IsT2 => _index == 2; @@ -508,7 +510,7 @@ public bool TryPickT11(out T11 value, out OneOf throw new InvalidOperationException() }; return this.IsT11; - } + } bool Equals(OneOfBase other) => _index == other._index && @@ -584,4 +586,4 @@ public override int GetHashCode() } } } -} +} diff --git a/OneOf.Extended/OneOfBaseT12.generated.cs b/OneOf.Extended/OneOfBaseT12.generated.cs index 7b9c66d..6d9c70a 100644 --- a/OneOf.Extended/OneOfBaseT12.generated.cs +++ b/OneOf.Extended/OneOfBaseT12.generated.cs @@ -20,7 +20,7 @@ public class OneOfBase : readonly T12 _value12; readonly int _index; - protected OneOfBase(OneOf input) + protected internal OneOfBase(OneOf input) { _index = input.Index; switch (_index) @@ -63,6 +63,8 @@ protected OneOfBase(OneOf public int Index => _index; + + public bool IsT0 => _index == 0; public bool IsT1 => _index == 1; public bool IsT2 => _index == 2; @@ -560,7 +562,7 @@ public bool TryPickT12(out T12 value, out OneOf throw new InvalidOperationException() }; return this.IsT12; - } + } bool Equals(OneOfBase other) => _index == other._index && @@ -639,4 +641,4 @@ public override int GetHashCode() } } } -} +} diff --git a/OneOf.Extended/OneOfBaseT13.generated.cs b/OneOf.Extended/OneOfBaseT13.generated.cs index ccf0cd7..a843703 100644 --- a/OneOf.Extended/OneOfBaseT13.generated.cs +++ b/OneOf.Extended/OneOfBaseT13.generated.cs @@ -21,7 +21,7 @@ public class OneOfBase input) + protected internal OneOfBase(OneOf input) { _index = input.Index; switch (_index) @@ -66,6 +66,8 @@ protected OneOfBase(OneOf _index; + + public bool IsT0 => _index == 0; public bool IsT1 => _index == 1; public bool IsT2 => _index == 2; @@ -614,7 +616,7 @@ public bool TryPickT13(out T13 value, out OneOf throw new InvalidOperationException() }; return this.IsT13; - } + } bool Equals(OneOfBase other) => _index == other._index && @@ -696,4 +698,4 @@ public override int GetHashCode() } } } -} +} diff --git a/OneOf.Extended/OneOfBaseT14.generated.cs b/OneOf.Extended/OneOfBaseT14.generated.cs index cade467..b5d9709 100644 --- a/OneOf.Extended/OneOfBaseT14.generated.cs +++ b/OneOf.Extended/OneOfBaseT14.generated.cs @@ -22,7 +22,7 @@ public class OneOfBase input) + protected internal OneOfBase(OneOf input) { _index = input.Index; switch (_index) @@ -69,6 +69,8 @@ protected OneOfBase(OneOf _index; + + public bool IsT0 => _index == 0; public bool IsT1 => _index == 1; public bool IsT2 => _index == 2; @@ -670,7 +672,7 @@ public bool TryPickT14(out T14 value, out OneOf throw new InvalidOperationException() }; return this.IsT14; - } + } bool Equals(OneOfBase other) => _index == other._index && @@ -755,4 +757,4 @@ public override int GetHashCode() } } } -} +} diff --git a/OneOf.Extended/OneOfBaseT15.generated.cs b/OneOf.Extended/OneOfBaseT15.generated.cs index 05132d2..3fa31e4 100644 --- a/OneOf.Extended/OneOfBaseT15.generated.cs +++ b/OneOf.Extended/OneOfBaseT15.generated.cs @@ -23,7 +23,7 @@ public class OneOfBase input) + protected internal OneOfBase(OneOf input) { _index = input.Index; switch (_index) @@ -72,6 +72,8 @@ protected OneOfBase(OneOf _index; + + public bool IsT0 => _index == 0; public bool IsT1 => _index == 1; public bool IsT2 => _index == 2; @@ -728,7 +730,7 @@ public bool TryPickT15(out T15 value, out OneOf throw new InvalidOperationException() }; return this.IsT15; - } + } bool Equals(OneOfBase other) => _index == other._index && @@ -816,4 +818,4 @@ public override int GetHashCode() } } } -} +} diff --git a/OneOf.Extended/OneOfBaseT16.generated.cs b/OneOf.Extended/OneOfBaseT16.generated.cs index d59e70a..e86ff6b 100644 --- a/OneOf.Extended/OneOfBaseT16.generated.cs +++ b/OneOf.Extended/OneOfBaseT16.generated.cs @@ -24,7 +24,7 @@ public class OneOfBase input) + protected internal OneOfBase(OneOf input) { _index = input.Index; switch (_index) @@ -75,6 +75,8 @@ protected OneOfBase(OneOf _index; + + public bool IsT0 => _index == 0; public bool IsT1 => _index == 1; public bool IsT2 => _index == 2; @@ -788,7 +790,7 @@ public bool TryPickT16(out T16 value, out OneOf throw new InvalidOperationException() }; return this.IsT16; - } + } bool Equals(OneOfBase other) => _index == other._index && @@ -879,4 +881,4 @@ public override int GetHashCode() } } } -} +} diff --git a/OneOf.Extended/OneOfBaseT17.generated.cs b/OneOf.Extended/OneOfBaseT17.generated.cs index b50d501..a407688 100644 --- a/OneOf.Extended/OneOfBaseT17.generated.cs +++ b/OneOf.Extended/OneOfBaseT17.generated.cs @@ -25,7 +25,7 @@ public class OneOfBase input) + protected internal OneOfBase(OneOf input) { _index = input.Index; switch (_index) @@ -78,6 +78,8 @@ protected OneOfBase(OneOf _index; + + public bool IsT0 => _index == 0; public bool IsT1 => _index == 1; public bool IsT2 => _index == 2; @@ -850,7 +852,7 @@ public bool TryPickT17(out T17 value, out OneOf throw new InvalidOperationException() }; return this.IsT17; - } + } bool Equals(OneOfBase other) => _index == other._index && @@ -944,4 +946,4 @@ public override int GetHashCode() } } } -} +} diff --git a/OneOf.Extended/OneOfBaseT18.generated.cs b/OneOf.Extended/OneOfBaseT18.generated.cs index 9749b93..f7b653e 100644 --- a/OneOf.Extended/OneOfBaseT18.generated.cs +++ b/OneOf.Extended/OneOfBaseT18.generated.cs @@ -26,7 +26,7 @@ public class OneOfBase input) + protected internal OneOfBase(OneOf input) { _index = input.Index; switch (_index) @@ -81,6 +81,8 @@ protected OneOfBase(OneOf _index; + + public bool IsT0 => _index == 0; public bool IsT1 => _index == 1; public bool IsT2 => _index == 2; @@ -914,7 +916,7 @@ public bool TryPickT18(out T18 value, out OneOf throw new InvalidOperationException() }; return this.IsT18; - } + } bool Equals(OneOfBase other) => _index == other._index && @@ -1011,4 +1013,4 @@ public override int GetHashCode() } } } -} +} diff --git a/OneOf.Extended/OneOfBaseT19.generated.cs b/OneOf.Extended/OneOfBaseT19.generated.cs index 76a2c60..2ab3a5f 100644 --- a/OneOf.Extended/OneOfBaseT19.generated.cs +++ b/OneOf.Extended/OneOfBaseT19.generated.cs @@ -27,7 +27,7 @@ public class OneOfBase input) + protected internal OneOfBase(OneOf input) { _index = input.Index; switch (_index) @@ -84,6 +84,8 @@ protected OneOfBase(OneOf _index; + + public bool IsT0 => _index == 0; public bool IsT1 => _index == 1; public bool IsT2 => _index == 2; @@ -980,7 +982,7 @@ public bool TryPickT19(out T19 value, out OneOf throw new InvalidOperationException() }; return this.IsT19; - } + } bool Equals(OneOfBase other) => _index == other._index && @@ -1080,4 +1082,4 @@ public override int GetHashCode() } } } -} +} diff --git a/OneOf.Extended/OneOfBaseT20.generated.cs b/OneOf.Extended/OneOfBaseT20.generated.cs index 7f69d8f..5016db2 100644 --- a/OneOf.Extended/OneOfBaseT20.generated.cs +++ b/OneOf.Extended/OneOfBaseT20.generated.cs @@ -28,7 +28,7 @@ public class OneOfBase input) + protected internal OneOfBase(OneOf input) { _index = input.Index; switch (_index) @@ -87,6 +87,8 @@ protected OneOfBase(OneOf _index; + + public bool IsT0 => _index == 0; public bool IsT1 => _index == 1; public bool IsT2 => _index == 2; @@ -1048,7 +1050,7 @@ public bool TryPickT20(out T20 value, out OneOf throw new InvalidOperationException() }; return this.IsT20; - } + } bool Equals(OneOfBase other) => _index == other._index && @@ -1151,4 +1153,4 @@ public override int GetHashCode() } } } -} +} diff --git a/OneOf.Extended/OneOfBaseT21.generated.cs b/OneOf.Extended/OneOfBaseT21.generated.cs index a6b02ee..62b0ba2 100644 --- a/OneOf.Extended/OneOfBaseT21.generated.cs +++ b/OneOf.Extended/OneOfBaseT21.generated.cs @@ -29,7 +29,7 @@ public class OneOfBase input) + protected internal OneOfBase(OneOf input) { _index = input.Index; switch (_index) @@ -90,6 +90,8 @@ protected OneOfBase(OneOf _index; + + public bool IsT0 => _index == 0; public bool IsT1 => _index == 1; public bool IsT2 => _index == 2; @@ -1118,7 +1120,7 @@ public bool TryPickT21(out T21 value, out OneOf throw new InvalidOperationException() }; return this.IsT21; - } + } bool Equals(OneOfBase other) => _index == other._index && @@ -1224,4 +1226,4 @@ public override int GetHashCode() } } } -} +} diff --git a/OneOf.Extended/OneOfBaseT22.generated.cs b/OneOf.Extended/OneOfBaseT22.generated.cs index daca4ef..fe9cde0 100644 --- a/OneOf.Extended/OneOfBaseT22.generated.cs +++ b/OneOf.Extended/OneOfBaseT22.generated.cs @@ -30,7 +30,7 @@ public class OneOfBase input) + protected internal OneOfBase(OneOf input) { _index = input.Index; switch (_index) @@ -93,6 +93,8 @@ protected OneOfBase(OneOf _index; + + public bool IsT0 => _index == 0; public bool IsT1 => _index == 1; public bool IsT2 => _index == 2; @@ -1190,7 +1192,7 @@ public bool TryPickT22(out T22 value, out OneOf throw new InvalidOperationException() }; return this.IsT22; - } + } bool Equals(OneOfBase other) => _index == other._index && @@ -1299,4 +1301,4 @@ public override int GetHashCode() } } } -} +} diff --git a/OneOf.Extended/OneOfBaseT23.generated.cs b/OneOf.Extended/OneOfBaseT23.generated.cs index 78a26b5..0f5957c 100644 --- a/OneOf.Extended/OneOfBaseT23.generated.cs +++ b/OneOf.Extended/OneOfBaseT23.generated.cs @@ -31,7 +31,7 @@ public class OneOfBase input) + protected internal OneOfBase(OneOf input) { _index = input.Index; switch (_index) @@ -96,6 +96,8 @@ protected OneOfBase(OneOf _index; + + public bool IsT0 => _index == 0; public bool IsT1 => _index == 1; public bool IsT2 => _index == 2; @@ -1264,7 +1266,7 @@ public bool TryPickT23(out T23 value, out OneOf throw new InvalidOperationException() }; return this.IsT23; - } + } bool Equals(OneOfBase other) => _index == other._index && @@ -1376,4 +1378,4 @@ public override int GetHashCode() } } } -} +} diff --git a/OneOf.Extended/OneOfBaseT24.generated.cs b/OneOf.Extended/OneOfBaseT24.generated.cs index c291a10..dd7db2b 100644 --- a/OneOf.Extended/OneOfBaseT24.generated.cs +++ b/OneOf.Extended/OneOfBaseT24.generated.cs @@ -32,7 +32,7 @@ public class OneOfBase input) + protected internal OneOfBase(OneOf input) { _index = input.Index; switch (_index) @@ -99,6 +99,8 @@ protected OneOfBase(OneOf _index; + + public bool IsT0 => _index == 0; public bool IsT1 => _index == 1; public bool IsT2 => _index == 2; @@ -1340,7 +1342,7 @@ public bool TryPickT24(out T24 value, out OneOf throw new InvalidOperationException() }; return this.IsT24; - } + } bool Equals(OneOfBase other) => _index == other._index && @@ -1455,4 +1457,4 @@ public override int GetHashCode() } } } -} +} diff --git a/OneOf.Extended/OneOfBaseT25.generated.cs b/OneOf.Extended/OneOfBaseT25.generated.cs index dc06dc9..27b491a 100644 --- a/OneOf.Extended/OneOfBaseT25.generated.cs +++ b/OneOf.Extended/OneOfBaseT25.generated.cs @@ -33,7 +33,7 @@ public class OneOfBase input) + protected internal OneOfBase(OneOf input) { _index = input.Index; switch (_index) @@ -102,6 +102,8 @@ protected OneOfBase(OneOf _index; + + public bool IsT0 => _index == 0; public bool IsT1 => _index == 1; public bool IsT2 => _index == 2; @@ -1418,7 +1420,7 @@ public bool TryPickT25(out T25 value, out OneOf throw new InvalidOperationException() }; return this.IsT25; - } + } bool Equals(OneOfBase other) => _index == other._index && @@ -1536,4 +1538,4 @@ public override int GetHashCode() } } } -} +} diff --git a/OneOf.Extended/OneOfBaseT26.generated.cs b/OneOf.Extended/OneOfBaseT26.generated.cs index edd010b..4f90444 100644 --- a/OneOf.Extended/OneOfBaseT26.generated.cs +++ b/OneOf.Extended/OneOfBaseT26.generated.cs @@ -34,7 +34,7 @@ public class OneOfBase input) + protected internal OneOfBase(OneOf input) { _index = input.Index; switch (_index) @@ -105,6 +105,8 @@ protected OneOfBase(OneOf _index; + + public bool IsT0 => _index == 0; public bool IsT1 => _index == 1; public bool IsT2 => _index == 2; @@ -1498,7 +1500,7 @@ public bool TryPickT26(out T26 value, out OneOf throw new InvalidOperationException() }; return this.IsT26; - } + } bool Equals(OneOfBase other) => _index == other._index && @@ -1619,4 +1621,4 @@ public override int GetHashCode() } } } -} +} diff --git a/OneOf.Extended/OneOfBaseT27.generated.cs b/OneOf.Extended/OneOfBaseT27.generated.cs index ae54cde..6a4eb82 100644 --- a/OneOf.Extended/OneOfBaseT27.generated.cs +++ b/OneOf.Extended/OneOfBaseT27.generated.cs @@ -35,7 +35,7 @@ public class OneOfBase input) + protected internal OneOfBase(OneOf input) { _index = input.Index; switch (_index) @@ -108,6 +108,8 @@ protected OneOfBase(OneOf _index; + + public bool IsT0 => _index == 0; public bool IsT1 => _index == 1; public bool IsT2 => _index == 2; @@ -1580,7 +1582,7 @@ public bool TryPickT27(out T27 value, out OneOf throw new InvalidOperationException() }; return this.IsT27; - } + } bool Equals(OneOfBase other) => _index == other._index && @@ -1704,4 +1706,4 @@ public override int GetHashCode() } } } -} +} diff --git a/OneOf.Extended/OneOfBaseT28.generated.cs b/OneOf.Extended/OneOfBaseT28.generated.cs index 611c63e..22b8e73 100644 --- a/OneOf.Extended/OneOfBaseT28.generated.cs +++ b/OneOf.Extended/OneOfBaseT28.generated.cs @@ -36,7 +36,7 @@ public class OneOfBase input) + protected internal OneOfBase(OneOf input) { _index = input.Index; switch (_index) @@ -111,6 +111,8 @@ protected OneOfBase(OneOf _index; + + public bool IsT0 => _index == 0; public bool IsT1 => _index == 1; public bool IsT2 => _index == 2; @@ -1664,7 +1666,7 @@ public bool TryPickT28(out T28 value, out OneOf throw new InvalidOperationException() }; return this.IsT28; - } + } bool Equals(OneOfBase other) => _index == other._index && @@ -1791,4 +1793,4 @@ public override int GetHashCode() } } } -} +} diff --git a/OneOf.Extended/OneOfBaseT29.generated.cs b/OneOf.Extended/OneOfBaseT29.generated.cs index 8348e0d..282bfe9 100644 --- a/OneOf.Extended/OneOfBaseT29.generated.cs +++ b/OneOf.Extended/OneOfBaseT29.generated.cs @@ -37,7 +37,7 @@ public class OneOfBase input) + protected internal OneOfBase(OneOf input) { _index = input.Index; switch (_index) @@ -114,6 +114,8 @@ protected OneOfBase(OneOf _index; + + public bool IsT0 => _index == 0; public bool IsT1 => _index == 1; public bool IsT2 => _index == 2; @@ -1750,7 +1752,7 @@ public bool TryPickT29(out T29 value, out OneOf throw new InvalidOperationException() }; return this.IsT29; - } + } bool Equals(OneOfBase other) => _index == other._index && @@ -1880,4 +1882,4 @@ public override int GetHashCode() } } } -} +} diff --git a/OneOf.Extended/OneOfBaseT30.generated.cs b/OneOf.Extended/OneOfBaseT30.generated.cs index 25229bd..f41bc7f 100644 --- a/OneOf.Extended/OneOfBaseT30.generated.cs +++ b/OneOf.Extended/OneOfBaseT30.generated.cs @@ -38,7 +38,7 @@ public class OneOfBase input) + protected internal OneOfBase(OneOf input) { _index = input.Index; switch (_index) @@ -117,6 +117,8 @@ protected OneOfBase(OneOf _index; + + public bool IsT0 => _index == 0; public bool IsT1 => _index == 1; public bool IsT2 => _index == 2; @@ -1838,7 +1840,7 @@ public bool TryPickT30(out T30 value, out OneOf throw new InvalidOperationException() }; return this.IsT30; - } + } bool Equals(OneOfBase other) => _index == other._index && @@ -1971,4 +1973,4 @@ public override int GetHashCode() } } } -} +} diff --git a/OneOf.Extended/OneOfBaseT31.generated.cs b/OneOf.Extended/OneOfBaseT31.generated.cs index 9a1fa4d..c015eec 100644 --- a/OneOf.Extended/OneOfBaseT31.generated.cs +++ b/OneOf.Extended/OneOfBaseT31.generated.cs @@ -39,7 +39,7 @@ public class OneOfBase input) + protected internal OneOfBase(OneOf input) { _index = input.Index; switch (_index) @@ -120,6 +120,8 @@ protected OneOfBase(OneOf _index; + + public bool IsT0 => _index == 0; public bool IsT1 => _index == 1; public bool IsT2 => _index == 2; @@ -1928,7 +1930,7 @@ public bool TryPickT31(out T31 value, out OneOf throw new InvalidOperationException() }; return this.IsT31; - } + } bool Equals(OneOfBase other) => _index == other._index && @@ -2064,4 +2066,4 @@ public override int GetHashCode() } } } -} +} diff --git a/OneOf.Extended/OneOfBaseT9.generated.cs b/OneOf.Extended/OneOfBaseT9.generated.cs index 9510257..de6d2be 100644 --- a/OneOf.Extended/OneOfBaseT9.generated.cs +++ b/OneOf.Extended/OneOfBaseT9.generated.cs @@ -17,7 +17,7 @@ public class OneOfBase : IOneOf readonly T9 _value9; readonly int _index; - protected OneOfBase(OneOf input) + protected internal OneOfBase(OneOf input) { _index = input.Index; switch (_index) @@ -54,6 +54,8 @@ protected OneOfBase(OneOf input) public int Index => _index; + + public bool IsT0 => _index == 0; public bool IsT1 => _index == 1; public bool IsT2 => _index == 2; @@ -410,7 +412,7 @@ public bool TryPickT9(out T9 value, out OneOf throw new InvalidOperationException() }; return this.IsT9; - } + } bool Equals(OneOfBase other) => _index == other._index && @@ -480,4 +482,4 @@ public override int GetHashCode() } } } -} +} diff --git a/OneOf.Extended/OneOfT10.generated.cs b/OneOf.Extended/OneOfT10.generated.cs index 1297e00..7930314 100644 --- a/OneOf.Extended/OneOfT10.generated.cs +++ b/OneOf.Extended/OneOfT10.generated.cs @@ -18,7 +18,7 @@ namespace OneOf readonly T10 _value10; readonly int _index; - OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default, T10 value10 = default) + internal OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default, T10 value10 = default) { _index = index; _value0 = value0; @@ -53,6 +53,8 @@ namespace OneOf public int Index => _index; + + public bool IsT0 => _index == 0; public bool IsT1 => _index == 1; public bool IsT2 => _index == 2; @@ -726,7 +728,7 @@ public bool TryPickT10(out T10 value, out OneOf throw new InvalidOperationException() }; return this.IsT10; - } + } bool Equals(OneOf other) => _index == other._index && @@ -795,4 +797,4 @@ public override int GetHashCode() } } } -} +} diff --git a/OneOf.Extended/OneOfT11.generated.cs b/OneOf.Extended/OneOfT11.generated.cs index 4b97d9f..7dd5d11 100644 --- a/OneOf.Extended/OneOfT11.generated.cs +++ b/OneOf.Extended/OneOfT11.generated.cs @@ -19,7 +19,7 @@ namespace OneOf readonly T11 _value11; readonly int _index; - OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default, T10 value10 = default, T11 value11 = default) + internal OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default, T10 value10 = default, T11 value11 = default) { _index = index; _value0 = value0; @@ -56,6 +56,8 @@ namespace OneOf public int Index => _index; + + public bool IsT0 => _index == 0; public bool IsT1 => _index == 1; public bool IsT2 => _index == 2; @@ -813,7 +815,7 @@ public bool TryPickT11(out T11 value, out OneOf throw new InvalidOperationException() }; return this.IsT11; - } + } bool Equals(OneOf other) => _index == other._index && @@ -885,4 +887,4 @@ public override int GetHashCode() } } } -} +} diff --git a/OneOf.Extended/OneOfT12.generated.cs b/OneOf.Extended/OneOfT12.generated.cs index 0801a8b..287ab4d 100644 --- a/OneOf.Extended/OneOfT12.generated.cs +++ b/OneOf.Extended/OneOfT12.generated.cs @@ -20,7 +20,7 @@ namespace OneOf readonly T12 _value12; readonly int _index; - OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default, T10 value10 = default, T11 value11 = default, T12 value12 = default) + internal OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default, T10 value10 = default, T11 value11 = default, T12 value12 = default) { _index = index; _value0 = value0; @@ -59,6 +59,8 @@ namespace OneOf public int Index => _index; + + public bool IsT0 => _index == 0; public bool IsT1 => _index == 1; public bool IsT2 => _index == 2; @@ -904,7 +906,7 @@ public bool TryPickT12(out T12 value, out OneOf throw new InvalidOperationException() }; return this.IsT12; - } + } bool Equals(OneOf other) => _index == other._index && @@ -979,4 +981,4 @@ public override int GetHashCode() } } } -} +} diff --git a/OneOf.Extended/OneOfT13.generated.cs b/OneOf.Extended/OneOfT13.generated.cs index c5d1ac5..3839d34 100644 --- a/OneOf.Extended/OneOfT13.generated.cs +++ b/OneOf.Extended/OneOfT13.generated.cs @@ -21,7 +21,7 @@ namespace OneOf readonly T13 _value13; readonly int _index; - OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default, T10 value10 = default, T11 value11 = default, T12 value12 = default, T13 value13 = default) + internal OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default, T10 value10 = default, T11 value11 = default, T12 value12 = default, T13 value13 = default) { _index = index; _value0 = value0; @@ -62,6 +62,8 @@ namespace OneOf public int Index => _index; + + public bool IsT0 => _index == 0; public bool IsT1 => _index == 1; public bool IsT2 => _index == 2; @@ -999,7 +1001,7 @@ public bool TryPickT13(out T13 value, out OneOf throw new InvalidOperationException() }; return this.IsT13; - } + } bool Equals(OneOf other) => _index == other._index && @@ -1077,4 +1079,4 @@ public override int GetHashCode() } } } -} +} diff --git a/OneOf.Extended/OneOfT14.generated.cs b/OneOf.Extended/OneOfT14.generated.cs index e7e9578..dc6fc26 100644 --- a/OneOf.Extended/OneOfT14.generated.cs +++ b/OneOf.Extended/OneOfT14.generated.cs @@ -22,7 +22,7 @@ namespace OneOf readonly T14 _value14; readonly int _index; - OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default, T10 value10 = default, T11 value11 = default, T12 value12 = default, T13 value13 = default, T14 value14 = default) + internal OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default, T10 value10 = default, T11 value11 = default, T12 value12 = default, T13 value13 = default, T14 value14 = default) { _index = index; _value0 = value0; @@ -65,6 +65,8 @@ namespace OneOf public int Index => _index; + + public bool IsT0 => _index == 0; public bool IsT1 => _index == 1; public bool IsT2 => _index == 2; @@ -1098,7 +1100,7 @@ public bool TryPickT14(out T14 value, out OneOf throw new InvalidOperationException() }; return this.IsT14; - } + } bool Equals(OneOf other) => _index == other._index && @@ -1179,4 +1181,4 @@ public override int GetHashCode() } } } -} +} diff --git a/OneOf.Extended/OneOfT15.generated.cs b/OneOf.Extended/OneOfT15.generated.cs index 8c3b91d..78c8902 100644 --- a/OneOf.Extended/OneOfT15.generated.cs +++ b/OneOf.Extended/OneOfT15.generated.cs @@ -23,7 +23,7 @@ namespace OneOf readonly T15 _value15; readonly int _index; - OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default, T10 value10 = default, T11 value11 = default, T12 value12 = default, T13 value13 = default, T14 value14 = default, T15 value15 = default) + internal OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default, T10 value10 = default, T11 value11 = default, T12 value12 = default, T13 value13 = default, T14 value14 = default, T15 value15 = default) { _index = index; _value0 = value0; @@ -68,6 +68,8 @@ namespace OneOf public int Index => _index; + + public bool IsT0 => _index == 0; public bool IsT1 => _index == 1; public bool IsT2 => _index == 2; @@ -1201,7 +1203,7 @@ public bool TryPickT15(out T15 value, out OneOf throw new InvalidOperationException() }; return this.IsT15; - } + } bool Equals(OneOf other) => _index == other._index && @@ -1285,4 +1287,4 @@ public override int GetHashCode() } } } -} +} diff --git a/OneOf.Extended/OneOfT16.generated.cs b/OneOf.Extended/OneOfT16.generated.cs index 51f8dc6..4e97e15 100644 --- a/OneOf.Extended/OneOfT16.generated.cs +++ b/OneOf.Extended/OneOfT16.generated.cs @@ -24,7 +24,7 @@ namespace OneOf readonly T16 _value16; readonly int _index; - OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default, T10 value10 = default, T11 value11 = default, T12 value12 = default, T13 value13 = default, T14 value14 = default, T15 value15 = default, T16 value16 = default) + internal OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default, T10 value10 = default, T11 value11 = default, T12 value12 = default, T13 value13 = default, T14 value14 = default, T15 value15 = default, T16 value16 = default) { _index = index; _value0 = value0; @@ -71,6 +71,8 @@ namespace OneOf public int Index => _index; + + public bool IsT0 => _index == 0; public bool IsT1 => _index == 1; public bool IsT2 => _index == 2; @@ -1308,7 +1310,7 @@ public bool TryPickT16(out T16 value, out OneOf throw new InvalidOperationException() }; return this.IsT16; - } + } bool Equals(OneOf other) => _index == other._index && @@ -1395,4 +1397,4 @@ public override int GetHashCode() } } } -} +} diff --git a/OneOf.Extended/OneOfT17.generated.cs b/OneOf.Extended/OneOfT17.generated.cs index eefe75b..015ff36 100644 --- a/OneOf.Extended/OneOfT17.generated.cs +++ b/OneOf.Extended/OneOfT17.generated.cs @@ -25,7 +25,7 @@ namespace OneOf readonly T17 _value17; readonly int _index; - OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default, T10 value10 = default, T11 value11 = default, T12 value12 = default, T13 value13 = default, T14 value14 = default, T15 value15 = default, T16 value16 = default, T17 value17 = default) + internal OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default, T10 value10 = default, T11 value11 = default, T12 value12 = default, T13 value13 = default, T14 value14 = default, T15 value15 = default, T16 value16 = default, T17 value17 = default) { _index = index; _value0 = value0; @@ -74,6 +74,8 @@ namespace OneOf public int Index => _index; + + public bool IsT0 => _index == 0; public bool IsT1 => _index == 1; public bool IsT2 => _index == 2; @@ -1419,7 +1421,7 @@ public bool TryPickT17(out T17 value, out OneOf throw new InvalidOperationException() }; return this.IsT17; - } + } bool Equals(OneOf other) => _index == other._index && @@ -1509,4 +1511,4 @@ public override int GetHashCode() } } } -} +} diff --git a/OneOf.Extended/OneOfT18.generated.cs b/OneOf.Extended/OneOfT18.generated.cs index ba17036..35b4151 100644 --- a/OneOf.Extended/OneOfT18.generated.cs +++ b/OneOf.Extended/OneOfT18.generated.cs @@ -26,7 +26,7 @@ namespace OneOf readonly T18 _value18; readonly int _index; - OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default, T10 value10 = default, T11 value11 = default, T12 value12 = default, T13 value13 = default, T14 value14 = default, T15 value15 = default, T16 value16 = default, T17 value17 = default, T18 value18 = default) + internal OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default, T10 value10 = default, T11 value11 = default, T12 value12 = default, T13 value13 = default, T14 value14 = default, T15 value15 = default, T16 value16 = default, T17 value17 = default, T18 value18 = default) { _index = index; _value0 = value0; @@ -77,6 +77,8 @@ namespace OneOf public int Index => _index; + + public bool IsT0 => _index == 0; public bool IsT1 => _index == 1; public bool IsT2 => _index == 2; @@ -1534,7 +1536,7 @@ public bool TryPickT18(out T18 value, out OneOf throw new InvalidOperationException() }; return this.IsT18; - } + } bool Equals(OneOf other) => _index == other._index && @@ -1627,4 +1629,4 @@ public override int GetHashCode() } } } -} +} diff --git a/OneOf.Extended/OneOfT19.generated.cs b/OneOf.Extended/OneOfT19.generated.cs index 3541ffe..74a638c 100644 --- a/OneOf.Extended/OneOfT19.generated.cs +++ b/OneOf.Extended/OneOfT19.generated.cs @@ -27,7 +27,7 @@ namespace OneOf readonly T19 _value19; readonly int _index; - OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default, T10 value10 = default, T11 value11 = default, T12 value12 = default, T13 value13 = default, T14 value14 = default, T15 value15 = default, T16 value16 = default, T17 value17 = default, T18 value18 = default, T19 value19 = default) + internal OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default, T10 value10 = default, T11 value11 = default, T12 value12 = default, T13 value13 = default, T14 value14 = default, T15 value15 = default, T16 value16 = default, T17 value17 = default, T18 value18 = default, T19 value19 = default) { _index = index; _value0 = value0; @@ -80,6 +80,8 @@ namespace OneOf public int Index => _index; + + public bool IsT0 => _index == 0; public bool IsT1 => _index == 1; public bool IsT2 => _index == 2; @@ -1653,7 +1655,7 @@ public bool TryPickT19(out T19 value, out OneOf throw new InvalidOperationException() }; return this.IsT19; - } + } bool Equals(OneOf other) => _index == other._index && @@ -1749,4 +1751,4 @@ public override int GetHashCode() } } } -} +} diff --git a/OneOf.Extended/OneOfT20.generated.cs b/OneOf.Extended/OneOfT20.generated.cs index c03bd8b..742ca88 100644 --- a/OneOf.Extended/OneOfT20.generated.cs +++ b/OneOf.Extended/OneOfT20.generated.cs @@ -28,7 +28,7 @@ namespace OneOf readonly T20 _value20; readonly int _index; - OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default, T10 value10 = default, T11 value11 = default, T12 value12 = default, T13 value13 = default, T14 value14 = default, T15 value15 = default, T16 value16 = default, T17 value17 = default, T18 value18 = default, T19 value19 = default, T20 value20 = default) + internal OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default, T10 value10 = default, T11 value11 = default, T12 value12 = default, T13 value13 = default, T14 value14 = default, T15 value15 = default, T16 value16 = default, T17 value17 = default, T18 value18 = default, T19 value19 = default, T20 value20 = default) { _index = index; _value0 = value0; @@ -83,6 +83,8 @@ namespace OneOf public int Index => _index; + + public bool IsT0 => _index == 0; public bool IsT1 => _index == 1; public bool IsT2 => _index == 2; @@ -1776,7 +1778,7 @@ public bool TryPickT20(out T20 value, out OneOf throw new InvalidOperationException() }; return this.IsT20; - } + } bool Equals(OneOf other) => _index == other._index && @@ -1875,4 +1877,4 @@ public override int GetHashCode() } } } -} +} diff --git a/OneOf.Extended/OneOfT21.generated.cs b/OneOf.Extended/OneOfT21.generated.cs index 1d89b7b..a1da48d 100644 --- a/OneOf.Extended/OneOfT21.generated.cs +++ b/OneOf.Extended/OneOfT21.generated.cs @@ -29,7 +29,7 @@ namespace OneOf readonly T21 _value21; readonly int _index; - OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default, T10 value10 = default, T11 value11 = default, T12 value12 = default, T13 value13 = default, T14 value14 = default, T15 value15 = default, T16 value16 = default, T17 value17 = default, T18 value18 = default, T19 value19 = default, T20 value20 = default, T21 value21 = default) + internal OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default, T10 value10 = default, T11 value11 = default, T12 value12 = default, T13 value13 = default, T14 value14 = default, T15 value15 = default, T16 value16 = default, T17 value17 = default, T18 value18 = default, T19 value19 = default, T20 value20 = default, T21 value21 = default) { _index = index; _value0 = value0; @@ -86,6 +86,8 @@ namespace OneOf public int Index => _index; + + public bool IsT0 => _index == 0; public bool IsT1 => _index == 1; public bool IsT2 => _index == 2; @@ -1903,7 +1905,7 @@ public bool TryPickT21(out T21 value, out OneOf throw new InvalidOperationException() }; return this.IsT21; - } + } bool Equals(OneOf other) => _index == other._index && @@ -2005,4 +2007,4 @@ public override int GetHashCode() } } } -} +} diff --git a/OneOf.Extended/OneOfT22.generated.cs b/OneOf.Extended/OneOfT22.generated.cs index 58f9f5d..616e9fb 100644 --- a/OneOf.Extended/OneOfT22.generated.cs +++ b/OneOf.Extended/OneOfT22.generated.cs @@ -30,7 +30,7 @@ namespace OneOf readonly T22 _value22; readonly int _index; - OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default, T10 value10 = default, T11 value11 = default, T12 value12 = default, T13 value13 = default, T14 value14 = default, T15 value15 = default, T16 value16 = default, T17 value17 = default, T18 value18 = default, T19 value19 = default, T20 value20 = default, T21 value21 = default, T22 value22 = default) + internal OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default, T10 value10 = default, T11 value11 = default, T12 value12 = default, T13 value13 = default, T14 value14 = default, T15 value15 = default, T16 value16 = default, T17 value17 = default, T18 value18 = default, T19 value19 = default, T20 value20 = default, T21 value21 = default, T22 value22 = default) { _index = index; _value0 = value0; @@ -89,6 +89,8 @@ namespace OneOf public int Index => _index; + + public bool IsT0 => _index == 0; public bool IsT1 => _index == 1; public bool IsT2 => _index == 2; @@ -2034,7 +2036,7 @@ public bool TryPickT22(out T22 value, out OneOf throw new InvalidOperationException() }; return this.IsT22; - } + } bool Equals(OneOf other) => _index == other._index && @@ -2139,4 +2141,4 @@ public override int GetHashCode() } } } -} +} diff --git a/OneOf.Extended/OneOfT23.generated.cs b/OneOf.Extended/OneOfT23.generated.cs index aa8881c..e0ebad4 100644 --- a/OneOf.Extended/OneOfT23.generated.cs +++ b/OneOf.Extended/OneOfT23.generated.cs @@ -31,7 +31,7 @@ namespace OneOf readonly T23 _value23; readonly int _index; - OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default, T10 value10 = default, T11 value11 = default, T12 value12 = default, T13 value13 = default, T14 value14 = default, T15 value15 = default, T16 value16 = default, T17 value17 = default, T18 value18 = default, T19 value19 = default, T20 value20 = default, T21 value21 = default, T22 value22 = default, T23 value23 = default) + internal OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default, T10 value10 = default, T11 value11 = default, T12 value12 = default, T13 value13 = default, T14 value14 = default, T15 value15 = default, T16 value16 = default, T17 value17 = default, T18 value18 = default, T19 value19 = default, T20 value20 = default, T21 value21 = default, T22 value22 = default, T23 value23 = default) { _index = index; _value0 = value0; @@ -92,6 +92,8 @@ namespace OneOf public int Index => _index; + + public bool IsT0 => _index == 0; public bool IsT1 => _index == 1; public bool IsT2 => _index == 2; @@ -2169,7 +2171,7 @@ public bool TryPickT23(out T23 value, out OneOf throw new InvalidOperationException() }; return this.IsT23; - } + } bool Equals(OneOf other) => _index == other._index && @@ -2277,4 +2279,4 @@ public override int GetHashCode() } } } -} +} diff --git a/OneOf.Extended/OneOfT24.generated.cs b/OneOf.Extended/OneOfT24.generated.cs index 87854ed..fe6b2ec 100644 --- a/OneOf.Extended/OneOfT24.generated.cs +++ b/OneOf.Extended/OneOfT24.generated.cs @@ -32,7 +32,7 @@ namespace OneOf readonly T24 _value24; readonly int _index; - OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default, T10 value10 = default, T11 value11 = default, T12 value12 = default, T13 value13 = default, T14 value14 = default, T15 value15 = default, T16 value16 = default, T17 value17 = default, T18 value18 = default, T19 value19 = default, T20 value20 = default, T21 value21 = default, T22 value22 = default, T23 value23 = default, T24 value24 = default) + internal OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default, T10 value10 = default, T11 value11 = default, T12 value12 = default, T13 value13 = default, T14 value14 = default, T15 value15 = default, T16 value16 = default, T17 value17 = default, T18 value18 = default, T19 value19 = default, T20 value20 = default, T21 value21 = default, T22 value22 = default, T23 value23 = default, T24 value24 = default) { _index = index; _value0 = value0; @@ -95,6 +95,8 @@ namespace OneOf public int Index => _index; + + public bool IsT0 => _index == 0; public bool IsT1 => _index == 1; public bool IsT2 => _index == 2; @@ -2308,7 +2310,7 @@ public bool TryPickT24(out T24 value, out OneOf throw new InvalidOperationException() }; return this.IsT24; - } + } bool Equals(OneOf other) => _index == other._index && @@ -2419,4 +2421,4 @@ public override int GetHashCode() } } } -} +} diff --git a/OneOf.Extended/OneOfT25.generated.cs b/OneOf.Extended/OneOfT25.generated.cs index dcc509c..0e2bed3 100644 --- a/OneOf.Extended/OneOfT25.generated.cs +++ b/OneOf.Extended/OneOfT25.generated.cs @@ -33,7 +33,7 @@ namespace OneOf readonly T25 _value25; readonly int _index; - OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default, T10 value10 = default, T11 value11 = default, T12 value12 = default, T13 value13 = default, T14 value14 = default, T15 value15 = default, T16 value16 = default, T17 value17 = default, T18 value18 = default, T19 value19 = default, T20 value20 = default, T21 value21 = default, T22 value22 = default, T23 value23 = default, T24 value24 = default, T25 value25 = default) + internal OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default, T10 value10 = default, T11 value11 = default, T12 value12 = default, T13 value13 = default, T14 value14 = default, T15 value15 = default, T16 value16 = default, T17 value17 = default, T18 value18 = default, T19 value19 = default, T20 value20 = default, T21 value21 = default, T22 value22 = default, T23 value23 = default, T24 value24 = default, T25 value25 = default) { _index = index; _value0 = value0; @@ -98,6 +98,8 @@ namespace OneOf public int Index => _index; + + public bool IsT0 => _index == 0; public bool IsT1 => _index == 1; public bool IsT2 => _index == 2; @@ -2451,7 +2453,7 @@ public bool TryPickT25(out T25 value, out OneOf throw new InvalidOperationException() }; return this.IsT25; - } + } bool Equals(OneOf other) => _index == other._index && @@ -2565,4 +2567,4 @@ public override int GetHashCode() } } } -} +} diff --git a/OneOf.Extended/OneOfT26.generated.cs b/OneOf.Extended/OneOfT26.generated.cs index a70fda0..e4a16c6 100644 --- a/OneOf.Extended/OneOfT26.generated.cs +++ b/OneOf.Extended/OneOfT26.generated.cs @@ -34,7 +34,7 @@ namespace OneOf readonly T26 _value26; readonly int _index; - OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default, T10 value10 = default, T11 value11 = default, T12 value12 = default, T13 value13 = default, T14 value14 = default, T15 value15 = default, T16 value16 = default, T17 value17 = default, T18 value18 = default, T19 value19 = default, T20 value20 = default, T21 value21 = default, T22 value22 = default, T23 value23 = default, T24 value24 = default, T25 value25 = default, T26 value26 = default) + internal OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default, T10 value10 = default, T11 value11 = default, T12 value12 = default, T13 value13 = default, T14 value14 = default, T15 value15 = default, T16 value16 = default, T17 value17 = default, T18 value18 = default, T19 value19 = default, T20 value20 = default, T21 value21 = default, T22 value22 = default, T23 value23 = default, T24 value24 = default, T25 value25 = default, T26 value26 = default) { _index = index; _value0 = value0; @@ -101,6 +101,8 @@ namespace OneOf public int Index => _index; + + public bool IsT0 => _index == 0; public bool IsT1 => _index == 1; public bool IsT2 => _index == 2; @@ -2598,7 +2600,7 @@ public bool TryPickT26(out T26 value, out OneOf throw new InvalidOperationException() }; return this.IsT26; - } + } bool Equals(OneOf other) => _index == other._index && @@ -2715,4 +2717,4 @@ public override int GetHashCode() } } } -} +} diff --git a/OneOf.Extended/OneOfT27.generated.cs b/OneOf.Extended/OneOfT27.generated.cs index fc45eab..492696a 100644 --- a/OneOf.Extended/OneOfT27.generated.cs +++ b/OneOf.Extended/OneOfT27.generated.cs @@ -35,7 +35,7 @@ namespace OneOf readonly T27 _value27; readonly int _index; - OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default, T10 value10 = default, T11 value11 = default, T12 value12 = default, T13 value13 = default, T14 value14 = default, T15 value15 = default, T16 value16 = default, T17 value17 = default, T18 value18 = default, T19 value19 = default, T20 value20 = default, T21 value21 = default, T22 value22 = default, T23 value23 = default, T24 value24 = default, T25 value25 = default, T26 value26 = default, T27 value27 = default) + internal OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default, T10 value10 = default, T11 value11 = default, T12 value12 = default, T13 value13 = default, T14 value14 = default, T15 value15 = default, T16 value16 = default, T17 value17 = default, T18 value18 = default, T19 value19 = default, T20 value20 = default, T21 value21 = default, T22 value22 = default, T23 value23 = default, T24 value24 = default, T25 value25 = default, T26 value26 = default, T27 value27 = default) { _index = index; _value0 = value0; @@ -104,6 +104,8 @@ namespace OneOf public int Index => _index; + + public bool IsT0 => _index == 0; public bool IsT1 => _index == 1; public bool IsT2 => _index == 2; @@ -2749,7 +2751,7 @@ public bool TryPickT27(out T27 value, out OneOf throw new InvalidOperationException() }; return this.IsT27; - } + } bool Equals(OneOf other) => _index == other._index && @@ -2869,4 +2871,4 @@ public override int GetHashCode() } } } -} +} diff --git a/OneOf.Extended/OneOfT28.generated.cs b/OneOf.Extended/OneOfT28.generated.cs index bdaa11f..68bd31b 100644 --- a/OneOf.Extended/OneOfT28.generated.cs +++ b/OneOf.Extended/OneOfT28.generated.cs @@ -36,7 +36,7 @@ namespace OneOf readonly T28 _value28; readonly int _index; - OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default, T10 value10 = default, T11 value11 = default, T12 value12 = default, T13 value13 = default, T14 value14 = default, T15 value15 = default, T16 value16 = default, T17 value17 = default, T18 value18 = default, T19 value19 = default, T20 value20 = default, T21 value21 = default, T22 value22 = default, T23 value23 = default, T24 value24 = default, T25 value25 = default, T26 value26 = default, T27 value27 = default, T28 value28 = default) + internal OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default, T10 value10 = default, T11 value11 = default, T12 value12 = default, T13 value13 = default, T14 value14 = default, T15 value15 = default, T16 value16 = default, T17 value17 = default, T18 value18 = default, T19 value19 = default, T20 value20 = default, T21 value21 = default, T22 value22 = default, T23 value23 = default, T24 value24 = default, T25 value25 = default, T26 value26 = default, T27 value27 = default, T28 value28 = default) { _index = index; _value0 = value0; @@ -107,6 +107,8 @@ namespace OneOf public int Index => _index; + + public bool IsT0 => _index == 0; public bool IsT1 => _index == 1; public bool IsT2 => _index == 2; @@ -2904,7 +2906,7 @@ public bool TryPickT28(out T28 value, out OneOf throw new InvalidOperationException() }; return this.IsT28; - } + } bool Equals(OneOf other) => _index == other._index && @@ -3027,4 +3029,4 @@ public override int GetHashCode() } } } -} +} diff --git a/OneOf.Extended/OneOfT29.generated.cs b/OneOf.Extended/OneOfT29.generated.cs index 74ec58e..62b10cb 100644 --- a/OneOf.Extended/OneOfT29.generated.cs +++ b/OneOf.Extended/OneOfT29.generated.cs @@ -37,7 +37,7 @@ namespace OneOf readonly T29 _value29; readonly int _index; - OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default, T10 value10 = default, T11 value11 = default, T12 value12 = default, T13 value13 = default, T14 value14 = default, T15 value15 = default, T16 value16 = default, T17 value17 = default, T18 value18 = default, T19 value19 = default, T20 value20 = default, T21 value21 = default, T22 value22 = default, T23 value23 = default, T24 value24 = default, T25 value25 = default, T26 value26 = default, T27 value27 = default, T28 value28 = default, T29 value29 = default) + internal OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default, T10 value10 = default, T11 value11 = default, T12 value12 = default, T13 value13 = default, T14 value14 = default, T15 value15 = default, T16 value16 = default, T17 value17 = default, T18 value18 = default, T19 value19 = default, T20 value20 = default, T21 value21 = default, T22 value22 = default, T23 value23 = default, T24 value24 = default, T25 value25 = default, T26 value26 = default, T27 value27 = default, T28 value28 = default, T29 value29 = default) { _index = index; _value0 = value0; @@ -110,6 +110,8 @@ namespace OneOf public int Index => _index; + + public bool IsT0 => _index == 0; public bool IsT1 => _index == 1; public bool IsT2 => _index == 2; @@ -3063,7 +3065,7 @@ public bool TryPickT29(out T29 value, out OneOf throw new InvalidOperationException() }; return this.IsT29; - } + } bool Equals(OneOf other) => _index == other._index && @@ -3189,4 +3191,4 @@ public override int GetHashCode() } } } -} +} diff --git a/OneOf.Extended/OneOfT30.generated.cs b/OneOf.Extended/OneOfT30.generated.cs index 5c6e763..90f3192 100644 --- a/OneOf.Extended/OneOfT30.generated.cs +++ b/OneOf.Extended/OneOfT30.generated.cs @@ -38,7 +38,7 @@ namespace OneOf readonly T30 _value30; readonly int _index; - OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default, T10 value10 = default, T11 value11 = default, T12 value12 = default, T13 value13 = default, T14 value14 = default, T15 value15 = default, T16 value16 = default, T17 value17 = default, T18 value18 = default, T19 value19 = default, T20 value20 = default, T21 value21 = default, T22 value22 = default, T23 value23 = default, T24 value24 = default, T25 value25 = default, T26 value26 = default, T27 value27 = default, T28 value28 = default, T29 value29 = default, T30 value30 = default) + internal OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default, T10 value10 = default, T11 value11 = default, T12 value12 = default, T13 value13 = default, T14 value14 = default, T15 value15 = default, T16 value16 = default, T17 value17 = default, T18 value18 = default, T19 value19 = default, T20 value20 = default, T21 value21 = default, T22 value22 = default, T23 value23 = default, T24 value24 = default, T25 value25 = default, T26 value26 = default, T27 value27 = default, T28 value28 = default, T29 value29 = default, T30 value30 = default) { _index = index; _value0 = value0; @@ -113,6 +113,8 @@ namespace OneOf public int Index => _index; + + public bool IsT0 => _index == 0; public bool IsT1 => _index == 1; public bool IsT2 => _index == 2; @@ -3226,7 +3228,7 @@ public bool TryPickT30(out T30 value, out OneOf throw new InvalidOperationException() }; return this.IsT30; - } + } bool Equals(OneOf other) => _index == other._index && @@ -3355,4 +3357,4 @@ public override int GetHashCode() } } } -} +} diff --git a/OneOf.Extended/OneOfT31.generated.cs b/OneOf.Extended/OneOfT31.generated.cs index 5e2686e..7e85c26 100644 --- a/OneOf.Extended/OneOfT31.generated.cs +++ b/OneOf.Extended/OneOfT31.generated.cs @@ -39,7 +39,7 @@ namespace OneOf readonly T31 _value31; readonly int _index; - OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default, T10 value10 = default, T11 value11 = default, T12 value12 = default, T13 value13 = default, T14 value14 = default, T15 value15 = default, T16 value16 = default, T17 value17 = default, T18 value18 = default, T19 value19 = default, T20 value20 = default, T21 value21 = default, T22 value22 = default, T23 value23 = default, T24 value24 = default, T25 value25 = default, T26 value26 = default, T27 value27 = default, T28 value28 = default, T29 value29 = default, T30 value30 = default, T31 value31 = default) + internal OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default, T10 value10 = default, T11 value11 = default, T12 value12 = default, T13 value13 = default, T14 value14 = default, T15 value15 = default, T16 value16 = default, T17 value17 = default, T18 value18 = default, T19 value19 = default, T20 value20 = default, T21 value21 = default, T22 value22 = default, T23 value23 = default, T24 value24 = default, T25 value25 = default, T26 value26 = default, T27 value27 = default, T28 value28 = default, T29 value29 = default, T30 value30 = default, T31 value31 = default) { _index = index; _value0 = value0; @@ -116,6 +116,8 @@ namespace OneOf public int Index => _index; + + public bool IsT0 => _index == 0; public bool IsT1 => _index == 1; public bool IsT2 => _index == 2; @@ -3393,7 +3395,7 @@ public bool TryPickT31(out T31 value, out OneOf throw new InvalidOperationException() }; return this.IsT31; - } + } bool Equals(OneOf other) => _index == other._index && @@ -3525,4 +3527,4 @@ public override int GetHashCode() } } } -} +} diff --git a/OneOf.Extended/OneOfT9.generated.cs b/OneOf.Extended/OneOfT9.generated.cs index a1efcd2..bd47324 100644 --- a/OneOf.Extended/OneOfT9.generated.cs +++ b/OneOf.Extended/OneOfT9.generated.cs @@ -17,7 +17,7 @@ namespace OneOf readonly T9 _value9; readonly int _index; - OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default) + internal OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default, T9 value9 = default) { _index = index; _value0 = value0; @@ -50,6 +50,8 @@ namespace OneOf public int Index => _index; + + public bool IsT0 => _index == 0; public bool IsT1 => _index == 1; public bool IsT2 => _index == 2; @@ -643,7 +645,7 @@ public bool TryPickT9(out T9 value, out OneOf throw new InvalidOperationException() }; return this.IsT9; - } + } bool Equals(OneOf other) => _index == other._index && @@ -709,4 +711,4 @@ public override int GetHashCode() } } } -} +} diff --git a/OneOf.Tests/WithTypeTests.cs b/OneOf.Tests/WithTypeTests.cs new file mode 100644 index 0000000..1d3d103 --- /dev/null +++ b/OneOf.Tests/WithTypeTests.cs @@ -0,0 +1,51 @@ +using NUnit.Framework; +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OneOf.Tests { + public class WithTypeTests { + [Test] + public void WithType() { + var example = OneOf.FromT2(5.0); + var result = example.WithType(); + Assert.AreEqual(result.Value, 5.0); + Assert.AreEqual(result.Value, example.Value); + Assert.AreEqual(result.Index, example.Index); + Assert.IsTrue(result.IsT2); + Assert.IsFalse(result.IsT4); + } + + #region the example code from the readme + public OneOf ParseDouble(string input) { + if (double.TryParse(input, out var result)) { + return result; + } else { + return input; + } + } + + public OneOf ParseDoubleOrUTCDateOrInt(string input) { + if (DateTime.TryParseExact(input, "yyyy-MM-dd", CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeUniversal, out var dateResult)) { + return dateResult; + } + else if (int.TryParse(input, out var intResult)) { + return intResult; + } else { + return ParseDouble(input).WithType().WithType(); + } + } + + [Test] + public void TestParseDoubleOrUTCDateOrInt() { + Assert.AreEqual(ParseDoubleOrUTCDateOrInt("fred").AsT0, "fred"); + Assert.AreEqual(ParseDoubleOrUTCDateOrInt("5.5").AsT1, 5.5); + Assert.AreEqual(ParseDoubleOrUTCDateOrInt("2000-01-01").AsT2, new DateTime(2000, 01, 01, 0, 0, 0, DateTimeKind.Unspecified)); + Assert.AreEqual(ParseDoubleOrUTCDateOrInt("999").AsT3, 999); + } + #endregion + } +} diff --git a/OneOf.sln b/OneOf.sln index 0dbf09e..f939408 100644 --- a/OneOf.sln +++ b/OneOf.sln @@ -1,70 +1,75 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.3.32611.2 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OneOf.Tests", "OneOf.Tests\OneOf.Tests.csproj", "{82023ED0-3E20-43CF-ACA1-1EA547E70903}" - ProjectSection(ProjectDependencies) = postProject - {21D0DD1E-D38A-4A76-B2B3-4CEF11B2C6CB} = {21D0DD1E-D38A-4A76-B2B3-4CEF11B2C6CB} - EndProjectSection -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OneOf", "OneOf\OneOf.csproj", "{21D0DD1E-D38A-4A76-B2B3-4CEF11B2C6CB}" -EndProject -Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "OneOf.FSharp", "OneOf.FSharp\OneOf.FSharp.fsproj", "{26D54D37-8692-4E2A-9043-D2FFCBF5A816}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OneOf.Extended", "OneOf.Extended\OneOf.Extended.csproj", "{FB8845F4-51F1-407A-8E10-2A0B892E17FB}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Generator", "Generator\Generator.csproj", "{508CDAF6-E780-459E-BD8F-776A5EE2C2FF}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OneOf.SourceGenerator", "OneOf.SourceGenerator\OneOf.SourceGenerator.csproj", "{AC54E93D-1DB2-4143-A1AF-3CE2492EAC83}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OneOf.SourceGenerator.Tests", "OneOf.SourceGenerator.Tests\OneOf.SourceGenerator.Tests.csproj", "{A7D18F0E-8966-4685-8146-34F507356F5D}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OneOf.SourceGenerator.AnalyzerTests", "OneOf.SourceGenerator.AnalyzerTests\OneOf.SourceGenerator.AnalyzerTests.csproj", "{C08F270E-157A-48B9-A7B6-C948FCFC5494}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {82023ED0-3E20-43CF-ACA1-1EA547E70903}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {82023ED0-3E20-43CF-ACA1-1EA547E70903}.Debug|Any CPU.Build.0 = Debug|Any CPU - {82023ED0-3E20-43CF-ACA1-1EA547E70903}.Release|Any CPU.ActiveCfg = Release|Any CPU - {82023ED0-3E20-43CF-ACA1-1EA547E70903}.Release|Any CPU.Build.0 = Release|Any CPU - {21D0DD1E-D38A-4A76-B2B3-4CEF11B2C6CB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {21D0DD1E-D38A-4A76-B2B3-4CEF11B2C6CB}.Debug|Any CPU.Build.0 = Debug|Any CPU - {21D0DD1E-D38A-4A76-B2B3-4CEF11B2C6CB}.Release|Any CPU.ActiveCfg = Release|Any CPU - {21D0DD1E-D38A-4A76-B2B3-4CEF11B2C6CB}.Release|Any CPU.Build.0 = Release|Any CPU - {26D54D37-8692-4E2A-9043-D2FFCBF5A816}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {26D54D37-8692-4E2A-9043-D2FFCBF5A816}.Debug|Any CPU.Build.0 = Debug|Any CPU - {26D54D37-8692-4E2A-9043-D2FFCBF5A816}.Release|Any CPU.ActiveCfg = Release|Any CPU - {26D54D37-8692-4E2A-9043-D2FFCBF5A816}.Release|Any CPU.Build.0 = Release|Any CPU - {FB8845F4-51F1-407A-8E10-2A0B892E17FB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {FB8845F4-51F1-407A-8E10-2A0B892E17FB}.Debug|Any CPU.Build.0 = Debug|Any CPU - {FB8845F4-51F1-407A-8E10-2A0B892E17FB}.Release|Any CPU.ActiveCfg = Release|Any CPU - {FB8845F4-51F1-407A-8E10-2A0B892E17FB}.Release|Any CPU.Build.0 = Release|Any CPU - {508CDAF6-E780-459E-BD8F-776A5EE2C2FF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {508CDAF6-E780-459E-BD8F-776A5EE2C2FF}.Debug|Any CPU.Build.0 = Debug|Any CPU - {508CDAF6-E780-459E-BD8F-776A5EE2C2FF}.Release|Any CPU.ActiveCfg = Release|Any CPU - {508CDAF6-E780-459E-BD8F-776A5EE2C2FF}.Release|Any CPU.Build.0 = Release|Any CPU - {AC54E93D-1DB2-4143-A1AF-3CE2492EAC83}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {AC54E93D-1DB2-4143-A1AF-3CE2492EAC83}.Debug|Any CPU.Build.0 = Debug|Any CPU - {AC54E93D-1DB2-4143-A1AF-3CE2492EAC83}.Release|Any CPU.ActiveCfg = Release|Any CPU - {AC54E93D-1DB2-4143-A1AF-3CE2492EAC83}.Release|Any CPU.Build.0 = Release|Any CPU - {A7D18F0E-8966-4685-8146-34F507356F5D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {A7D18F0E-8966-4685-8146-34F507356F5D}.Debug|Any CPU.Build.0 = Debug|Any CPU - {A7D18F0E-8966-4685-8146-34F507356F5D}.Release|Any CPU.ActiveCfg = Release|Any CPU - {A7D18F0E-8966-4685-8146-34F507356F5D}.Release|Any CPU.Build.0 = Release|Any CPU - {C08F270E-157A-48B9-A7B6-C948FCFC5494}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {C08F270E-157A-48B9-A7B6-C948FCFC5494}.Debug|Any CPU.Build.0 = Debug|Any CPU - {C08F270E-157A-48B9-A7B6-C948FCFC5494}.Release|Any CPU.ActiveCfg = Release|Any CPU - {C08F270E-157A-48B9-A7B6-C948FCFC5494}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {10E10950-5AD9-4F2C-8174-E0F810680317} - EndGlobalSection -EndGlobal + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.3.32611.2 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OneOf.Tests", "OneOf.Tests\OneOf.Tests.csproj", "{82023ED0-3E20-43CF-ACA1-1EA547E70903}" + ProjectSection(ProjectDependencies) = postProject + {21D0DD1E-D38A-4A76-B2B3-4CEF11B2C6CB} = {21D0DD1E-D38A-4A76-B2B3-4CEF11B2C6CB} + EndProjectSection +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OneOf", "OneOf\OneOf.csproj", "{21D0DD1E-D38A-4A76-B2B3-4CEF11B2C6CB}" +EndProject +Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "OneOf.FSharp", "OneOf.FSharp\OneOf.FSharp.fsproj", "{26D54D37-8692-4E2A-9043-D2FFCBF5A816}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OneOf.Extended", "OneOf.Extended\OneOf.Extended.csproj", "{FB8845F4-51F1-407A-8E10-2A0B892E17FB}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Generator", "Generator\Generator.csproj", "{508CDAF6-E780-459E-BD8F-776A5EE2C2FF}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OneOf.SourceGenerator", "OneOf.SourceGenerator\OneOf.SourceGenerator.csproj", "{AC54E93D-1DB2-4143-A1AF-3CE2492EAC83}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OneOf.SourceGenerator.Tests", "OneOf.SourceGenerator.Tests\OneOf.SourceGenerator.Tests.csproj", "{A7D18F0E-8966-4685-8146-34F507356F5D}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OneOf.SourceGenerator.AnalyzerTests", "OneOf.SourceGenerator.AnalyzerTests\OneOf.SourceGenerator.AnalyzerTests.csproj", "{C08F270E-157A-48B9-A7B6-C948FCFC5494}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{DE277A67-AD12-4F46-B605-45622A0F4BE1}" + ProjectSection(SolutionItems) = preProject + README.md = README.md + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {82023ED0-3E20-43CF-ACA1-1EA547E70903}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {82023ED0-3E20-43CF-ACA1-1EA547E70903}.Debug|Any CPU.Build.0 = Debug|Any CPU + {82023ED0-3E20-43CF-ACA1-1EA547E70903}.Release|Any CPU.ActiveCfg = Release|Any CPU + {82023ED0-3E20-43CF-ACA1-1EA547E70903}.Release|Any CPU.Build.0 = Release|Any CPU + {21D0DD1E-D38A-4A76-B2B3-4CEF11B2C6CB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {21D0DD1E-D38A-4A76-B2B3-4CEF11B2C6CB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {21D0DD1E-D38A-4A76-B2B3-4CEF11B2C6CB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {21D0DD1E-D38A-4A76-B2B3-4CEF11B2C6CB}.Release|Any CPU.Build.0 = Release|Any CPU + {26D54D37-8692-4E2A-9043-D2FFCBF5A816}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {26D54D37-8692-4E2A-9043-D2FFCBF5A816}.Debug|Any CPU.Build.0 = Debug|Any CPU + {26D54D37-8692-4E2A-9043-D2FFCBF5A816}.Release|Any CPU.ActiveCfg = Release|Any CPU + {26D54D37-8692-4E2A-9043-D2FFCBF5A816}.Release|Any CPU.Build.0 = Release|Any CPU + {FB8845F4-51F1-407A-8E10-2A0B892E17FB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FB8845F4-51F1-407A-8E10-2A0B892E17FB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FB8845F4-51F1-407A-8E10-2A0B892E17FB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FB8845F4-51F1-407A-8E10-2A0B892E17FB}.Release|Any CPU.Build.0 = Release|Any CPU + {508CDAF6-E780-459E-BD8F-776A5EE2C2FF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {508CDAF6-E780-459E-BD8F-776A5EE2C2FF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {508CDAF6-E780-459E-BD8F-776A5EE2C2FF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {508CDAF6-E780-459E-BD8F-776A5EE2C2FF}.Release|Any CPU.Build.0 = Release|Any CPU + {AC54E93D-1DB2-4143-A1AF-3CE2492EAC83}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AC54E93D-1DB2-4143-A1AF-3CE2492EAC83}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AC54E93D-1DB2-4143-A1AF-3CE2492EAC83}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AC54E93D-1DB2-4143-A1AF-3CE2492EAC83}.Release|Any CPU.Build.0 = Release|Any CPU + {A7D18F0E-8966-4685-8146-34F507356F5D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A7D18F0E-8966-4685-8146-34F507356F5D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A7D18F0E-8966-4685-8146-34F507356F5D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A7D18F0E-8966-4685-8146-34F507356F5D}.Release|Any CPU.Build.0 = Release|Any CPU + {C08F270E-157A-48B9-A7B6-C948FCFC5494}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C08F270E-157A-48B9-A7B6-C948FCFC5494}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C08F270E-157A-48B9-A7B6-C948FCFC5494}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C08F270E-157A-48B9-A7B6-C948FCFC5494}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {10E10950-5AD9-4F2C-8174-E0F810680317} + EndGlobalSection +EndGlobal diff --git a/OneOf/OneOfBaseT0.generated.cs b/OneOf/OneOfBaseT0.generated.cs index 52a7fba..6606585 100644 --- a/OneOf/OneOfBaseT0.generated.cs +++ b/OneOf/OneOfBaseT0.generated.cs @@ -8,7 +8,7 @@ public class OneOfBase : IOneOf readonly T0 _value0; readonly int _index; - protected OneOfBase(OneOf input) + protected internal OneOfBase(OneOf input) { _index = input.Index; switch (_index) @@ -27,6 +27,10 @@ protected OneOfBase(OneOf input) public int Index => _index; + public OneOf WithType() => + new OneOf(_index, _value0, default); + + public bool IsT0 => _index == 0; public T0 AsT0 => @@ -100,4 +104,4 @@ public override int GetHashCode() } } } -} +} diff --git a/OneOf/OneOfBaseT1.generated.cs b/OneOf/OneOfBaseT1.generated.cs index b5816b4..8098bc8 100644 --- a/OneOf/OneOfBaseT1.generated.cs +++ b/OneOf/OneOfBaseT1.generated.cs @@ -9,7 +9,7 @@ public class OneOfBase : IOneOf readonly T1 _value1; readonly int _index; - protected OneOfBase(OneOf input) + protected internal OneOfBase(OneOf input) { _index = input.Index; switch (_index) @@ -30,6 +30,10 @@ protected OneOfBase(OneOf input) public int Index => _index; + public OneOf WithType() => + new OneOf(_index, _value0, _value1, default); + + public bool IsT0 => _index == 0; public bool IsT1 => _index == 1; @@ -98,7 +102,7 @@ public bool TryPickT1(out T1 value, out T0 remainder) _ => throw new InvalidOperationException() }; return this.IsT1; - } + } bool Equals(OneOfBase other) => _index == other._index && @@ -144,4 +148,4 @@ public override int GetHashCode() } } } -} +} diff --git a/OneOf/OneOfBaseT2.generated.cs b/OneOf/OneOfBaseT2.generated.cs index d8ed1a8..b95b4ed 100644 --- a/OneOf/OneOfBaseT2.generated.cs +++ b/OneOf/OneOfBaseT2.generated.cs @@ -10,7 +10,7 @@ public class OneOfBase : IOneOf readonly T2 _value2; readonly int _index; - protected OneOfBase(OneOf input) + protected internal OneOfBase(OneOf input) { _index = input.Index; switch (_index) @@ -33,6 +33,10 @@ protected OneOfBase(OneOf input) public int Index => _index; + public OneOf WithType() => + new OneOf(_index, _value0, _value1, _value2, default); + + public bool IsT0 => _index == 0; public bool IsT1 => _index == 1; public bool IsT2 => _index == 2; @@ -130,7 +134,7 @@ public bool TryPickT2(out T2 value, out OneOf remainder) _ => throw new InvalidOperationException() }; return this.IsT2; - } + } bool Equals(OneOfBase other) => _index == other._index && @@ -179,4 +183,4 @@ public override int GetHashCode() } } } -} +} diff --git a/OneOf/OneOfBaseT3.generated.cs b/OneOf/OneOfBaseT3.generated.cs index c47bd8e..f3d5e87 100644 --- a/OneOf/OneOfBaseT3.generated.cs +++ b/OneOf/OneOfBaseT3.generated.cs @@ -11,7 +11,7 @@ public class OneOfBase : IOneOf readonly T3 _value3; readonly int _index; - protected OneOfBase(OneOf input) + protected internal OneOfBase(OneOf input) { _index = input.Index; switch (_index) @@ -36,6 +36,10 @@ protected OneOfBase(OneOf input) public int Index => _index; + public OneOf WithType() => + new OneOf(_index, _value0, _value1, _value2, _value3, default); + + public bool IsT0 => _index == 0; public bool IsT1 => _index == 1; public bool IsT2 => _index == 2; @@ -164,7 +168,7 @@ public bool TryPickT3(out T3 value, out OneOf remainder) _ => throw new InvalidOperationException() }; return this.IsT3; - } + } bool Equals(OneOfBase other) => _index == other._index && @@ -216,4 +220,4 @@ public override int GetHashCode() } } } -} +} diff --git a/OneOf/OneOfBaseT4.generated.cs b/OneOf/OneOfBaseT4.generated.cs index 454c6cf..5d5819b 100644 --- a/OneOf/OneOfBaseT4.generated.cs +++ b/OneOf/OneOfBaseT4.generated.cs @@ -12,7 +12,7 @@ public class OneOfBase : IOneOf readonly T4 _value4; readonly int _index; - protected OneOfBase(OneOf input) + protected internal OneOfBase(OneOf input) { _index = input.Index; switch (_index) @@ -39,6 +39,10 @@ protected OneOfBase(OneOf input) public int Index => _index; + public OneOf WithType() => + new OneOf(_index, _value0, _value1, _value2, _value3, _value4, default); + + public bool IsT0 => _index == 0; public bool IsT1 => _index == 1; public bool IsT2 => _index == 2; @@ -200,7 +204,7 @@ public bool TryPickT4(out T4 value, out OneOf remainder) _ => throw new InvalidOperationException() }; return this.IsT4; - } + } bool Equals(OneOfBase other) => _index == other._index && @@ -255,4 +259,4 @@ public override int GetHashCode() } } } -} +} diff --git a/OneOf/OneOfBaseT5.generated.cs b/OneOf/OneOfBaseT5.generated.cs index feb72c3..2a1f89a 100644 --- a/OneOf/OneOfBaseT5.generated.cs +++ b/OneOf/OneOfBaseT5.generated.cs @@ -13,7 +13,7 @@ public class OneOfBase : IOneOf readonly T5 _value5; readonly int _index; - protected OneOfBase(OneOf input) + protected internal OneOfBase(OneOf input) { _index = input.Index; switch (_index) @@ -42,6 +42,10 @@ protected OneOfBase(OneOf input) public int Index => _index; + public OneOf WithType() => + new OneOf(_index, _value0, _value1, _value2, _value3, _value4, _value5, default); + + public bool IsT0 => _index == 0; public bool IsT1 => _index == 1; public bool IsT2 => _index == 2; @@ -238,7 +242,7 @@ public bool TryPickT5(out T5 value, out OneOf remainder) _ => throw new InvalidOperationException() }; return this.IsT5; - } + } bool Equals(OneOfBase other) => _index == other._index && @@ -296,4 +300,4 @@ public override int GetHashCode() } } } -} +} diff --git a/OneOf/OneOfBaseT6.generated.cs b/OneOf/OneOfBaseT6.generated.cs index 607b865..8718dbd 100644 --- a/OneOf/OneOfBaseT6.generated.cs +++ b/OneOf/OneOfBaseT6.generated.cs @@ -14,7 +14,7 @@ public class OneOfBase : IOneOf readonly T6 _value6; readonly int _index; - protected OneOfBase(OneOf input) + protected internal OneOfBase(OneOf input) { _index = input.Index; switch (_index) @@ -45,6 +45,10 @@ protected OneOfBase(OneOf input) public int Index => _index; + public OneOf WithType() => + new OneOf(_index, _value0, _value1, _value2, _value3, _value4, _value5, _value6, default); + + public bool IsT0 => _index == 0; public bool IsT1 => _index == 1; public bool IsT2 => _index == 2; @@ -278,7 +282,7 @@ public bool TryPickT6(out T6 value, out OneOf remainder) _ => throw new InvalidOperationException() }; return this.IsT6; - } + } bool Equals(OneOfBase other) => _index == other._index && @@ -339,4 +343,4 @@ public override int GetHashCode() } } } -} +} diff --git a/OneOf/OneOfBaseT7.generated.cs b/OneOf/OneOfBaseT7.generated.cs index c30d6bf..2a9c856 100644 --- a/OneOf/OneOfBaseT7.generated.cs +++ b/OneOf/OneOfBaseT7.generated.cs @@ -15,7 +15,7 @@ public class OneOfBase : IOneOf readonly T7 _value7; readonly int _index; - protected OneOfBase(OneOf input) + protected internal OneOfBase(OneOf input) { _index = input.Index; switch (_index) @@ -48,6 +48,10 @@ protected OneOfBase(OneOf input) public int Index => _index; + public OneOf WithType() => + new OneOf(_index, _value0, _value1, _value2, _value3, _value4, _value5, _value6, _value7, default); + + public bool IsT0 => _index == 0; public bool IsT1 => _index == 1; public bool IsT2 => _index == 2; @@ -320,7 +324,7 @@ public bool TryPickT7(out T7 value, out OneOf remain _ => throw new InvalidOperationException() }; return this.IsT7; - } + } bool Equals(OneOfBase other) => _index == other._index && @@ -384,4 +388,4 @@ public override int GetHashCode() } } } -} +} diff --git a/OneOf/OneOfBaseT8.generated.cs b/OneOf/OneOfBaseT8.generated.cs index 5ee8beb..c7ef72b 100644 --- a/OneOf/OneOfBaseT8.generated.cs +++ b/OneOf/OneOfBaseT8.generated.cs @@ -16,7 +16,7 @@ public class OneOfBase : IOneOf readonly T8 _value8; readonly int _index; - protected OneOfBase(OneOf input) + protected internal OneOfBase(OneOf input) { _index = input.Index; switch (_index) @@ -51,6 +51,8 @@ protected OneOfBase(OneOf input) public int Index => _index; + + public bool IsT0 => _index == 0; public bool IsT1 => _index == 1; public bool IsT2 => _index == 2; @@ -364,7 +366,7 @@ public bool TryPickT8(out T8 value, out OneOf re _ => throw new InvalidOperationException() }; return this.IsT8; - } + } bool Equals(OneOfBase other) => _index == other._index && @@ -431,4 +433,4 @@ public override int GetHashCode() } } } -} +} diff --git a/OneOf/OneOfT0.generated.cs b/OneOf/OneOfT0.generated.cs index 1f3090b..48f749e 100644 --- a/OneOf/OneOfT0.generated.cs +++ b/OneOf/OneOfT0.generated.cs @@ -8,7 +8,7 @@ namespace OneOf readonly T0 _value0; readonly int _index; - OneOf(int index, T0 value0 = default) + internal OneOf(int index, T0 value0 = default) { _index = index; _value0 = value0; @@ -23,6 +23,10 @@ namespace OneOf public int Index => _index; + public OneOf WithType() => + new OneOf(_index, _value0, default); + + public bool IsT0 => _index == 0; public T0 AsT0 => @@ -104,4 +108,4 @@ public override int GetHashCode() } } } -} +} diff --git a/OneOf/OneOfT1.generated.cs b/OneOf/OneOfT1.generated.cs index e6b645c..575d905 100644 --- a/OneOf/OneOfT1.generated.cs +++ b/OneOf/OneOfT1.generated.cs @@ -9,7 +9,7 @@ namespace OneOf readonly T1 _value1; readonly int _index; - OneOf(int index, T0 value0 = default, T1 value1 = default) + internal OneOf(int index, T0 value0 = default, T1 value1 = default) { _index = index; _value0 = value0; @@ -26,6 +26,10 @@ namespace OneOf public int Index => _index; + public OneOf WithType() => + new OneOf(_index, _value0, _value1, default); + + public bool IsT0 => _index == 0; public bool IsT1 => _index == 1; @@ -123,7 +127,7 @@ public bool TryPickT1(out T1 value, out T0 remainder) _ => throw new InvalidOperationException() }; return this.IsT1; - } + } bool Equals(OneOf other) => _index == other._index && @@ -165,4 +169,4 @@ public override int GetHashCode() } } } -} +} diff --git a/OneOf/OneOfT2.generated.cs b/OneOf/OneOfT2.generated.cs index 9e4e68c..c40ca64 100644 --- a/OneOf/OneOfT2.generated.cs +++ b/OneOf/OneOfT2.generated.cs @@ -10,7 +10,7 @@ namespace OneOf readonly T2 _value2; readonly int _index; - OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default) + internal OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default) { _index = index; _value0 = value0; @@ -29,6 +29,10 @@ namespace OneOf public int Index => _index; + public OneOf WithType() => + new OneOf(_index, _value0, _value1, _value2, default); + + public bool IsT0 => _index == 0; public bool IsT1 => _index == 1; public bool IsT2 => _index == 2; @@ -174,7 +178,7 @@ public bool TryPickT2(out T2 value, out OneOf remainder) _ => throw new InvalidOperationException() }; return this.IsT2; - } + } bool Equals(OneOf other) => _index == other._index && @@ -219,4 +223,4 @@ public override int GetHashCode() } } } -} +} diff --git a/OneOf/OneOfT3.generated.cs b/OneOf/OneOfT3.generated.cs index b6556fc..3bc98ec 100644 --- a/OneOf/OneOfT3.generated.cs +++ b/OneOf/OneOfT3.generated.cs @@ -11,7 +11,7 @@ namespace OneOf readonly T3 _value3; readonly int _index; - OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default) + internal OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default) { _index = index; _value0 = value0; @@ -32,6 +32,10 @@ namespace OneOf public int Index => _index; + public OneOf WithType() => + new OneOf(_index, _value0, _value1, _value2, _value3, default); + + public bool IsT0 => _index == 0; public bool IsT1 => _index == 1; public bool IsT2 => _index == 2; @@ -229,7 +233,7 @@ public bool TryPickT3(out T3 value, out OneOf remainder) _ => throw new InvalidOperationException() }; return this.IsT3; - } + } bool Equals(OneOf other) => _index == other._index && @@ -277,4 +281,4 @@ public override int GetHashCode() } } } -} +} diff --git a/OneOf/OneOfT4.generated.cs b/OneOf/OneOfT4.generated.cs index 38245fb..ec95c75 100644 --- a/OneOf/OneOfT4.generated.cs +++ b/OneOf/OneOfT4.generated.cs @@ -12,7 +12,7 @@ namespace OneOf readonly T4 _value4; readonly int _index; - OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default) + internal OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default) { _index = index; _value0 = value0; @@ -35,6 +35,10 @@ namespace OneOf public int Index => _index; + public OneOf WithType() => + new OneOf(_index, _value0, _value1, _value2, _value3, _value4, default); + + public bool IsT0 => _index == 0; public bool IsT1 => _index == 1; public bool IsT2 => _index == 2; @@ -288,7 +292,7 @@ public bool TryPickT4(out T4 value, out OneOf remainder) _ => throw new InvalidOperationException() }; return this.IsT4; - } + } bool Equals(OneOf other) => _index == other._index && @@ -339,4 +343,4 @@ public override int GetHashCode() } } } -} +} diff --git a/OneOf/OneOfT5.generated.cs b/OneOf/OneOfT5.generated.cs index 83ac23e..93510f8 100644 --- a/OneOf/OneOfT5.generated.cs +++ b/OneOf/OneOfT5.generated.cs @@ -13,7 +13,7 @@ namespace OneOf readonly T5 _value5; readonly int _index; - OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default) + internal OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default) { _index = index; _value0 = value0; @@ -38,6 +38,10 @@ namespace OneOf public int Index => _index; + public OneOf WithType() => + new OneOf(_index, _value0, _value1, _value2, _value3, _value4, _value5, default); + + public bool IsT0 => _index == 0; public bool IsT1 => _index == 1; public bool IsT2 => _index == 2; @@ -351,7 +355,7 @@ public bool TryPickT5(out T5 value, out OneOf remainder) _ => throw new InvalidOperationException() }; return this.IsT5; - } + } bool Equals(OneOf other) => _index == other._index && @@ -405,4 +409,4 @@ public override int GetHashCode() } } } -} +} diff --git a/OneOf/OneOfT6.generated.cs b/OneOf/OneOfT6.generated.cs index 9922c8a..54d69fb 100644 --- a/OneOf/OneOfT6.generated.cs +++ b/OneOf/OneOfT6.generated.cs @@ -14,7 +14,7 @@ namespace OneOf readonly T6 _value6; readonly int _index; - OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default) + internal OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default) { _index = index; _value0 = value0; @@ -41,6 +41,10 @@ namespace OneOf public int Index => _index; + public OneOf WithType() => + new OneOf(_index, _value0, _value1, _value2, _value3, _value4, _value5, _value6, default); + + public bool IsT0 => _index == 0; public bool IsT1 => _index == 1; public bool IsT2 => _index == 2; @@ -418,7 +422,7 @@ public bool TryPickT6(out T6 value, out OneOf remainder) _ => throw new InvalidOperationException() }; return this.IsT6; - } + } bool Equals(OneOf other) => _index == other._index && @@ -475,4 +479,4 @@ public override int GetHashCode() } } } -} +} diff --git a/OneOf/OneOfT7.generated.cs b/OneOf/OneOfT7.generated.cs index c0b0160..fd45993 100644 --- a/OneOf/OneOfT7.generated.cs +++ b/OneOf/OneOfT7.generated.cs @@ -15,7 +15,7 @@ namespace OneOf readonly T7 _value7; readonly int _index; - OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default) + internal OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default) { _index = index; _value0 = value0; @@ -44,6 +44,10 @@ namespace OneOf public int Index => _index; + public OneOf WithType() => + new OneOf(_index, _value0, _value1, _value2, _value3, _value4, _value5, _value6, _value7, default); + + public bool IsT0 => _index == 0; public bool IsT1 => _index == 1; public bool IsT2 => _index == 2; @@ -489,7 +493,7 @@ public bool TryPickT7(out T7 value, out OneOf remain _ => throw new InvalidOperationException() }; return this.IsT7; - } + } bool Equals(OneOf other) => _index == other._index && @@ -549,4 +553,4 @@ public override int GetHashCode() } } } -} +} diff --git a/OneOf/OneOfT8.generated.cs b/OneOf/OneOfT8.generated.cs index e040095..2720a29 100644 --- a/OneOf/OneOfT8.generated.cs +++ b/OneOf/OneOfT8.generated.cs @@ -16,7 +16,7 @@ namespace OneOf readonly T8 _value8; readonly int _index; - OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default) + internal OneOf(int index, T0 value0 = default, T1 value1 = default, T2 value2 = default, T3 value3 = default, T4 value4 = default, T5 value5 = default, T6 value6 = default, T7 value7 = default, T8 value8 = default) { _index = index; _value0 = value0; @@ -47,6 +47,8 @@ namespace OneOf public int Index => _index; + + public bool IsT0 => _index == 0; public bool IsT1 => _index == 1; public bool IsT2 => _index == 2; @@ -564,7 +566,7 @@ public bool TryPickT8(out T8 value, out OneOf re _ => throw new InvalidOperationException() }; return this.IsT8; - } + } bool Equals(OneOf other) => _index == other._index && @@ -627,4 +629,4 @@ public override int GetHashCode() } } } -} +} diff --git a/README.md b/README.md index beea4b1..72f9784 100644 --- a/README.md +++ b/README.md @@ -135,6 +135,35 @@ IActionResult Get(string id) } ``` +### WithType method + +In order that functions that return OneOf can call other functions that return +OneOf, the `.WithType()` method allows you to return existing OneOf structs but +with added types. + +**Note:** Unfortunately because of the extended assembly design, OneOf types with +over 8 parameters cannot use `.WithType`. + +```csharp +public OneOf ParseDouble(string input) { + if(double.TryParse(input, out var result)) { + return result; + } else { + return input; + } +} + +public OneOf ParseDoubleOrUTCDateOrInt (string input) { + if (DateTime.TryParseExact(input, "yyyy-MM-dd", CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeUniversal, out var dateResult)) { + return dateResult; + } else if (int.TryParse(input, out var intResult)) { + return intResult; + } else { + return ParseDouble(input).WithType().WithType(); + } +} +``` + ### Reusable OneOf Types using OneOfBase You can declare a OneOf as a type, either for reuse of the type, or to provide additional members, by inheriting from `OneOfBase`. The derived class will inherit the `.Match`, `.Switch`, and `.TryPick𝑥` methods.