-
Notifications
You must be signed in to change notification settings - Fork 167
/
OneOfBaseT13.generated.cs
699 lines (665 loc) · 21.8 KB
/
OneOfBaseT13.generated.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
using System;
using static OneOf.Functions;
namespace OneOf
{
public class OneOfBase<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13> : IOneOf
{
readonly T0 _value0;
readonly T1 _value1;
readonly T2 _value2;
readonly T3 _value3;
readonly T4 _value4;
readonly T5 _value5;
readonly T6 _value6;
readonly T7 _value7;
readonly T8 _value8;
readonly T9 _value9;
readonly T10 _value10;
readonly T11 _value11;
readonly T12 _value12;
readonly T13 _value13;
readonly int _index;
protected OneOfBase(OneOf<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13> input)
{
_index = input.Index;
switch (_index)
{
case 0: _value0 = input.AsT0; break;
case 1: _value1 = input.AsT1; break;
case 2: _value2 = input.AsT2; break;
case 3: _value3 = input.AsT3; break;
case 4: _value4 = input.AsT4; break;
case 5: _value5 = input.AsT5; break;
case 6: _value6 = input.AsT6; break;
case 7: _value7 = input.AsT7; break;
case 8: _value8 = input.AsT8; break;
case 9: _value9 = input.AsT9; break;
case 10: _value10 = input.AsT10; break;
case 11: _value11 = input.AsT11; break;
case 12: _value12 = input.AsT12; break;
case 13: _value13 = input.AsT13; break;
default: throw new InvalidOperationException();
}
}
public object Value =>
_index switch
{
0 => _value0,
1 => _value1,
2 => _value2,
3 => _value3,
4 => _value4,
5 => _value5,
6 => _value6,
7 => _value7,
8 => _value8,
9 => _value9,
10 => _value10,
11 => _value11,
12 => _value12,
13 => _value13,
_ => throw new InvalidOperationException()
};
public int Index => _index;
public bool IsT0 => _index == 0;
public bool IsT1 => _index == 1;
public bool IsT2 => _index == 2;
public bool IsT3 => _index == 3;
public bool IsT4 => _index == 4;
public bool IsT5 => _index == 5;
public bool IsT6 => _index == 6;
public bool IsT7 => _index == 7;
public bool IsT8 => _index == 8;
public bool IsT9 => _index == 9;
public bool IsT10 => _index == 10;
public bool IsT11 => _index == 11;
public bool IsT12 => _index == 12;
public bool IsT13 => _index == 13;
public T0 AsT0 =>
_index == 0 ?
_value0 :
throw new InvalidOperationException($"Cannot return as T0 as result is T{_index}");
public T1 AsT1 =>
_index == 1 ?
_value1 :
throw new InvalidOperationException($"Cannot return as T1 as result is T{_index}");
public T2 AsT2 =>
_index == 2 ?
_value2 :
throw new InvalidOperationException($"Cannot return as T2 as result is T{_index}");
public T3 AsT3 =>
_index == 3 ?
_value3 :
throw new InvalidOperationException($"Cannot return as T3 as result is T{_index}");
public T4 AsT4 =>
_index == 4 ?
_value4 :
throw new InvalidOperationException($"Cannot return as T4 as result is T{_index}");
public T5 AsT5 =>
_index == 5 ?
_value5 :
throw new InvalidOperationException($"Cannot return as T5 as result is T{_index}");
public T6 AsT6 =>
_index == 6 ?
_value6 :
throw new InvalidOperationException($"Cannot return as T6 as result is T{_index}");
public T7 AsT7 =>
_index == 7 ?
_value7 :
throw new InvalidOperationException($"Cannot return as T7 as result is T{_index}");
public T8 AsT8 =>
_index == 8 ?
_value8 :
throw new InvalidOperationException($"Cannot return as T8 as result is T{_index}");
public T9 AsT9 =>
_index == 9 ?
_value9 :
throw new InvalidOperationException($"Cannot return as T9 as result is T{_index}");
public T10 AsT10 =>
_index == 10 ?
_value10 :
throw new InvalidOperationException($"Cannot return as T10 as result is T{_index}");
public T11 AsT11 =>
_index == 11 ?
_value11 :
throw new InvalidOperationException($"Cannot return as T11 as result is T{_index}");
public T12 AsT12 =>
_index == 12 ?
_value12 :
throw new InvalidOperationException($"Cannot return as T12 as result is T{_index}");
public T13 AsT13 =>
_index == 13 ?
_value13 :
throw new InvalidOperationException($"Cannot return as T13 as result is T{_index}");
public void Switch(Action<T0> f0, Action<T1> f1, Action<T2> f2, Action<T3> f3, Action<T4> f4, Action<T5> f5, Action<T6> f6, Action<T7> f7, Action<T8> f8, Action<T9> f9, Action<T10> f10, Action<T11> f11, Action<T12> f12, Action<T13> f13)
{
if (_index == 0 && f0 != null)
{
f0(_value0);
return;
}
if (_index == 1 && f1 != null)
{
f1(_value1);
return;
}
if (_index == 2 && f2 != null)
{
f2(_value2);
return;
}
if (_index == 3 && f3 != null)
{
f3(_value3);
return;
}
if (_index == 4 && f4 != null)
{
f4(_value4);
return;
}
if (_index == 5 && f5 != null)
{
f5(_value5);
return;
}
if (_index == 6 && f6 != null)
{
f6(_value6);
return;
}
if (_index == 7 && f7 != null)
{
f7(_value7);
return;
}
if (_index == 8 && f8 != null)
{
f8(_value8);
return;
}
if (_index == 9 && f9 != null)
{
f9(_value9);
return;
}
if (_index == 10 && f10 != null)
{
f10(_value10);
return;
}
if (_index == 11 && f11 != null)
{
f11(_value11);
return;
}
if (_index == 12 && f12 != null)
{
f12(_value12);
return;
}
if (_index == 13 && f13 != null)
{
f13(_value13);
return;
}
throw new InvalidOperationException();
}
public TResult Match<TResult>(Func<T0, TResult> f0, Func<T1, TResult> f1, Func<T2, TResult> f2, Func<T3, TResult> f3, Func<T4, TResult> f4, Func<T5, TResult> f5, Func<T6, TResult> f6, Func<T7, TResult> f7, Func<T8, TResult> f8, Func<T9, TResult> f9, Func<T10, TResult> f10, Func<T11, TResult> f11, Func<T12, TResult> f12, Func<T13, TResult> f13)
{
if (_index == 0 && f0 != null)
{
return f0(_value0);
}
if (_index == 1 && f1 != null)
{
return f1(_value1);
}
if (_index == 2 && f2 != null)
{
return f2(_value2);
}
if (_index == 3 && f3 != null)
{
return f3(_value3);
}
if (_index == 4 && f4 != null)
{
return f4(_value4);
}
if (_index == 5 && f5 != null)
{
return f5(_value5);
}
if (_index == 6 && f6 != null)
{
return f6(_value6);
}
if (_index == 7 && f7 != null)
{
return f7(_value7);
}
if (_index == 8 && f8 != null)
{
return f8(_value8);
}
if (_index == 9 && f9 != null)
{
return f9(_value9);
}
if (_index == 10 && f10 != null)
{
return f10(_value10);
}
if (_index == 11 && f11 != null)
{
return f11(_value11);
}
if (_index == 12 && f12 != null)
{
return f12(_value12);
}
if (_index == 13 && f13 != null)
{
return f13(_value13);
}
throw new InvalidOperationException();
}
public bool TryPickT0(out T0 value, out OneOf<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13> remainder)
{
value = IsT0 ? AsT0 : default;
remainder = _index switch
{
0 => default,
1 => AsT1,
2 => AsT2,
3 => AsT3,
4 => AsT4,
5 => AsT5,
6 => AsT6,
7 => AsT7,
8 => AsT8,
9 => AsT9,
10 => AsT10,
11 => AsT11,
12 => AsT12,
13 => AsT13,
_ => throw new InvalidOperationException()
};
return this.IsT0;
}
public bool TryPickT1(out T1 value, out OneOf<T0, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13> remainder)
{
value = IsT1 ? AsT1 : default;
remainder = _index switch
{
0 => AsT0,
1 => default,
2 => AsT2,
3 => AsT3,
4 => AsT4,
5 => AsT5,
6 => AsT6,
7 => AsT7,
8 => AsT8,
9 => AsT9,
10 => AsT10,
11 => AsT11,
12 => AsT12,
13 => AsT13,
_ => throw new InvalidOperationException()
};
return this.IsT1;
}
public bool TryPickT2(out T2 value, out OneOf<T0, T1, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13> remainder)
{
value = IsT2 ? AsT2 : default;
remainder = _index switch
{
0 => AsT0,
1 => AsT1,
2 => default,
3 => AsT3,
4 => AsT4,
5 => AsT5,
6 => AsT6,
7 => AsT7,
8 => AsT8,
9 => AsT9,
10 => AsT10,
11 => AsT11,
12 => AsT12,
13 => AsT13,
_ => throw new InvalidOperationException()
};
return this.IsT2;
}
public bool TryPickT3(out T3 value, out OneOf<T0, T1, T2, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13> remainder)
{
value = IsT3 ? AsT3 : default;
remainder = _index switch
{
0 => AsT0,
1 => AsT1,
2 => AsT2,
3 => default,
4 => AsT4,
5 => AsT5,
6 => AsT6,
7 => AsT7,
8 => AsT8,
9 => AsT9,
10 => AsT10,
11 => AsT11,
12 => AsT12,
13 => AsT13,
_ => throw new InvalidOperationException()
};
return this.IsT3;
}
public bool TryPickT4(out T4 value, out OneOf<T0, T1, T2, T3, T5, T6, T7, T8, T9, T10, T11, T12, T13> remainder)
{
value = IsT4 ? AsT4 : default;
remainder = _index switch
{
0 => AsT0,
1 => AsT1,
2 => AsT2,
3 => AsT3,
4 => default,
5 => AsT5,
6 => AsT6,
7 => AsT7,
8 => AsT8,
9 => AsT9,
10 => AsT10,
11 => AsT11,
12 => AsT12,
13 => AsT13,
_ => throw new InvalidOperationException()
};
return this.IsT4;
}
public bool TryPickT5(out T5 value, out OneOf<T0, T1, T2, T3, T4, T6, T7, T8, T9, T10, T11, T12, T13> remainder)
{
value = IsT5 ? AsT5 : default;
remainder = _index switch
{
0 => AsT0,
1 => AsT1,
2 => AsT2,
3 => AsT3,
4 => AsT4,
5 => default,
6 => AsT6,
7 => AsT7,
8 => AsT8,
9 => AsT9,
10 => AsT10,
11 => AsT11,
12 => AsT12,
13 => AsT13,
_ => throw new InvalidOperationException()
};
return this.IsT5;
}
public bool TryPickT6(out T6 value, out OneOf<T0, T1, T2, T3, T4, T5, T7, T8, T9, T10, T11, T12, T13> remainder)
{
value = IsT6 ? AsT6 : default;
remainder = _index switch
{
0 => AsT0,
1 => AsT1,
2 => AsT2,
3 => AsT3,
4 => AsT4,
5 => AsT5,
6 => default,
7 => AsT7,
8 => AsT8,
9 => AsT9,
10 => AsT10,
11 => AsT11,
12 => AsT12,
13 => AsT13,
_ => throw new InvalidOperationException()
};
return this.IsT6;
}
public bool TryPickT7(out T7 value, out OneOf<T0, T1, T2, T3, T4, T5, T6, T8, T9, T10, T11, T12, T13> remainder)
{
value = IsT7 ? AsT7 : default;
remainder = _index switch
{
0 => AsT0,
1 => AsT1,
2 => AsT2,
3 => AsT3,
4 => AsT4,
5 => AsT5,
6 => AsT6,
7 => default,
8 => AsT8,
9 => AsT9,
10 => AsT10,
11 => AsT11,
12 => AsT12,
13 => AsT13,
_ => throw new InvalidOperationException()
};
return this.IsT7;
}
public bool TryPickT8(out T8 value, out OneOf<T0, T1, T2, T3, T4, T5, T6, T7, T9, T10, T11, T12, T13> remainder)
{
value = IsT8 ? AsT8 : default;
remainder = _index switch
{
0 => AsT0,
1 => AsT1,
2 => AsT2,
3 => AsT3,
4 => AsT4,
5 => AsT5,
6 => AsT6,
7 => AsT7,
8 => default,
9 => AsT9,
10 => AsT10,
11 => AsT11,
12 => AsT12,
13 => AsT13,
_ => throw new InvalidOperationException()
};
return this.IsT8;
}
public bool TryPickT9(out T9 value, out OneOf<T0, T1, T2, T3, T4, T5, T6, T7, T8, T10, T11, T12, T13> remainder)
{
value = IsT9 ? AsT9 : default;
remainder = _index switch
{
0 => AsT0,
1 => AsT1,
2 => AsT2,
3 => AsT3,
4 => AsT4,
5 => AsT5,
6 => AsT6,
7 => AsT7,
8 => AsT8,
9 => default,
10 => AsT10,
11 => AsT11,
12 => AsT12,
13 => AsT13,
_ => throw new InvalidOperationException()
};
return this.IsT9;
}
public bool TryPickT10(out T10 value, out OneOf<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T11, T12, T13> remainder)
{
value = IsT10 ? AsT10 : default;
remainder = _index switch
{
0 => AsT0,
1 => AsT1,
2 => AsT2,
3 => AsT3,
4 => AsT4,
5 => AsT5,
6 => AsT6,
7 => AsT7,
8 => AsT8,
9 => AsT9,
10 => default,
11 => AsT11,
12 => AsT12,
13 => AsT13,
_ => throw new InvalidOperationException()
};
return this.IsT10;
}
public bool TryPickT11(out T11 value, out OneOf<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T12, T13> remainder)
{
value = IsT11 ? AsT11 : default;
remainder = _index switch
{
0 => AsT0,
1 => AsT1,
2 => AsT2,
3 => AsT3,
4 => AsT4,
5 => AsT5,
6 => AsT6,
7 => AsT7,
8 => AsT8,
9 => AsT9,
10 => AsT10,
11 => default,
12 => AsT12,
13 => AsT13,
_ => throw new InvalidOperationException()
};
return this.IsT11;
}
public bool TryPickT12(out T12 value, out OneOf<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T13> remainder)
{
value = IsT12 ? AsT12 : default;
remainder = _index switch
{
0 => AsT0,
1 => AsT1,
2 => AsT2,
3 => AsT3,
4 => AsT4,
5 => AsT5,
6 => AsT6,
7 => AsT7,
8 => AsT8,
9 => AsT9,
10 => AsT10,
11 => AsT11,
12 => default,
13 => AsT13,
_ => throw new InvalidOperationException()
};
return this.IsT12;
}
public bool TryPickT13(out T13 value, out OneOf<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> remainder)
{
value = IsT13 ? AsT13 : default;
remainder = _index switch
{
0 => AsT0,
1 => AsT1,
2 => AsT2,
3 => AsT3,
4 => AsT4,
5 => AsT5,
6 => AsT6,
7 => AsT7,
8 => AsT8,
9 => AsT9,
10 => AsT10,
11 => AsT11,
12 => AsT12,
13 => default,
_ => throw new InvalidOperationException()
};
return this.IsT13;
}
bool Equals(OneOfBase<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13> other) =>
_index == other._index &&
_index switch
{
0 => Equals(_value0, other._value0),
1 => Equals(_value1, other._value1),
2 => Equals(_value2, other._value2),
3 => Equals(_value3, other._value3),
4 => Equals(_value4, other._value4),
5 => Equals(_value5, other._value5),
6 => Equals(_value6, other._value6),
7 => Equals(_value7, other._value7),
8 => Equals(_value8, other._value8),
9 => Equals(_value9, other._value9),
10 => Equals(_value10, other._value10),
11 => Equals(_value11, other._value11),
12 => Equals(_value12, other._value12),
13 => Equals(_value13, other._value13),
_ => false
};
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
if (ReferenceEquals(this, obj)) {
return true;
}
return obj is OneOfBase<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13> o && Equals(o);
}
public override string ToString() =>
_index switch {
0 => FormatValue(_value0),
1 => FormatValue(_value1),
2 => FormatValue(_value2),
3 => FormatValue(_value3),
4 => FormatValue(_value4),
5 => FormatValue(_value5),
6 => FormatValue(_value6),
7 => FormatValue(_value7),
8 => FormatValue(_value8),
9 => FormatValue(_value9),
10 => FormatValue(_value10),
11 => FormatValue(_value11),
12 => FormatValue(_value12),
13 => FormatValue(_value13),
_ => throw new InvalidOperationException("Unexpected index, which indicates a problem in the OneOf codegen.")
};
public override int GetHashCode()
{
unchecked
{
int hashCode = _index switch
{
0 => _value0?.GetHashCode(),
1 => _value1?.GetHashCode(),
2 => _value2?.GetHashCode(),
3 => _value3?.GetHashCode(),
4 => _value4?.GetHashCode(),
5 => _value5?.GetHashCode(),
6 => _value6?.GetHashCode(),
7 => _value7?.GetHashCode(),
8 => _value8?.GetHashCode(),
9 => _value9?.GetHashCode(),
10 => _value10?.GetHashCode(),
11 => _value11?.GetHashCode(),
12 => _value12?.GetHashCode(),
13 => _value13?.GetHashCode(),
_ => 0
} ?? 0;
return (hashCode*397) ^ _index;
}
}
}
}