Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
TypeDesc.cs
Go to the documentation of this file.
3
5
6internal sealed class TypeDesc
7{
8 private readonly string _name;
9
10 private readonly string _fullName;
11
12 private string _cSharpName;
13
15
17
19
20 private readonly TypeKind _kind;
21
22 private readonly XmlSchemaType _dataType;
23
25 private Type _type;
26
28
30
31 private readonly string _formatterName;
32
33 private readonly bool _isXsdType;
34
35 private bool _isMixed;
36
37 private int _weight;
38
40
41 internal TypeFlags Flags => _flags;
42
43 internal bool IsXsdType => _isXsdType;
44
45 internal bool IsMappedType => false;
46
47 internal string Name => _name;
48
49 internal string FullName => _fullName;
50
51 internal string CSharpName
52 {
53 get
54 {
55 if (_cSharpName == null)
56 {
58 }
59 return _cSharpName;
60 }
61 }
62
64
66 internal Type Type => _type;
67
68 internal string FormatterName => _formatterName;
69
70 internal TypeKind Kind => _kind;
71
72 internal bool IsValueType => (_flags & TypeFlags.Reference) == 0;
73
74 internal bool CanBeAttributeValue => (_flags & TypeFlags.CanBeAttributeValue) != 0;
75
76 internal bool XmlEncodingNotRequired => (_flags & TypeFlags.XmlEncodingNotRequired) != 0;
77
78 internal bool CanBeElementValue => (_flags & TypeFlags.CanBeElementValue) != 0;
79
80 internal bool CanBeTextValue => (_flags & TypeFlags.CanBeTextValue) != 0;
81
82 internal bool IsMixed
83 {
84 get
85 {
86 if (!_isMixed)
87 {
88 return CanBeTextValue;
89 }
90 return true;
91 }
92 set
93 {
95 }
96 }
97
98 internal bool IsSpecial => (_flags & TypeFlags.Special) != 0;
99
100 internal bool IsAmbiguousDataType => (_flags & TypeFlags.AmbiguousDataType) != 0;
101
102 internal bool HasCustomFormatter => (_flags & TypeFlags.HasCustomFormatter) != 0;
103
104 internal bool HasDefaultSupport => (_flags & TypeFlags.IgnoreDefault) == 0;
105
106 internal bool HasIsEmpty => (_flags & TypeFlags.HasIsEmpty) != 0;
107
108 internal bool CollapseWhitespace => (_flags & TypeFlags.CollapseWhitespace) != 0;
109
110 internal bool HasDefaultConstructor => (_flags & TypeFlags.HasDefaultConstructor) != 0;
111
112 internal bool IsUnsupported => (_flags & TypeFlags.Unsupported) != 0;
113
114 internal bool IsGenericInterface => (_flags & TypeFlags.GenericInterface) != 0;
115
116 internal bool IsPrivateImplementation => (_flags & TypeFlags.UsePrivateImplementation) != 0;
117
118 internal bool CannotNew
119 {
120 get
121 {
123 {
125 }
126 return true;
127 }
128 }
129
130 internal bool IsAbstract => (_flags & TypeFlags.Abstract) != 0;
131
132 internal bool IsOptionalValue => (_flags & TypeFlags.OptionalValue) != 0;
133
134 internal bool UseReflection => (_flags & TypeFlags.UseReflection) != 0;
135
136 internal bool IsVoid => _kind == TypeKind.Void;
137
138 internal bool IsClass => _kind == TypeKind.Class;
139
140 internal bool IsStructLike
141 {
142 get
143 {
144 if (_kind != TypeKind.Struct)
145 {
146 return _kind == TypeKind.Class;
147 }
148 return true;
149 }
150 }
151
152 internal bool IsArrayLike
153 {
154 get
155 {
156 if (_kind != TypeKind.Array && _kind != TypeKind.Collection)
157 {
158 return _kind == TypeKind.Enumerable;
159 }
160 return true;
161 }
162 }
163
164 internal bool IsCollection => _kind == TypeKind.Collection;
165
166 internal bool IsEnumerable => _kind == TypeKind.Enumerable;
167
168 internal bool IsArray => _kind == TypeKind.Array;
169
170 internal bool IsPrimitive => _kind == TypeKind.Primitive;
171
172 internal bool IsEnum => _kind == TypeKind.Enum;
173
174 internal bool IsNullable => !IsValueType;
175
176 internal bool IsRoot => _kind == TypeKind.Root;
177
178 internal bool ConstructorInaccessible => (_flags & TypeFlags.CtorInaccessible) != 0;
179
181 {
182 get
183 {
184 return _exception;
185 }
186 set
187 {
189 }
190 }
191
193 {
194 get
195 {
197 }
198 set
199 {
201 }
202 }
203
204 internal int Weight => _weight;
205
207 {
208 get
209 {
210 return _baseTypeDesc;
211 }
212 set
213 {
215 _weight = ((_baseTypeDesc != null) ? (_baseTypeDesc.Weight + 1) : 0);
216 }
217 }
218
219 internal TypeDesc(string name, string fullName, XmlSchemaType dataType, TypeKind kind, TypeDesc baseTypeDesc, TypeFlags flags, string formatterName)
220 {
221 _name = name.Replace('+', '.');
222 _fullName = fullName.Replace('+', '.');
223 _kind = kind;
225 _flags = flags;
226 _isXsdType = kind == TypeKind.Primitive;
227 if (_isXsdType)
228 {
229 _weight = 1;
230 }
231 else if (kind == TypeKind.Enum)
232 {
233 _weight = 2;
234 }
235 else if (_kind == TypeKind.Root)
236 {
237 _weight = -1;
238 }
239 else
240 {
241 _weight = ((baseTypeDesc != null) ? (baseTypeDesc.Weight + 1) : 0);
242 }
243 _dataType = dataType;
245 }
246
247 internal TypeDesc(string name, string fullName, TypeKind kind, TypeDesc baseTypeDesc, TypeFlags flags)
248 : this(name, fullName, null, kind, baseTypeDesc, flags, null)
249 {
250 }
251
258
265
266 public override string ToString()
267 {
268 return _fullName;
269 }
270
272 {
273 if (IsOptionalValue)
274 {
275 return this;
276 }
277 if (_nullableTypeDesc == null)
278 {
279 _nullableTypeDesc = new TypeDesc("NullableOf" + _name, "System.Nullable`1[" + _fullName + "]", null, TypeKind.Struct, this, _flags | TypeFlags.OptionalValue, _formatterName);
281 }
282 return _nullableTypeDesc;
283 }
284
285 internal void CheckSupported()
286 {
287 if (IsUnsupported)
288 {
289 if (Exception != null)
290 {
291 throw Exception;
292 }
294 }
295 if (_baseTypeDesc != null)
296 {
298 }
299 if (_arrayElementTypeDesc != null)
300 {
302 }
303 }
304
313
315 {
316 if (_arrayTypeDesc == null)
317 {
318 _arrayTypeDesc = new TypeDesc(null, _name + "[]", _fullName + "[]", TypeKind.Array, null, TypeFlags.Reference | (_flags & TypeFlags.UseReflection), this);
319 }
320 return _arrayTypeDesc;
321 }
322
324 {
325 for (TypeDesc typeDesc = this; typeDesc != null; typeDesc = typeDesc.BaseTypeDesc)
326 {
327 if (typeDesc == baseTypeDesc)
328 {
329 return true;
330 }
331 }
332 return baseTypeDesc.IsRoot;
333 }
334
336 {
337 if (typeDescs.Length == 0)
338 {
339 return null;
340 }
341 TypeDesc typeDesc = null;
342 int num = int.MaxValue;
343 for (int i = 0; i < typeDescs.Length; i++)
344 {
345 int weight = typeDescs[i].Weight;
346 if (weight < num)
347 {
348 num = weight;
349 typeDesc = typeDescs[i];
350 }
351 }
352 while (typeDesc != null)
353 {
354 int j;
355 for (j = 0; j < typeDescs.Length && typeDescs[j].IsDerivedFrom(typeDesc); j++)
356 {
357 }
358 if (j == typeDescs.Length)
359 {
360 break;
361 }
362 typeDesc = typeDesc.BaseTypeDesc;
363 }
364 return typeDesc;
365 }
366}
static string XmlSerializerUnsupportedType
Definition SR.cs:1394
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string XmlConstructorInaccessible
Definition SR.cs:1410
Definition SR.cs:7
static string GetCSharpName(string name)
TypeDesc GetNullableTypeDesc([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type type)
Definition TypeDesc.cs:271
TypeDesc([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type type, string name, string fullName, TypeKind kind, TypeDesc baseTypeDesc, TypeFlags flags, TypeDesc arrayElementTypeDesc)
Definition TypeDesc.cs:259
TypeDesc(string name, string fullName, XmlSchemaType dataType, TypeKind kind, TypeDesc baseTypeDesc, TypeFlags flags, string formatterName)
Definition TypeDesc.cs:219
static TypeDesc FindCommonBaseTypeDesc(TypeDesc[] typeDescs)
Definition TypeDesc.cs:335
readonly XmlSchemaType _dataType
Definition TypeDesc.cs:22
bool IsDerivedFrom(TypeDesc baseTypeDesc)
Definition TypeDesc.cs:323
TypeDesc([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type type, bool isXsdType, XmlSchemaType dataType, string formatterName, TypeFlags flags)
Definition TypeDesc.cs:252
TypeDesc(string name, string fullName, TypeKind kind, TypeDesc baseTypeDesc, TypeFlags flags)
Definition TypeDesc.cs:247