Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
TypeScope.cs
Go to the documentation of this file.
5using System.Text;
7
9
10internal sealed class TypeScope
11{
12 private readonly Hashtable _typeDescs = new Hashtable();
13
14 private readonly Hashtable _arrayTypeDescs = new Hashtable();
15
16 private readonly ArrayList _typeMappings = new ArrayList();
17
18 private static readonly Hashtable s_primitiveTypes;
19
20 private static readonly Hashtable s_primitiveDataTypes;
21
22 private static readonly NameTable s_primitiveNames;
23
24 private static readonly string[] s_unsupportedTypes;
25
27
29
31
32 static TypeScope()
33 {
37 s_unsupportedTypes = new string[20]
38 {
39 "anyURI", "duration", "ENTITY", "ENTITIES", "gDay", "gMonth", "gMonthDay", "gYear", "gYearMonth", "ID",
40 "IDREF", "IDREFS", "integer", "language", "negativeInteger", "nonNegativeInteger", "nonPositiveInteger", "NOTATION", "positiveInteger", "token"
41 };
42 AddPrimitive(typeof(string), "string", "String", (TypeFlags)2106);
43 AddPrimitive(typeof(int), "int", "Int32", (TypeFlags)4136);
44 AddPrimitive(typeof(bool), "boolean", "Boolean", (TypeFlags)4136);
45 AddPrimitive(typeof(short), "short", "Int16", (TypeFlags)4136);
46 AddPrimitive(typeof(long), "long", "Int64", (TypeFlags)4136);
47 AddPrimitive(typeof(float), "float", "Single", (TypeFlags)4136);
48 AddPrimitive(typeof(double), "double", "Double", (TypeFlags)4136);
49 AddPrimitive(typeof(decimal), "decimal", "Decimal", (TypeFlags)4136);
50 AddPrimitive(typeof(DateTime), "dateTime", "DateTime", (TypeFlags)4200);
51 AddPrimitive(typeof(XmlQualifiedName), "QName", "XmlQualifiedName", (TypeFlags)5226);
52 AddPrimitive(typeof(byte), "unsignedByte", "Byte", (TypeFlags)4136);
53 AddPrimitive(typeof(sbyte), "byte", "SByte", (TypeFlags)4136);
54 AddPrimitive(typeof(ushort), "unsignedShort", "UInt16", (TypeFlags)4136);
55 AddPrimitive(typeof(uint), "unsignedInt", "UInt32", (TypeFlags)4136);
56 AddPrimitive(typeof(ulong), "unsignedLong", "UInt64", (TypeFlags)4136);
57 AddPrimitive(typeof(DateTime), "date", "Date", (TypeFlags)4328);
58 AddPrimitive(typeof(DateTime), "time", "Time", (TypeFlags)4328);
59 AddPrimitive(typeof(string), "Name", "XmlName", (TypeFlags)234);
60 AddPrimitive(typeof(string), "NCName", "XmlNCName", (TypeFlags)234);
61 AddPrimitive(typeof(string), "NMTOKEN", "XmlNmToken", (TypeFlags)234);
62 AddPrimitive(typeof(string), "NMTOKENS", "XmlNmTokens", (TypeFlags)234);
63 AddPrimitive(typeof(byte[]), "base64Binary", "ByteArrayBase64", (TypeFlags)6890);
64 AddPrimitive(typeof(byte[]), "hexBinary", "ByteArrayHex", (TypeFlags)6890);
66 {
67 Value = "[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}"
68 };
69 AddNonXsdPrimitive(typeof(Guid), "guid", "http://microsoft.com/wsdl/types/", "Guid", new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"), new XmlSchemaFacet[1] { xmlSchemaPatternFacet }, (TypeFlags)4648);
70 AddNonXsdPrimitive(typeof(char), "char", "http://microsoft.com/wsdl/types/", "Char", new XmlQualifiedName("unsignedShort", "http://www.w3.org/2001/XMLSchema"), Array.Empty<XmlSchemaFacet>(), (TypeFlags)616);
71 AddNonXsdPrimitive(typeof(TimeSpan), "TimeSpan", "http://microsoft.com/wsdl/types/", "TimeSpan", new XmlQualifiedName("duration", "http://www.w3.org/2001/XMLSchema"), Array.Empty<XmlSchemaFacet>(), (TypeFlags)4136);
72 AddNonXsdPrimitive(typeof(DateTimeOffset), "dateTimeOffset", "http://microsoft.com/wsdl/types/", "DateTimeOffset", new XmlQualifiedName("dateTime", "http://www.w3.org/2001/XMLSchema"), Array.Empty<XmlSchemaFacet>(), (TypeFlags)4136);
73 AddSoapEncodedTypes("http://schemas.xmlsoap.org/soap/encoding/");
74 AddPrimitive(typeof(string), "normalizedString", "String", (TypeFlags)2234);
75 for (int i = 0; i < s_unsupportedTypes.Length; i++)
76 {
77 AddPrimitive(typeof(string), s_unsupportedTypes[i], "String", (TypeFlags)32954);
78 }
79 }
80
81 internal static bool IsKnownType(Type type)
82 {
83 if (type == typeof(object))
84 {
85 return true;
86 }
87 if (type.IsEnum)
88 {
89 return false;
90 }
91 switch (Type.GetTypeCode(type))
92 {
93 case TypeCode.String:
94 return true;
95 case TypeCode.Int32:
96 return true;
97 case TypeCode.Boolean:
98 return true;
99 case TypeCode.Int16:
100 return true;
101 case TypeCode.Int64:
102 return true;
103 case TypeCode.Single:
104 return true;
105 case TypeCode.Double:
106 return true;
107 case TypeCode.Decimal:
108 return true;
109 case TypeCode.DateTime:
110 return true;
111 case TypeCode.Byte:
112 return true;
113 case TypeCode.SByte:
114 return true;
115 case TypeCode.UInt16:
116 return true;
117 case TypeCode.UInt32:
118 return true;
119 case TypeCode.UInt64:
120 return true;
121 case TypeCode.Char:
122 return true;
123 default:
125 {
126 return true;
127 }
128 if (type == typeof(byte[]))
129 {
130 return true;
131 }
132 if (type == typeof(Guid))
133 {
134 return true;
135 }
136 if (type == typeof(TimeSpan))
137 {
138 return true;
139 }
140 if (type == typeof(DateTimeOffset))
141 {
142 return true;
143 }
144 if (type == typeof(XmlNode[]))
145 {
146 return true;
147 }
148 return false;
149 }
150 }
151
152 private static void AddSoapEncodedTypes(string ns)
153 {
154 AddSoapEncodedPrimitive(typeof(string), "normalizedString", ns, "String", new XmlQualifiedName("normalizedString", "http://www.w3.org/2001/XMLSchema"), (TypeFlags)2218);
155 for (int i = 0; i < s_unsupportedTypes.Length; i++)
156 {
157 AddSoapEncodedPrimitive(typeof(string), s_unsupportedTypes[i], ns, "String", new XmlQualifiedName(s_unsupportedTypes[i], "http://www.w3.org/2001/XMLSchema"), (TypeFlags)32938);
158 }
159 AddSoapEncodedPrimitive(typeof(string), "string", ns, "String", new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"), (TypeFlags)58);
160 AddSoapEncodedPrimitive(typeof(int), "int", ns, "Int32", new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"), (TypeFlags)4136);
161 AddSoapEncodedPrimitive(typeof(bool), "boolean", ns, "Boolean", new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"), (TypeFlags)4136);
162 AddSoapEncodedPrimitive(typeof(short), "short", ns, "Int16", new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"), (TypeFlags)4136);
163 AddSoapEncodedPrimitive(typeof(long), "long", ns, "Int64", new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"), (TypeFlags)4136);
164 AddSoapEncodedPrimitive(typeof(float), "float", ns, "Single", new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"), (TypeFlags)4136);
165 AddSoapEncodedPrimitive(typeof(double), "double", ns, "Double", new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"), (TypeFlags)4136);
166 AddSoapEncodedPrimitive(typeof(decimal), "decimal", ns, "Decimal", new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"), (TypeFlags)4136);
167 AddSoapEncodedPrimitive(typeof(DateTime), "dateTime", ns, "DateTime", new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"), (TypeFlags)4200);
168 AddSoapEncodedPrimitive(typeof(XmlQualifiedName), "QName", ns, "XmlQualifiedName", new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"), (TypeFlags)5226);
169 AddSoapEncodedPrimitive(typeof(byte), "unsignedByte", ns, "Byte", new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"), (TypeFlags)4136);
170 AddSoapEncodedPrimitive(typeof(sbyte), "byte", ns, "SByte", new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"), (TypeFlags)4136);
171 AddSoapEncodedPrimitive(typeof(ushort), "unsignedShort", ns, "UInt16", new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"), (TypeFlags)4136);
172 AddSoapEncodedPrimitive(typeof(uint), "unsignedInt", ns, "UInt32", new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"), (TypeFlags)4136);
173 AddSoapEncodedPrimitive(typeof(ulong), "unsignedLong", ns, "UInt64", new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"), (TypeFlags)4136);
174 AddSoapEncodedPrimitive(typeof(DateTime), "date", ns, "Date", new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"), (TypeFlags)4328);
175 AddSoapEncodedPrimitive(typeof(DateTime), "time", ns, "Time", new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"), (TypeFlags)4328);
176 AddSoapEncodedPrimitive(typeof(string), "Name", ns, "XmlName", new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"), (TypeFlags)234);
177 AddSoapEncodedPrimitive(typeof(string), "NCName", ns, "XmlNCName", new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"), (TypeFlags)234);
178 AddSoapEncodedPrimitive(typeof(string), "NMTOKEN", ns, "XmlNmToken", new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"), (TypeFlags)234);
179 AddSoapEncodedPrimitive(typeof(string), "NMTOKENS", ns, "XmlNmTokens", new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"), (TypeFlags)234);
180 AddSoapEncodedPrimitive(typeof(byte[]), "base64Binary", ns, "ByteArrayBase64", new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"), (TypeFlags)4842);
181 AddSoapEncodedPrimitive(typeof(byte[]), "hexBinary", ns, "ByteArrayHex", new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"), (TypeFlags)4842);
182 AddSoapEncodedPrimitive(typeof(string), "arrayCoordinate", ns, "String", new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"), (TypeFlags)40);
183 AddSoapEncodedPrimitive(typeof(byte[]), "base64", ns, "ByteArrayBase64", new XmlQualifiedName("base64Binary", "http://www.w3.org/2001/XMLSchema"), (TypeFlags)554);
184 }
185
198
218
223
224 internal TypeDesc GetTypeDesc(string name, string ns)
225 {
226 return GetTypeDesc(name, ns, (TypeFlags)56);
227 }
228
229 internal TypeDesc GetTypeDesc(string name, string ns, TypeFlags flags)
230 {
232 if (typeDesc != null && (typeDesc.Flags & flags) != 0)
233 {
234 return typeDesc;
235 }
236 return null;
237 }
238
240 {
241 return (TypeDesc)s_primitiveDataTypes[dataType];
242 }
243
244 [RequiresUnreferencedCode("calls GetTypeDesc")]
246 {
247 return GetTypeDesc(type, null, directReference: true, throwOnError: true);
248 }
249
250 [RequiresUnreferencedCode("calls GetTypeDesc")]
255
256 [RequiresUnreferencedCode("calls ImportTypeDesc")]
258 {
259 if (type.ContainsGenericParameters)
260 {
262 }
264 if (typeDesc == null)
265 {
267 if (typeDesc == null)
268 {
270 }
271 }
272 if (throwOnError)
273 {
274 typeDesc.CheckSupported();
275 }
276 return typeDesc;
277 }
278
279 [RequiresUnreferencedCode("calls ImportTypeDesc")]
281 {
283 if (typeDesc == null)
284 {
286 if (!typeDesc.IsArrayLike)
287 {
289 }
290 typeDesc.CheckSupported();
292 }
293 return typeDesc;
294 }
295
297 {
299 {
300 if (typeMapping.TypeDesc == typeDesc)
301 {
302 return typeMapping;
303 }
304 }
305 return null;
306 }
307
309 {
310 if (typeDesc.Type != null)
311 {
312 return typeDesc.Type;
313 }
315 {
316 if (typeDesc2.Value == typeDesc)
317 {
318 return typeDesc2.Key as Type;
319 }
320 }
321 return null;
322 }
323
324 [RequiresUnreferencedCode("calls GetEnumeratorElementType")]
326 {
327 TypeDesc typeDesc = null;
328 Type type2 = null;
329 Type type3 = null;
330 TypeFlags flags = TypeFlags.None;
331 Exception exception = null;
332 if (!type.IsVisible)
333 {
334 flags |= TypeFlags.Unsupported;
336 }
337 else if (directReference && type.IsAbstract && type.IsSealed)
338 {
339 flags |= TypeFlags.Unsupported;
341 }
343 {
344 flags |= TypeFlags.UseReflection;
345 }
346 if (!type.IsValueType)
347 {
348 flags |= TypeFlags.Reference;
349 }
351 if (type == typeof(object))
352 {
353 typeKind = TypeKind.Root;
354 flags |= TypeFlags.HasDefaultConstructor;
355 }
356 else if (type == typeof(ValueType))
357 {
358 typeKind = TypeKind.Enum;
359 flags |= TypeFlags.Unsupported;
360 if (exception == null)
361 {
363 }
364 }
365 else if (type == typeof(void))
366 {
367 typeKind = TypeKind.Void;
368 }
369 else if (typeof(IXmlSerializable).IsAssignableFrom(type))
370 {
371 typeKind = TypeKind.Serializable;
372 flags |= (TypeFlags)36;
374 }
375 else if (type.IsArray)
376 {
377 typeKind = TypeKind.Array;
378 if (type.GetArrayRank() > 1)
379 {
380 flags |= TypeFlags.Unsupported;
381 if (exception == null)
382 {
384 }
385 }
386 type2 = type.GetElementType();
387 flags |= TypeFlags.HasDefaultConstructor;
388 }
389 else if (typeof(ICollection).IsAssignableFrom(type) && !IsArraySegment(type))
390 {
391 typeKind = TypeKind.Collection;
394 }
395 else if (type == typeof(XmlQualifiedName))
396 {
397 typeKind = TypeKind.Primitive;
398 }
399 else if (type.IsPrimitive)
400 {
401 typeKind = TypeKind.Primitive;
402 flags |= TypeFlags.Unsupported;
403 if (exception == null)
404 {
406 }
407 }
408 else if (type.IsEnum)
409 {
410 typeKind = TypeKind.Enum;
411 }
412 else if (type.IsValueType)
413 {
414 typeKind = TypeKind.Struct;
416 {
417 type3 = type.GetGenericArguments()[0];
418 flags |= TypeFlags.OptionalValue;
419 }
420 else
421 {
422 type3 = type.BaseType;
423 }
424 if (type.IsAbstract)
425 {
426 flags |= TypeFlags.Abstract;
427 }
428 }
429 else if (type.IsClass)
430 {
431 if (type == typeof(XmlAttribute))
432 {
433 typeKind = TypeKind.Attribute;
434 flags |= (TypeFlags)12;
435 }
436 else if (typeof(XmlNode).IsAssignableFrom(type))
437 {
438 typeKind = TypeKind.Node;
439 type3 = type.BaseType;
440 flags |= (TypeFlags)52;
441 if (typeof(XmlText).IsAssignableFrom(type))
442 {
443 flags &= (TypeFlags)(-33);
444 }
445 else if (typeof(XmlElement).IsAssignableFrom(type))
446 {
447 flags &= (TypeFlags)(-17);
448 }
449 else if (type.IsAssignableFrom(typeof(XmlAttribute)))
450 {
451 flags |= TypeFlags.CanBeAttributeValue;
452 }
453 }
454 else
455 {
456 typeKind = TypeKind.Class;
457 type3 = type.BaseType;
458 if (type.IsAbstract)
459 {
460 flags |= TypeFlags.Abstract;
461 }
462 }
463 }
464 else if (type.IsInterface)
465 {
466 typeKind = TypeKind.Void;
467 flags |= TypeFlags.Unsupported;
468 if (exception == null)
469 {
471 }
472 }
473 else
474 {
475 typeKind = TypeKind.Void;
476 flags |= TypeFlags.Unsupported;
477 if (exception == null)
478 {
480 }
481 }
482 if (typeKind == TypeKind.Class && !type.IsAbstract)
483 {
485 }
486 if ((typeKind == TypeKind.Struct || typeKind == TypeKind.Class) && typeof(IEnumerable).IsAssignableFrom(type) && !IsArraySegment(type))
487 {
489 typeKind = TypeKind.Enumerable;
491 }
492 typeDesc = new TypeDesc(type, CodeIdentifier.MakeValid(TypeName(type)), type.ToString(), typeKind, null, flags, null);
494 if (directReference && (typeDesc.IsClass || typeKind == TypeKind.Serializable))
495 {
496 typeDesc.CheckNeedConstructor();
497 }
498 if (typeDesc.IsUnsupported)
499 {
500 return typeDesc;
501 }
503 if (type2 != null)
504 {
506 if (directReference && (typeDesc2.IsCollection || typeDesc2.IsEnumerable) && !typeDesc2.IsPrimitive)
507 {
508 typeDesc2.CheckNeedConstructor();
509 }
511 }
512 if (type3 != null && type3 != typeof(object) && type3 != typeof(ValueType))
513 {
515 }
516 if (type.IsNestedPublic)
517 {
518 Type declaringType = type.DeclaringType;
519 while (declaringType != null && !declaringType.ContainsGenericParameters && (!declaringType.IsAbstract || !declaringType.IsSealed))
520 {
522 declaringType = declaringType.DeclaringType;
523 }
524 }
525 return typeDesc;
526 }
527
528 private static bool IsArraySegment(Type t)
529 {
530 if (t.IsGenericType)
531 {
533 }
534 return false;
535 }
536
537 internal static bool IsOptionalValue(Type type)
538 {
539 if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>).GetGenericTypeDefinition())
540 {
541 return true;
542 }
543 return false;
544 }
545
546 internal static string TypeName(Type t)
547 {
548 if (t.IsArray)
549 {
550 return "ArrayOf" + TypeName(t.GetElementType());
551 }
552 if (t.IsGenericType)
553 {
556 string text = t.Name;
557 int num = text.IndexOf('`');
558 if (num >= 0)
559 {
560 text = text.Substring(0, num);
561 }
562 stringBuilder.Append(text);
563 stringBuilder.Append("Of");
565 for (int i = 0; i < genericArguments.Length; i++)
566 {
569 }
570 return stringBuilder.ToString();
571 }
572 return t.Name;
573 }
574
575 [RequiresUnreferencedCode("calls GetEnumeratorElementType")]
576 internal static Type GetArrayElementType(Type type, string memberInfo)
577 {
578 if (type.IsArray)
579 {
580 return type.GetElementType();
581 }
582 if (IsArraySegment(type))
583 {
584 return null;
585 }
586 if (typeof(ICollection).IsAssignableFrom(type))
587 {
589 }
590 if (typeof(IEnumerable).IsAssignableFrom(type))
591 {
592 TypeFlags flags = TypeFlags.None;
593 return GetEnumeratorElementType(type, ref flags);
594 }
595 return null;
596 }
597
599 {
600 if (mapping.BaseMapping == null)
601 {
602 return mapping.Members;
603 }
606 return list.ToArray();
607 }
608
610 {
611 if (mapping.BaseMapping != null)
612 {
613 GetAllMembers(mapping.BaseMapping, list);
614 }
615 for (int i = 0; i < mapping.Members.Length; i++)
616 {
617 list.Add(mapping.Members[i]);
618 }
619 }
620
627
634
636 {
637 if (mapping.BaseMapping != null)
638 {
639 GetSettableMembers(mapping.BaseMapping, list);
640 }
641 if (mapping.Members == null)
642 {
643 return;
644 }
645 MemberMapping[] members = mapping.Members;
647 {
649 PropertyInfo propertyInfo = memberInfo as PropertyInfo;
650 if (propertyInfo != null && !CanWriteProperty(propertyInfo, memberMapping.TypeDesc))
651 {
653 }
654 list.Add(memberMapping);
655 }
656 }
657
658 private static bool CanWriteProperty(PropertyInfo propertyInfo, TypeDesc typeDesc)
659 {
660 if (typeDesc.Kind == TypeKind.Collection || typeDesc.Kind == TypeKind.Enumerable)
661 {
662 return true;
663 }
664 if (propertyInfo.SetMethod != null)
665 {
666 return propertyInfo.SetMethod.IsPublic;
667 }
668 return false;
669 }
670
677
679 {
680 memberInfos.Clear();
681 for (int i = 0; i < mappings.Length; i++)
682 {
683 memberInfos[mappings[i].Name] = mappings[i].MemberInfo;
684 if (mappings[i].ChoiceIdentifier != null)
685 {
686 memberInfos[mappings[i].ChoiceIdentifier.MemberName] = mappings[i].ChoiceIdentifier.MemberInfo;
687 }
688 if (mappings[i].CheckSpecifiedMemberInfo != null)
689 {
690 memberInfos[mappings[i].Name + "Specified"] = mappings[i].CheckSpecifiedMemberInfo;
691 }
692 }
695 foreach (KeyValuePair<string, MemberInfo> memberInfo in memberInfos)
696 {
697 if (ShouldBeReplaced(memberInfo.Value, structMapping.TypeDesc.Type, out replacedInfo))
698 {
699 if (dictionary == null)
700 {
702 }
704 }
705 }
706 if (dictionary == null)
707 {
708 return;
709 }
711 {
712 memberInfos[item.Key] = item.Value;
713 }
714 for (int j = 0; j < mappings.Length; j++)
715 {
716 if (dictionary.TryGetValue(mappings[j].Name, out var value))
717 {
721 }
722 }
723 }
724
726 {
730 if (declaringType.IsAssignableFrom(type))
731 {
732 while (type != declaringType)
733 {
734 PropertyInfo[] properties = type.GetProperties(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
735 foreach (PropertyInfo propertyInfo in properties)
736 {
737 if (!(propertyInfo.Name == memberInfoToBeReplaced.Name))
738 {
739 continue;
740 }
741 replacedInfo = propertyInfo;
743 {
744 if (propertyInfo.GetMethod != null && !propertyInfo.GetMethod.IsPublic && memberInfoToBeReplaced is PropertyInfo && ((PropertyInfo)memberInfoToBeReplaced).GetMethod.IsPublic)
745 {
746 break;
747 }
748 return true;
749 }
750 }
751 FieldInfo[] fields = type.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
752 foreach (FieldInfo fieldInfo in fields)
753 {
754 if (fieldInfo.Name == memberInfoToBeReplaced.Name)
755 {
758 {
759 return true;
760 }
761 }
762 }
763 type = type.BaseType;
764 }
765 }
766 return false;
767 }
768
770 {
771 ConstructorInfo constructor = type.GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, Type.EmptyTypes);
772 if (constructor != null)
773 {
774 TypeFlags typeFlags = TypeFlags.HasDefaultConstructor;
775 if (!constructor.IsPublic)
776 {
777 typeFlags |= TypeFlags.CtorInaccessible;
778 }
779 else
780 {
781 object[] customAttributes = constructor.GetCustomAttributes(typeof(ObsoleteAttribute), inherit: false);
782 if (customAttributes != null && customAttributes.Length != 0)
783 {
785 if (obsoleteAttribute.IsError)
786 {
787 typeFlags |= TypeFlags.CtorInaccessible;
788 }
789 }
790 }
791 return typeFlags;
792 }
793 return TypeFlags.None;
794 }
795
796 [RequiresUnreferencedCode("Needs to mark members on the return type of the GetEnumerator method")]
798 {
799 if (typeof(IEnumerable).IsAssignableFrom(type))
800 {
801 MethodInfo methodInfo = type.GetMethod("GetEnumerator", Type.EmptyTypes);
802 if (methodInfo == null || !typeof(IEnumerator).IsAssignableFrom(methodInfo.ReturnType))
803 {
804 methodInfo = null;
805 MemberInfo[] member = type.GetMember("System.Collections.Generic.IEnumerable<*", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
806 foreach (MemberInfo memberInfo in member)
807 {
809 if (methodInfo != null && typeof(IEnumerator).IsAssignableFrom(methodInfo.ReturnType))
810 {
811 flags |= TypeFlags.GenericInterface;
812 break;
813 }
814 methodInfo = null;
815 }
816 if (methodInfo == null)
817 {
818 flags |= TypeFlags.UsePrivateImplementation;
819 methodInfo = type.GetMethod("System.Collections.IEnumerable.GetEnumerator", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, Type.EmptyTypes);
820 }
821 }
822 if (methodInfo == null || !typeof(IEnumerator).IsAssignableFrom(methodInfo.ReturnType))
823 {
824 return null;
825 }
827 if (xmlAttributes.XmlIgnore)
828 {
829 return null;
830 }
831 PropertyInfo property = methodInfo.ReturnType.GetProperty("Current");
832 Type type2 = ((property == null) ? typeof(object) : property.PropertyType);
833 MethodInfo method = type.GetMethod("Add", new Type[1] { type2 });
834 if (method == null && type2 != typeof(object))
835 {
836 type2 = typeof(object);
837 method = type.GetMethod("Add", new Type[1] { type2 });
838 }
839 if (method == null)
840 {
841 throw new InvalidOperationException(System.SR.Format(System.SR.XmlNoAddMethod, type.FullName, type2, "IEnumerable"));
842 }
843 return type2;
844 }
845 return null;
846 }
847
849 {
850 if (typeof(IDictionary).IsAssignableFrom(type))
851 {
852 if (memberInfo == null)
853 {
855 }
857 }
858 MemberInfo[] defaultMembers = type.GetDefaultMembers();
859 PropertyInfo propertyInfo = null;
860 if (defaultMembers != null && defaultMembers.Length != 0)
861 {
862 Type type2 = type;
863 while (type2 != null)
864 {
865 for (int i = 0; i < defaultMembers.Length; i++)
866 {
868 {
869 continue;
870 }
872 if (!(propertyInfo2.DeclaringType != type2) && propertyInfo2.CanRead)
873 {
875 ParameterInfo[] parameters = getMethod.GetParameters();
876 if (parameters.Length == 1 && parameters[0].ParameterType == typeof(int))
877 {
878 propertyInfo = propertyInfo2;
879 break;
880 }
881 }
882 }
883 if (propertyInfo != null)
884 {
885 break;
886 }
887 type2 = type2.BaseType;
888 }
889 }
890 if (propertyInfo == null)
891 {
893 }
894 MethodInfo method = type.GetMethod("Add", new Type[1] { propertyInfo.PropertyType });
895 if (method == null)
896 {
897 throw new InvalidOperationException(System.SR.Format(System.SR.XmlNoAddMethod, type.FullName, propertyInfo.PropertyType, "ICollection"));
898 }
899 return propertyInfo;
900 }
901
906
907 internal static XmlQualifiedName ParseWsdlArrayType(string type, out string dims, XmlSchemaObject parent)
908 {
909 int num = type.LastIndexOf(':');
910 string text = ((num > 0) ? type.Substring(0, num) : "");
911 int num2 = type.IndexOf('[', num + 1);
912 if (num2 <= num)
913 {
915 }
916 string name = type.Substring(num + 1, num2 - num - 1);
917 dims = type.Substring(num2);
918 while (parent != null)
919 {
920 if (parent.Namespaces != null && parent.Namespaces.TryLookupNamespace(text, out var ns) && ns != null)
921 {
922 text = ns;
923 break;
924 }
925 parent = parent.Parent;
926 }
927 return new XmlQualifiedName(name, text);
928 }
929
934}
virtual int Add(object? value)
void Add(TKey key, TValue value)
virtual ICollection Keys
Definition Hashtable.cs:532
virtual void Add(object key, object? value)
Definition Hashtable.cs:676
virtual ? MethodInfo GetMethod
virtual ? MethodInfo SetMethod
static string XmlUnsupportedOpenGenericType
Definition SR.cs:1720
static string XmlInvalidArrayTypeSyntax
Definition SR.cs:1548
static string XmlReadOnlyPropertyError
Definition SR.cs:1420
static string XmlUnsupportedIDictionary
Definition SR.cs:1402
static string XmlUnsupportedInterfaceDetails
Definition SR.cs:1664
static string XmlSerializerUnsupportedType
Definition SR.cs:1394
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string XmlNoAddMethod
Definition SR.cs:1418
static string XmlUnsupportedRank
Definition SR.cs:1666
static string XmlUnsupportedIDictionaryDetails
Definition SR.cs:1404
static string XmlUnsupportedInterface
Definition SR.cs:1662
static string XmlTypeStatic
Definition SR.cs:1414
static string XmlNoDefaultAccessors
Definition SR.cs:1416
static string XmlTypeInaccessible
Definition SR.cs:1412
Definition SR.cs:7
Type? GetElementType()
virtual Type[] GetGenericArguments()
Definition Type.cs:500
bool IsArray
Definition Type.cs:71
static TypeCode GetTypeCode(Type? type)
Definition Type.cs:919
virtual bool IsGenericType
Definition Type.cs:111
static readonly Type[] EmptyTypes
Definition Type.cs:19
virtual Type GetGenericTypeDefinition()
Definition Type.cs:495
XmlSerializerNamespaces Namespaces
static string MakeValid(string identifier)
static void PopulateMemberInfos(StructMapping structMapping, MemberMapping[] mappings, Dictionary< string, MemberInfo > memberInfos)
Definition TypeScope.cs:678
static bool IsKnownType(Type type)
Definition TypeScope.cs:81
static void AddPrimitive([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type type, string dataTypeName, string formatterName, TypeFlags flags)
Definition TypeScope.cs:186
static void GetSettableMembers(StructMapping mapping, List< MemberMapping > list)
Definition TypeScope.cs:635
readonly ArrayList _typeMappings
Definition TypeScope.cs:16
static void GetAllMembers(StructMapping mapping, List< MemberMapping > list)
Definition TypeScope.cs:609
static Type GetCollectionElementType([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors|DynamicallyAccessedMemberTypes.PublicMethods|DynamicallyAccessedMemberTypes.PublicFields|DynamicallyAccessedMemberTypes.PublicNestedTypes|DynamicallyAccessedMemberTypes.PublicProperties|DynamicallyAccessedMemberTypes.PublicEvents)] Type type, string memberInfo)
Definition TypeScope.cs:902
static XmlQualifiedName ParseWsdlArrayType(string type, out string dims, XmlSchemaObject parent)
Definition TypeScope.cs:907
Type GetTypeFromTypeDesc(TypeDesc typeDesc)
Definition TypeScope.cs:308
TypeDesc GetTypeDesc(Type type, MemberInfo source, bool directReference)
Definition TypeScope.cs:251
static void AddNonXsdPrimitive([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type type, string dataTypeName, string ns, string formatterName, XmlQualifiedName baseTypeName, XmlSchemaFacet[] facets, TypeFlags flags)
Definition TypeScope.cs:199
static bool CanWriteProperty(PropertyInfo propertyInfo, TypeDesc typeDesc)
Definition TypeScope.cs:658
void AddTypeMapping(TypeMapping typeMapping)
Definition TypeScope.cs:930
static readonly string[] s_unsupportedTypes
Definition TypeScope.cs:24
static PropertyInfo GetDefaultIndexer([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors|DynamicallyAccessedMemberTypes.PublicMethods|DynamicallyAccessedMemberTypes.PublicFields|DynamicallyAccessedMemberTypes.PublicNestedTypes|DynamicallyAccessedMemberTypes.PublicProperties|DynamicallyAccessedMemberTypes.PublicEvents)] Type type, string memberInfo)
Definition TypeScope.cs:848
TypeDesc GetArrayTypeDesc(Type type)
Definition TypeScope.cs:280
static MemberMapping[] GetSettableMembers(StructMapping structMapping)
Definition TypeScope.cs:628
static bool IsOptionalValue(Type type)
Definition TypeScope.cs:537
TypeDesc GetTypeDesc(XmlSchemaSimpleType dataType)
Definition TypeScope.cs:239
static string TypeName(Type t)
Definition TypeScope.cs:546
readonly Hashtable _typeDescs
Definition TypeScope.cs:12
static TypeFlags GetConstructorFlags([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors|DynamicallyAccessedMemberTypes.NonPublicConstructors)] Type type, ref Exception exception)
Definition TypeScope.cs:769
TypeDesc GetTypeDesc(Type type, MemberInfo source, bool directReference, bool throwOnError)
Definition TypeScope.cs:257
static MemberMapping[] GetSettableMembers(StructMapping mapping, Dictionary< string, MemberInfo > memberInfos)
Definition TypeScope.cs:671
TypeDesc GetTypeDesc(string name, string ns, TypeFlags flags)
Definition TypeScope.cs:229
static readonly Hashtable s_primitiveTypes
Definition TypeScope.cs:18
TypeMapping GetTypeMappingFromTypeDesc(TypeDesc typeDesc)
Definition TypeScope.cs:296
static MemberMapping[] GetAllMembers(StructMapping mapping, Dictionary< string, MemberInfo > memberInfos)
Definition TypeScope.cs:621
TypeDesc GetTypeDesc(Type type)
Definition TypeScope.cs:245
static Type GetArrayElementType(Type type, string memberInfo)
Definition TypeScope.cs:576
static readonly NameTable s_primitiveNames
Definition TypeScope.cs:22
static void AddSoapEncodedPrimitive([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type type, string dataTypeName, string ns, string formatterName, XmlQualifiedName baseTypeName, TypeFlags flags)
Definition TypeScope.cs:219
TypeDesc GetTypeDesc(string name, string ns)
Definition TypeScope.cs:224
static Type GetEnumeratorElementType(Type type, ref TypeFlags flags)
Definition TypeScope.cs:797
static void AddSoapEncodedTypes(string ns)
Definition TypeScope.cs:152
readonly Hashtable _arrayTypeDescs
Definition TypeScope.cs:14
static MemberMapping[] GetAllMembers(StructMapping mapping)
Definition TypeScope.cs:598
TypeDesc ImportTypeDesc(Type type, MemberInfo memberInfo, bool directReference)
Definition TypeScope.cs:325
static readonly Hashtable s_primitiveDataTypes
Definition TypeScope.cs:20
static bool IsArraySegment(Type t)
Definition TypeScope.cs:528
static bool ShouldBeReplaced(MemberInfo memberInfoToBeReplaced, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields|DynamicallyAccessedMemberTypes.NonPublicFields|DynamicallyAccessedMemberTypes.PublicProperties|DynamicallyAccessedMemberTypes.NonPublicProperties)] Type derivedType, out MemberInfo replacedInfo)
Definition TypeScope.cs:725
TypeCode
Definition TypeCode.cs:4