forked from AArnott/ImmutableObjectGraph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Fruit.generated.cs
329 lines (261 loc) · 8.14 KB
/
Fruit.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
// ------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// ImmutableTree Version: 0.0.0.1
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
// ------------------------------------------------------------------------------
namespace ImmutableObjectGraph {
using System.Diagnostics;
/// <summary>
/// A wrapper around optional parameters to capture whether they were specified or omitted.
/// An implicit operator is defined so no one has to explicitly create this struct.
/// </summary>
public struct Optional<T> {
private readonly T value;
private readonly bool isDefined;
public Optional(T value) {
this.isDefined = true;
this.value = value;
}
public bool IsDefined {
get { return this.isDefined; }
}
public T Value {
get { return this.value; }
}
public static implicit operator Optional<T>(T value) {
return new Optional<T>(value);
}
}
public static class Optional {
public static Optional<T> For<T>(T value) {
return value;
}
}
public partial class Basket {
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private static readonly Basket DefaultInstance = new Basket();
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private readonly System.Int32 size;
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private readonly System.Collections.Immutable.IImmutableList<Fruit> contents;
/// <summary>Initializes a new instance of the Basket class.</summary>
private Basket()
{
}
/// <summary>Initializes a new instance of the Basket class.</summary>
private Basket(System.Int32 size, System.Collections.Immutable.IImmutableList<Fruit> contents)
{
this.size = size;
this.contents = contents;
this.Validate();
}
public static Basket Default {
get { return DefaultInstance; }
}
public System.Int32 Size {
get { return this.size; }
}
public Basket WithSize(System.Int32 value) {
if (value == this.Size) {
return this;
}
return new Basket(value, this.Contents);
}
public System.Collections.Immutable.IImmutableList<Fruit> Contents {
get { return this.contents; }
}
public Basket WithContents(System.Collections.Immutable.IImmutableList<Fruit> value) {
if (value == this.Contents) {
return this;
}
return new Basket(this.Size, value);
}
/// <summary>Returns a new instance of this object with any number of properties changed.</summary>
public Basket With(
Optional<System.Int32> size = default(Optional<System.Int32>),
Optional<System.Collections.Immutable.IImmutableList<Fruit>> contents = default(Optional<System.Collections.Immutable.IImmutableList<Fruit>>)) {
return new Basket(
size.IsDefined ? size.Value : this.Size,
contents.IsDefined ? contents.Value : this.Contents);
}
public Builder ToBuilder() {
return new Builder(this);
}
/// <summary>Normalizes and/or validates all properties on this object.</summary>
/// <exception type="ArgumentException">Thrown if any properties have disallowed values.</exception>
partial void Validate();
public partial class Builder {
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private Basket immutable;
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private System.Int32 size;
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private System.Collections.Immutable.IImmutableList<Fruit> contents;
internal Builder(Basket immutable) {
this.immutable = immutable;
this.size = immutable.Size;
this.contents = immutable.Contents;
}
public System.Int32 Size {
get {
return this.size;
}
set {
if (this.size != value) {
this.size = value;
this.immutable = null;
}
}
}
public System.Collections.Immutable.IImmutableList<Fruit> Contents {
get {
return this.contents;
}
set {
if (this.contents != value) {
this.contents = value;
this.immutable = null;
}
}
}
public Basket ToImmutable() {
if (this.immutable == null) {
this.immutable = Basket.Default.With(
Optional.For(this.size),
Optional.For(this.contents));
}
return this.immutable;
}
}
}
public partial class Fruit {
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private static readonly Fruit DefaultInstance = new Fruit();
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private readonly System.String color;
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private readonly System.Int32 skinThickness;
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private readonly System.ICloneable growsOn;
/// <summary>Initializes a new instance of the Fruit class.</summary>
private Fruit()
{
}
/// <summary>Initializes a new instance of the Fruit class.</summary>
private Fruit(System.String color, System.Int32 skinThickness, System.ICloneable growsOn)
{
this.color = color;
this.skinThickness = skinThickness;
this.growsOn = growsOn;
this.Validate();
}
public static Fruit Default {
get { return DefaultInstance; }
}
public System.String Color {
get { return this.color; }
}
public Fruit WithColor(System.String value) {
if (value == this.Color) {
return this;
}
return new Fruit(value, this.SkinThickness, this.GrowsOn);
}
public System.Int32 SkinThickness {
get { return this.skinThickness; }
}
public Fruit WithSkinThickness(System.Int32 value) {
if (value == this.SkinThickness) {
return this;
}
return new Fruit(this.Color, value, this.GrowsOn);
}
public System.ICloneable GrowsOn {
get { return this.growsOn; }
}
public Fruit WithGrowsOn(System.ICloneable value) {
if (value == this.GrowsOn) {
return this;
}
return new Fruit(this.Color, this.SkinThickness, value);
}
/// <summary>Returns a new instance of this object with any number of properties changed.</summary>
public Fruit With(
Optional<System.String> color = default(Optional<System.String>),
Optional<System.Int32> skinThickness = default(Optional<System.Int32>),
Optional<System.ICloneable> growsOn = default(Optional<System.ICloneable>)) {
return new Fruit(
color.IsDefined ? color.Value : this.Color,
skinThickness.IsDefined ? skinThickness.Value : this.SkinThickness,
growsOn.IsDefined ? growsOn.Value : this.GrowsOn);
}
public Builder ToBuilder() {
return new Builder(this);
}
/// <summary>Normalizes and/or validates all properties on this object.</summary>
/// <exception type="ArgumentException">Thrown if any properties have disallowed values.</exception>
partial void Validate();
public partial class Builder {
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private Fruit immutable;
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private System.String color;
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private System.Int32 skinThickness;
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private System.ICloneable growsOn;
internal Builder(Fruit immutable) {
this.immutable = immutable;
this.color = immutable.Color;
this.skinThickness = immutable.SkinThickness;
this.growsOn = immutable.GrowsOn;
}
public System.String Color {
get {
return this.color;
}
set {
if (this.color != value) {
this.color = value;
this.immutable = null;
}
}
}
public System.Int32 SkinThickness {
get {
return this.skinThickness;
}
set {
if (this.skinThickness != value) {
this.skinThickness = value;
this.immutable = null;
}
}
}
public System.ICloneable GrowsOn {
get {
return this.growsOn;
}
set {
if (this.growsOn != value) {
this.growsOn = value;
this.immutable = null;
}
}
}
public Fruit ToImmutable() {
if (this.immutable == null) {
this.immutable = Fruit.Default.With(
Optional.For(this.color),
Optional.For(this.skinThickness),
Optional.For(this.growsOn));
}
return this.immutable;
}
}
}
}