-
Notifications
You must be signed in to change notification settings - Fork 167
/
OneOfBaseT10.generated.cs
534 lines (503 loc) · 16.4 KB
/
OneOfBaseT10.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
using System;
using static OneOf.Functions;
namespace OneOf
{
public class OneOfBase<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> : 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 int _index;
protected OneOfBase(OneOf<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> 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;
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,
_ => 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 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 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)
{
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;
}
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)
{
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);
}
throw new InvalidOperationException();
}
public bool TryPickT0(out T0 value, out OneOf<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> 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,
_ => throw new InvalidOperationException()
};
return this.IsT0;
}
public bool TryPickT1(out T1 value, out OneOf<T0, T2, T3, T4, T5, T6, T7, T8, T9, T10> 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,
_ => throw new InvalidOperationException()
};
return this.IsT1;
}
public bool TryPickT2(out T2 value, out OneOf<T0, T1, T3, T4, T5, T6, T7, T8, T9, T10> 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,
_ => throw new InvalidOperationException()
};
return this.IsT2;
}
public bool TryPickT3(out T3 value, out OneOf<T0, T1, T2, T4, T5, T6, T7, T8, T9, T10> 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,
_ => throw new InvalidOperationException()
};
return this.IsT3;
}
public bool TryPickT4(out T4 value, out OneOf<T0, T1, T2, T3, T5, T6, T7, T8, T9, T10> 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,
_ => throw new InvalidOperationException()
};
return this.IsT4;
}
public bool TryPickT5(out T5 value, out OneOf<T0, T1, T2, T3, T4, T6, T7, T8, T9, T10> 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,
_ => throw new InvalidOperationException()
};
return this.IsT5;
}
public bool TryPickT6(out T6 value, out OneOf<T0, T1, T2, T3, T4, T5, T7, T8, T9, T10> 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,
_ => throw new InvalidOperationException()
};
return this.IsT6;
}
public bool TryPickT7(out T7 value, out OneOf<T0, T1, T2, T3, T4, T5, T6, T8, T9, T10> 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,
_ => throw new InvalidOperationException()
};
return this.IsT7;
}
public bool TryPickT8(out T8 value, out OneOf<T0, T1, T2, T3, T4, T5, T6, T7, T9, T10> 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,
_ => throw new InvalidOperationException()
};
return this.IsT8;
}
public bool TryPickT9(out T9 value, out OneOf<T0, T1, T2, T3, T4, T5, T6, T7, T8, T10> 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,
_ => throw new InvalidOperationException()
};
return this.IsT9;
}
public bool TryPickT10(out T10 value, out OneOf<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> 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,
_ => throw new InvalidOperationException()
};
return this.IsT10;
}
bool Equals(OneOfBase<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> 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),
_ => 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> 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),
_ => 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(),
_ => 0
} ?? 0;
return (hashCode*397) ^ _index;
}
}
}
}