Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
WriteStack.cs
Go to the documentation of this file.
9
10namespace System.Text.Json;
11
12[DebuggerDisplay("Path:{PropertyPath()} Current: ConverterStrategy.{ConverterStrategy.JsonTypeInfo.PropertyInfoForTypeInfo.ConverterStrategy}, {Current.JsonTypeInfo.Type.Name}")]
13internal struct WriteStack
14{
16
18
19 private int _count;
20
21 private int _continuationCount;
22
24
25 public bool SuppressFlush;
26
28
30
31 public int FlushThreshold;
32
34
36
38
40
41 private void EnsurePushCapacity()
42 {
43 if (_stack == null)
44 {
45 _stack = new WriteStackFrame[4];
46 }
47 else if (_count - 1 == _stack.Length)
48 {
49 Array.Resize(ref _stack, 2 * _stack.Length);
50 }
51 }
52
58
60 {
62 Current.DeclaredJsonPropertyInfo = jsonTypeInfo.PropertyInfoForTypeInfo;
65 if (options.ReferenceHandlingStrategy != 0)
66 {
67 ReferenceResolver = options.ReferenceHandler.CreateResolver(writing: true);
68 }
70 return jsonTypeInfo.PropertyInfoForTypeInfo.ConverterBase;
71 }
72
73 public void Push()
74 {
75 if (_continuationCount == 0)
76 {
77 if (_count == 0)
78 {
79 _count = 1;
80 return;
81 }
85 _stack[_count - 1] = Current;
86 Current = default(WriteStackFrame);
87 _count++;
89 Current.DeclaredJsonPropertyInfo = runtimeTypeInfo.PropertyInfoForTypeInfo;
91 }
92 else
93 {
94 if (_count++ > 0)
95 {
96 Current = _stack[_count - 1];
97 }
99 {
101 }
102 }
103 }
104
105 public void Pop(bool success)
106 {
107 if (!success)
108 {
109 if (_continuationCount == 0)
110 {
111 if (_count == 1)
112 {
114 _count = 0;
115 return;
116 }
119 }
120 else if (--_count == 0)
121 {
122 return;
123 }
125 Current = _stack[_count - 1];
126 }
127 else if (--_count > 0)
128 {
129 Current = _stack[_count - 1];
130 }
131 }
132
137
139 {
140 Exception exception = null;
142 {
143 try
144 {
145 await completedAsyncDisposable.DisposeAsync().ConfigureAwait(continueOnCapturedContext: false);
146 }
147 catch (Exception ex)
148 {
149 exception = ex;
150 }
151 }
152 if (exception != null)
153 {
155 }
157 }
158
160 {
161 Exception exception2 = null;
163 int num = Math.Max(_count, _continuationCount);
164 for (int i = 0; i < num - 1; i++)
165 {
166 DisposeFrame(_stack[i].CollectionEnumerator, ref exception2);
167 }
168 if (exception2 != null)
169 {
171 }
173 {
174 try
175 {
177 {
178 disposable.Dispose();
179 }
180 }
181 catch (Exception ex)
182 {
183 exception = ex;
184 }
185 }
186 }
187
189 {
190 Exception exception2 = null;
193 for (int i = 0; i < stackSize - 1; i++)
194 {
195 exception2 = await DisposeFrame(_stack[i].CollectionEnumerator, _stack[i].AsyncDisposable, exception2).ConfigureAwait(continueOnCapturedContext: false);
196 }
197 if (exception2 != null)
198 {
200 }
202 {
203 try
204 {
206 {
207 disposable.Dispose();
208 }
209 else if (asyncDisposable != null)
210 {
211 await asyncDisposable.DisposeAsync().ConfigureAwait(continueOnCapturedContext: false);
212 }
213 }
214 catch (Exception ex)
215 {
216 exception = ex;
217 }
218 return exception;
219 }
220 }
221
222 public string PropertyPath()
223 {
225 int num = Math.Max(_count, _continuationCount);
226 for (int i = 0; i < num - 1; i++)
227 {
229 }
230 if (_continuationCount == 0)
231 {
233 }
234 return stringBuilder.ToString();
235 static void AppendPropertyName(StringBuilder sb, string propertyName)
236 {
237 if (propertyName != null)
238 {
239 if (propertyName.IndexOfAny(ReadStack.SpecialCharacters) != -1)
240 {
241 sb.Append("['");
243 sb.Append("']");
244 }
245 else
246 {
247 sb.Append('.');
249 }
250 }
251 }
253 {
254 string text = frame.DeclaredJsonPropertyInfo?.ClrName;
255 if (text == null)
256 {
257 text = frame.JsonPropertyNameAsString;
258 }
260 }
261 }
262}
void Add(TKey key, TValue value)
static byte Max(byte val1, byte val2)
Definition Math.cs:738
static ExceptionDispatchInfo Capture(Exception source)
StringBuilder Append(char value, int repeatCount)
static readonly char[] SpecialCharacters
Definition ReadStack.cs:13
JsonPropertyInfo DeclaredJsonPropertyInfo
JsonPropertyInfo GetPolymorphicJsonPropertyInfo()
void AddCompletedAsyncDisposable(IAsyncDisposable asyncDisposable)
ReferenceResolver ReferenceResolver
Definition WriteStack.cs:33
async ValueTask DisposePendingDisposablesOnExceptionAsync()
async ValueTask DisposeCompletedAsyncDisposables()
void Pop(bool success)
JsonConverter Initialize(JsonTypeInfo jsonTypeInfo, bool supportContinuation)
Definition WriteStack.cs:59
WriteStackFrame Current
Definition WriteStack.cs:15
JsonConverter Initialize(Type type, JsonSerializerOptions options, bool supportContinuation)
Definition WriteStack.cs:53
CancellationToken CancellationToken
Definition WriteStack.cs:23
List< IAsyncDisposable > CompletedAsyncDisposables
Definition WriteStack.cs:29
void DisposePendingDisposablesOnException()
WriteStackFrame[] _stack
Definition WriteStack.cs:17