Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
CodeTypeReference.cs
Go to the documentation of this file.
2
4
5internal sealed class CodeTypeReference : CodeObject
6{
7 private string _baseType;
8
9 private readonly bool _isInterface;
10
12
13 private bool _needsFixup;
14
16
17 public int ArrayRank { get; set; }
18
19 internal int NestedArrayDepth
20 {
21 get
22 {
23 if (ArrayElementType != null)
24 {
26 }
27 return 0;
28 }
29 }
30
31 public string BaseType
32 {
33 get
34 {
35 if (ArrayRank > 0 && ArrayElementType != null)
36 {
38 }
39 if (string.IsNullOrEmpty(_baseType))
40 {
41 return string.Empty;
42 }
43 string baseType = _baseType;
44 if (!_needsFixup || TypeArguments.Count <= 0)
45 {
46 return baseType;
47 }
48 return $"{baseType}`{TypeArguments.Count}";
49 }
50 set
51 {
54 }
55 }
56
57 public CodeTypeReferenceOptions Options { get; set; }
58
60 {
61 get
62 {
63 if (ArrayRank > 0 && ArrayElementType != null)
64 {
66 }
67 if (_typeArguments == null)
68 {
70 }
71 return _typeArguments;
72 }
73 }
74
75 internal bool IsInterface => _isInterface;
76
78 {
79 _baseType = string.Empty;
80 ArrayRank = 0;
81 ArrayElementType = null;
82 }
83
85 {
86 if (type == null)
87 {
88 throw new ArgumentNullException("type");
89 }
90 if (type.IsArray)
91 {
92 ArrayRank = type.GetArrayRank();
93 ArrayElementType = new CodeTypeReference(type.GetElementType());
94 _baseType = null;
95 }
96 else
97 {
99 ArrayRank = 0;
100 ArrayElementType = null;
101 }
102 _isInterface = type.IsInterface;
103 }
104
110
115
116 public CodeTypeReference(string typeName)
117 {
118 Initialize(typeName);
119 }
120
122 {
123 _baseType = type.Name;
124 if (!type.IsGenericParameter)
125 {
126 Type type2 = type;
127 while (type2.IsNested)
128 {
129 type2 = type2.DeclaringType;
131 }
132 if (!string.IsNullOrEmpty(type.Namespace))
133 {
135 }
136 }
137 if (type.IsGenericType && !type.ContainsGenericParameters)
138 {
139 Type[] genericArguments = type.GetGenericArguments();
140 for (int i = 0; i < genericArguments.Length; i++)
141 {
143 }
144 }
145 else if (!type.IsGenericTypeDefinition)
146 {
147 _needsFixup = true;
148 }
149 }
150
151 private void Initialize(string typeName)
152 {
153 Initialize(typeName, Options);
154 }
155
156 private void Initialize(string typeName, CodeTypeReferenceOptions options)
157 {
159 if (string.IsNullOrEmpty(typeName))
160 {
161 typeName = typeof(void).FullName;
162 _baseType = typeName;
163 ArrayRank = 0;
164 ArrayElementType = null;
165 return;
166 }
167 typeName = RipOffAssemblyInformationFromTypeName(typeName);
168 int num = typeName.Length - 1;
169 int num2 = num;
170 _needsFixup = true;
172 while (num2 >= 0)
173 {
174 int num3 = 1;
175 if (typeName[num2--] != ']')
176 {
177 break;
178 }
179 while (num2 >= 0 && typeName[num2] == ',')
180 {
181 num3++;
182 num2--;
183 }
184 if (num2 < 0 || typeName[num2] != '[')
185 {
186 break;
187 }
188 queue.Enqueue(num3);
189 num2--;
190 num = num2;
191 }
192 num2 = num;
194 Stack<string> stack = new Stack<string>();
195 if (num2 > 0 && typeName[num2--] == ']')
196 {
197 _needsFixup = false;
198 int num4 = 1;
199 int num5 = num;
200 while (num2 >= 0)
201 {
202 if (typeName[num2] == '[')
203 {
204 if (--num4 == 0)
205 {
206 break;
207 }
208 }
209 else if (typeName[num2] == ']')
210 {
211 num4++;
212 }
213 else if (typeName[num2] == ',' && num4 == 1)
214 {
215 if (num2 + 1 < num5)
216 {
217 stack.Push(typeName.Substring(num2 + 1, num5 - num2 - 1));
218 }
219 num5 = num2;
220 }
221 num2--;
222 }
223 if (num2 > 0 && num - num2 - 1 > 0)
224 {
225 if (num2 + 1 < num5)
226 {
227 stack.Push(typeName.Substring(num2 + 1, num5 - num2 - 1));
228 }
229 while (stack.Count > 0)
230 {
233 }
234 num = num2 - 1;
235 }
236 }
237 if (num < 0)
238 {
239 _baseType = typeName;
240 return;
241 }
242 if (queue.Count > 0)
243 {
244 CodeTypeReference codeTypeReference = new CodeTypeReference(typeName.Substring(0, num + 1), Options);
245 for (int i = 0; i < list.Count; i++)
246 {
247 codeTypeReference.TypeArguments.Add(list[i]);
248 }
249 while (queue.Count > 1)
250 {
252 }
253 _baseType = null;
254 ArrayRank = queue.Dequeue();
256 }
257 else if (list.Count > 0)
258 {
259 for (int j = 0; j < list.Count; j++)
260 {
262 }
263 _baseType = typeName.Substring(0, num + 1);
264 }
265 else
266 {
267 _baseType = typeName;
268 }
269 if (_baseType != null && _baseType.IndexOf('`') != -1)
270 {
271 _needsFixup = false;
272 }
273 }
274
276 : this(typeName)
277 {
278 if (typeArguments != null && typeArguments.Length != 0)
279 {
281 }
282 }
283
284 public CodeTypeReference(string baseType, int rank)
285 {
286 _baseType = null;
287 ArrayRank = rank;
289 }
290
297
298 private string RipOffAssemblyInformationFromTypeName(string typeName)
299 {
300 int i = 0;
301 int num = typeName.Length - 1;
302 string result = typeName;
303 for (; i < typeName.Length && char.IsWhiteSpace(typeName[i]); i++)
304 {
305 }
306 while (num >= 0 && char.IsWhiteSpace(typeName[num]))
307 {
308 num--;
309 }
310 if (i < num)
311 {
312 if (typeName[i] == '[' && typeName[num] == ']')
313 {
314 i++;
315 num--;
316 }
317 if (typeName[num] != ']')
318 {
319 int num2 = 0;
320 for (int num3 = num; num3 >= i; num3--)
321 {
322 if (typeName[num3] == ',')
323 {
324 num2++;
325 if (num2 == 4)
326 {
327 result = typeName.Substring(i, num3 - i);
328 break;
329 }
330 }
331 }
332 }
333 }
334 return result;
335 }
336}
void Add(TKey key, TValue value)
CodeTypeReference(string typeName, params CodeTypeReference[] typeArguments)
CodeTypeReference(string typeName, CodeTypeReferenceOptions codeTypeReferenceOption)
string RipOffAssemblyInformationFromTypeName(string typeName)
void Initialize(string typeName, CodeTypeReferenceOptions options)
CodeTypeReference(CodeTypeReference arrayType, int rank)
CodeTypeReference(Type type, CodeTypeReferenceOptions codeTypeReferenceOption)