-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPatchOperationListBuilder.cs
More file actions
164 lines (139 loc) · 5.08 KB
/
PatchOperationListBuilder.cs
File metadata and controls
164 lines (139 loc) · 5.08 KB
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
using Microsoft.Azure.Cosmos;
using Newtonsoft.Json.Linq;
using System.Reflection;
namespace CosmosDBPartialUpdateTypeConverter
{
//Possibly need more work
public class PatchOperationListBuilder(List<PatchOperation> _patchOperations)
{
public PatchOperationListBuilder() : this(new List<PatchOperation>()) { }
public PatchOperationListBuilder(IEnumerable<PatchOperation> patchOperations) : this(patchOperations.ToList()) { }
public PatchOperationListBuilder(PatchOperation patchOperation) : this(new List<PatchOperation> { patchOperation }) { }
public PatchOperationListBuilder(params PatchOperation[] patchOperations) : this(patchOperations.AsEnumerable()) { }
public PatchOperationListBuilder With(PatchOperation patchOperation)
{
ArgumentNullException.ThrowIfNull(patchOperation, nameof(patchOperation));
_patchOperations.Add(patchOperation);
return this;
}
public PatchOperationListBuilder With(IEnumerable<PatchOperation> entities)
{
_patchOperations.AddRange(entities);
return this;
}
public PatchOperationListBuilder With(List<PatchOperation> entities)
{
_patchOperations.AddRange(entities);
return this;
}
public PatchOperationListBuilder With(params PatchOperation[] patchOperations)
{
_patchOperations.AddRange(patchOperations);
return this;
}
public PatchOperationListBuilder WithAdd(string path, object? value)
{
_patchOperations.Add(path, value);
return this;
}
public PatchOperationListBuilder WithAdd<T>(string path, T? value)
{
_patchOperations.Add(path, value);
return this;
}
public PatchOperationListBuilder WithAdd(JObject value)
{
ArgumentNullException.ThrowIfNull(value, nameof(value));
_patchOperations.Add(value);
return this;
}
public PatchOperationListBuilder WithAdd<T>(T entity)
where T : class
{
_patchOperations.Add(entity);
return this;
}
public PatchOperationListBuilder WithAdd<T>(IEnumerable<T> entities)
where T : class
{
_patchOperations.Add(entities);
return this;
}
public PatchOperationListBuilder WithAdd<T>(params T[] entities)
where T : class
{
_patchOperations.Add(entities);
return this;
}
public PatchOperationListBuilder WithAdd(object value, Func<PropertyInfo, bool>? propertyInfoFilter = null)
{
_patchOperations.Add(value, propertyInfoFilter);
return this;
}
public PatchOperationListBuilder WithAddAppend(string path, object? value)
{
_patchOperations.AddAppend(path, value);
return this;
}
public PatchOperationListBuilder WithIncrement(string path, long value)
{
_patchOperations.AddIncrement(path, value);
return this;
}
public PatchOperationListBuilder WithMove(string from, string path)
{
_patchOperations.AddMove(from, path);
return this;
}
public PatchOperationListBuilder WithRemove(string path)
{
_patchOperations.AddRemove(path);
return this;
}
public PatchOperationListBuilder WithReplace(string path, object? value)
{
_patchOperations.AddReplace(path, value);
return this;
}
public PatchOperationListBuilder WithSet(string path, object? value)
{
_patchOperations.AddSet(path, value);
return this;
}
public PatchOperationListBuilder WithSet<T>(string path, T? value)
{
_patchOperations.AddSet(path, value);
return this;
}
public PatchOperationListBuilder WithSet(JObject value)
{
ArgumentNullException.ThrowIfNull(value, nameof(value));
_patchOperations.AddSet(value);
return this;
}
public PatchOperationListBuilder WithSet<T>(T entity)
where T : class
{
_patchOperations.AddSet(entity);
return this;
}
public PatchOperationListBuilder WithSet<T>(IEnumerable<T> entities)
where T : class
{
_patchOperations.AddSet(entities);
return this;
}
public PatchOperationListBuilder WithSet<T>(params T[] entities)
where T : class
{
_patchOperations.AddSet(entities);
return this;
}
public PatchOperationListBuilder WithSet(object value, Func<PropertyInfo, bool>? propertyInfoFilter = null)
{
_patchOperations.AddSet(value, propertyInfoFilter);
return this;
}
public PatchOperationList Build() => _patchOperations.Where(op=> op is not null).ToList();
}
}