Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
DataContract.cs
Go to the documentation of this file.
5using System.Linq;
8using System.Text;
10using System.Xml;
11
13
14internal abstract class DataContract
15{
17 {
19
20 private static DataContract[] s_dataContractCache = new DataContract[32];
21
22 private static int s_dataContractID;
23
25
27
29
31
33
34 private static readonly TypeHandleRef s_typeHandleRef = new TypeHandleRef();
35
36 private static readonly object s_cacheLock = new object();
37
38 private static readonly object s_createDataContractLock = new object();
39
40 private static readonly object s_initBuiltInContractsLock = new object();
41
42 private static readonly object s_namespacesLock = new object();
43
44 private static readonly object s_clrTypeStringsLock = new object();
45
48
50
51 private bool _isReference;
52
53 private bool _isValueType;
54
56
58
60
62
63 private bool _parseMethodSet;
64
66
69 {
70 get
71 {
72 return _underlyingType;
73 }
74 set
75 {
77 }
78 }
79
81 {
82 get
83 {
84 if (_originalUnderlyingType == null)
85 {
87 }
89 }
90 set
91 {
93 }
94 }
95
96 internal virtual bool IsBuiltInDataContract => false;
97
99
100 internal bool IsReference
101 {
102 get
103 {
104 return _isReference;
105 }
106 set
107 {
109 }
110 }
111
112 internal bool IsValueType
113 {
114 get
115 {
116 return _isValueType;
117 }
118 set
119 {
121 }
122 }
123
125 {
126 get
127 {
128 return _stableName;
129 }
130 set
131 {
133 }
134 }
135
137 {
138 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
139 get
140 {
141 return null;
142 }
143 set
144 {
145 }
146 }
147
148 internal virtual bool IsISerializable
149 {
150 get
151 {
152 return false;
153 }
154 set
155 {
157 }
158 }
159
161 {
162 get
163 {
164 return _name;
165 }
166 set
167 {
168 _name = value;
169 }
170 }
171
173 {
174 get
175 {
176 return _ns;
177 }
178 set
179 {
180 _ns = value;
181 }
182 }
183
184 internal virtual bool HasRoot
185 {
186 get
187 {
188 return true;
189 }
190 set
191 {
192 }
193 }
194
196 {
197 get
198 {
199 return _name;
200 }
201 set
202 {
203 _name = value;
204 }
205 }
206
208 {
209 get
210 {
211 return _ns;
212 }
213 set
214 {
215 _ns = value;
216 }
217 }
218
219 internal virtual bool CanContainReferences => true;
220
221 internal virtual bool IsPrimitive => false;
222
224 {
225 get
226 {
227 if (!_parseMethodSet)
228 {
229 MethodInfo method = UnderlyingType.GetMethod("Parse", BindingFlags.Static | BindingFlags.Public, new Type[1] { typeof(string) });
230 if (method != null && method.ReturnType == UnderlyingType)
231 {
233 }
234 _parseMethodSet = true;
235 }
236 return _parseMethod;
237 }
238 }
239
240 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
242 {
244 if (dataContract == null)
245 {
248 return dataContract;
249 }
250 return dataContract.GetValidContract();
251 }
252
253 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
264
274
276 {
277 int id = DataContract.GetId(classContract.TypeForInitialization.TypeHandle);
279 {
280 return id;
281 }
282 int num = s_dataContractID;
283 for (int i = 0; i < num; i++)
284 {
286 {
287 return i;
288 }
289 }
291 }
292
294 {
295 if (cachedContract != null)
296 {
297 return cachedContract.UnderlyingType == contract.UnderlyingType;
298 }
299 return false;
300 }
301
302 internal static int GetId(RuntimeTypeHandle typeHandle)
303 {
305 {
308 if (!s_typeToIDCache.TryGetValue(s_typeHandleRef, out var value))
309 {
310 int num = s_dataContractID++;
311 if (num >= s_dataContractCache.Length)
312 {
313 int num2 = ((num < 1073741823) ? (num * 2) : int.MaxValue);
314 if (num2 <= num)
315 {
317 }
319 }
320 value = new IntRef(num);
321 try
322 {
324 }
325 catch (Exception ex)
326 {
328 }
329 }
330 return value.Value;
331 }
332 }
333
334 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
336 {
338 if (dataContract == null)
339 {
341 {
343 if (dataContract == null)
344 {
345 if (type == null)
346 {
348 }
351 if (dataContract != null)
352 {
354 return dataContract;
355 }
357 }
358 }
359 }
360 return dataContract;
361 }
362
363 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
407
408 [MethodImpl(MethodImplOptions.NoInlining)]
410 {
412 {
414 }
415 }
416
417 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
440
441 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
443 {
445 {
447 }
449 {
451 }
452 if (type.IsGenericType && type.GetGenericTypeDefinition() == Globals.TypeOfKeyValuePair)
453 {
454 return Globals.TypeOfKeyValuePairAdapter.MakeGenericType(type.GetGenericArguments());
455 }
456 return type;
457 }
458
460 {
462 {
464 }
466 {
468 }
469 return type;
470 }
471
473 {
474 if (Globals.TypeOfDateTimeOffset.TypeHandle.Equals(typeHandle))
475 {
476 return Globals.TypeOfDateTimeOffsetAdapter.TypeHandle;
477 }
478 if (Globals.TypeOfMemoryStream.TypeHandle.Equals(typeHandle))
479 {
480 return Globals.TypeOfMemoryStreamAdapter.TypeHandle;
481 }
482 return typeHandle;
483 }
484
485 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
487 {
489 {
491 }
493 {
494 if (s_typeToBuiltInContract == null)
495 {
497 }
498 if (!s_typeToBuiltInContract.TryGetValue(type, out var value))
499 {
502 }
503 return value;
504 }
505 }
506
507 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
508 public static DataContract GetBuiltInDataContract(string name, string ns)
509 {
511 {
512 if (s_nameToBuiltInContract == null)
513 {
515 }
517 if (!s_nameToBuiltInContract.TryGetValue(key, out var value))
518 {
521 }
522 return value;
523 }
524 }
525
526 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
527 public static DataContract GetBuiltInDataContract(string typeName)
528 {
529 if (!typeName.StartsWith("System.", StringComparison.Ordinal))
530 {
531 return null;
532 }
534 {
535 if (s_nameToBuiltInContract == null)
536 {
538 }
539 XmlQualifiedName key = new XmlQualifiedName(typeName);
540 if (!s_nameToBuiltInContract.TryGetValue(key, out var value))
541 {
542 Type type = null;
543 switch (typeName.Substring(7))
544 {
545 case "Char":
546 type = typeof(char);
547 break;
548 case "Boolean":
549 type = typeof(bool);
550 break;
551 case "SByte":
552 type = typeof(sbyte);
553 break;
554 case "Byte":
555 type = typeof(byte);
556 break;
557 case "Int16":
558 type = typeof(short);
559 break;
560 case "UInt16":
561 type = typeof(ushort);
562 break;
563 case "Int32":
564 type = typeof(int);
565 break;
566 case "UInt32":
567 type = typeof(uint);
568 break;
569 case "Int64":
570 type = typeof(long);
571 break;
572 case "UInt64":
573 type = typeof(ulong);
574 break;
575 case "Single":
576 type = typeof(float);
577 break;
578 case "Double":
579 type = typeof(double);
580 break;
581 case "Decimal":
582 type = typeof(decimal);
583 break;
584 case "DateTime":
586 break;
587 case "String":
588 type = typeof(string);
589 break;
590 case "Byte[]":
591 type = typeof(byte[]);
592 break;
593 case "Object":
594 type = typeof(object);
595 break;
596 case "TimeSpan":
598 break;
599 case "Guid":
600 type = typeof(Guid);
601 break;
602 case "Uri":
603 type = typeof(Uri);
604 break;
605 case "Xml.XmlQualifiedName":
607 break;
608 case "Enum":
609 type = typeof(Enum);
610 break;
611 case "ValueType":
613 break;
614 case "Array":
615 type = typeof(Array);
616 break;
617 case "Xml.XmlElement":
619 break;
620 case "Xml.XmlNode[]":
621 type = typeof(XmlNode[]);
622 break;
623 }
624 if (type != null)
625 {
627 }
629 }
630 return value;
631 }
632 }
633
634 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
636 {
637 if (type.IsEnum)
638 {
639 dataContract = null;
640 return false;
641 }
642 dataContract = null;
643 switch (type.GetTypeCode())
644 {
645 case TypeCode.Boolean:
647 break;
648 case TypeCode.Byte:
650 break;
651 case TypeCode.Char:
653 break;
654 case TypeCode.DateTime:
656 break;
657 case TypeCode.Decimal:
659 break;
660 case TypeCode.Double:
662 break;
663 case TypeCode.Int16:
665 break;
666 case TypeCode.Int32:
668 break;
669 case TypeCode.Int64:
671 break;
672 case TypeCode.SByte:
674 break;
675 case TypeCode.Single:
677 break;
678 case TypeCode.String:
680 break;
681 case TypeCode.UInt16:
683 break;
684 case TypeCode.UInt32:
686 break;
687 case TypeCode.UInt64:
689 break;
690 default:
691 if (type == typeof(byte[]))
692 {
694 }
695 else if (type == typeof(object))
696 {
698 }
699 else if (type == typeof(Uri))
700 {
702 }
703 else if (type == typeof(XmlQualifiedName))
704 {
706 }
707 else if (type == typeof(TimeSpan))
708 {
710 }
711 else if (type == typeof(Guid))
712 {
714 }
715 else if (type == typeof(Enum) || type == typeof(ValueType))
716 {
718 }
719 else if (type == typeof(Array))
720 {
722 }
723 else if (type == typeof(XmlElement) || type == typeof(XmlNode[]))
724 {
726 }
727 break;
728 }
729 return dataContract != null;
730 }
731
732 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
733 public static bool TryCreateBuiltInDataContract(string name, string ns, [NotNullWhen(true)] out DataContract dataContract)
734 {
735 dataContract = null;
736 if (ns == DictionaryGlobals.SchemaNamespace.Value)
737 {
739 {
741 }
743 {
745 }
747 {
749 }
750 else if (DictionaryGlobals.ShortLocalName.Value == name)
751 {
753 }
755 {
757 }
758 else if (DictionaryGlobals.IntLocalName.Value == name)
759 {
761 }
763 {
765 }
766 else if (DictionaryGlobals.LongLocalName.Value == name)
767 {
769 }
770 else if (DictionaryGlobals.integerLocalName.Value == name)
771 {
773 }
775 {
777 }
779 {
781 }
783 {
785 }
787 {
789 }
791 {
793 }
794 else if (DictionaryGlobals.FloatLocalName.Value == name)
795 {
797 }
798 else if (DictionaryGlobals.DoubleLocalName.Value == name)
799 {
801 }
802 else if (DictionaryGlobals.DecimalLocalName.Value == name)
803 {
805 }
806 else if (DictionaryGlobals.DateTimeLocalName.Value == name)
807 {
809 }
810 else if (DictionaryGlobals.StringLocalName.Value == name)
811 {
813 }
814 else if (DictionaryGlobals.timeLocalName.Value == name)
815 {
817 }
818 else if (DictionaryGlobals.dateLocalName.Value == name)
819 {
821 }
822 else if (DictionaryGlobals.hexBinaryLocalName.Value == name)
823 {
825 }
827 {
829 }
830 else if (DictionaryGlobals.gYearLocalName.Value == name)
831 {
833 }
834 else if (DictionaryGlobals.gMonthDayLocalName.Value == name)
835 {
837 }
838 else if (DictionaryGlobals.gDayLocalName.Value == name)
839 {
841 }
842 else if (DictionaryGlobals.gMonthLocalName.Value == name)
843 {
845 }
847 {
849 }
850 else if (DictionaryGlobals.tokenLocalName.Value == name)
851 {
853 }
854 else if (DictionaryGlobals.languageLocalName.Value == name)
855 {
857 }
858 else if (DictionaryGlobals.NameLocalName.Value == name)
859 {
861 }
862 else if (DictionaryGlobals.NCNameLocalName.Value == name)
863 {
865 }
866 else if (DictionaryGlobals.XSDIDLocalName.Value == name)
867 {
869 }
870 else if (DictionaryGlobals.IDREFLocalName.Value == name)
871 {
873 }
874 else if (DictionaryGlobals.IDREFSLocalName.Value == name)
875 {
877 }
878 else if (DictionaryGlobals.ENTITYLocalName.Value == name)
879 {
881 }
882 else if (DictionaryGlobals.ENTITIESLocalName.Value == name)
883 {
885 }
886 else if (DictionaryGlobals.NMTOKENLocalName.Value == name)
887 {
889 }
890 else if (DictionaryGlobals.NMTOKENSLocalName.Value == name)
891 {
893 }
894 else if (DictionaryGlobals.ByteArrayLocalName.Value == name)
895 {
897 }
898 else if (DictionaryGlobals.ObjectLocalName.Value == name)
899 {
901 }
902 else if (DictionaryGlobals.TimeSpanLocalName.Value == name)
903 {
905 }
906 else if (DictionaryGlobals.UriLocalName.Value == name)
907 {
909 }
910 else if (DictionaryGlobals.QNameLocalName.Value == name)
911 {
913 }
914 }
915 else if (ns == DictionaryGlobals.SerializationNamespace.Value)
916 {
918 {
920 }
921 else if (DictionaryGlobals.GuidLocalName.Value == name)
922 {
924 }
925 else if (DictionaryGlobals.CharLocalName.Value == name)
926 {
928 }
929 else if ("ArrayOfanyType" == name)
930 {
932 }
933 }
934 else if (ns == DictionaryGlobals.AsmxTypesNamespace.Value)
935 {
937 {
939 }
940 else if (DictionaryGlobals.GuidLocalName.Value == name)
941 {
943 }
944 }
945 else if (ns == "http://schemas.datacontract.org/2004/07/System.Xml")
946 {
947 if (name == "XmlElement")
948 {
950 }
951 else if (name == "ArrayOfXmlNode")
952 {
954 }
955 }
956 return dataContract != null;
957 }
958
959 internal static string GetNamespace(string key)
960 {
962 {
963 if (s_namespaces == null)
964 {
966 }
967 if (s_namespaces.TryGetValue(key, out var value))
968 {
969 return value;
970 }
971 try
972 {
973 s_namespaces.Add(key, key);
974 }
975 catch (Exception ex)
976 {
978 }
979 return key;
980 }
981 }
982
984 {
986 {
987 if (s_clrTypeStrings == null)
988 {
991 try
992 {
993 s_clrTypeStrings.Add(Globals.TypeOfInt.Assembly.FullName, s_clrTypeStringsDictionary.Add("0"));
994 }
995 catch (Exception ex)
996 {
998 }
999 }
1000 if (s_clrTypeStrings.TryGetValue(key, out var value))
1001 {
1002 return value;
1003 }
1005 try
1006 {
1008 }
1009 catch (Exception ex2)
1010 {
1012 }
1013 return value;
1014 }
1015 }
1016
1018 internal static void ThrowInvalidDataContractException(string message, Type type)
1019 {
1020 if (type != null)
1021 {
1023 {
1025 try
1026 {
1028 }
1029 catch (Exception ex)
1030 {
1032 }
1033 }
1034 }
1036 }
1037
1044
1045 [MemberNotNull("_typeForInitialization")]
1050
1058
1060 {
1061 Name = name;
1062 Namespace = ns;
1064 }
1065
1067 internal void ThrowInvalidDataContractException(string message)
1068 {
1070 }
1071 }
1072
1074
1076
1078
1079 internal const string SerializerTrimmerWarning = "Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.";
1080
1082
1084
1086
1089 {
1090 get
1091 {
1092 return _helper.UnderlyingType;
1093 }
1094 set
1095 {
1097 }
1098 }
1099
1101 {
1102 get
1103 {
1105 }
1106 set
1107 {
1109 }
1110 }
1111
1112 public virtual bool IsBuiltInDataContract
1113 {
1114 get
1115 {
1117 }
1118 set
1119 {
1120 }
1121 }
1122
1124
1125 public bool IsValueType
1126 {
1127 get
1128 {
1129 return _helper.IsValueType;
1130 }
1131 set
1132 {
1134 }
1135 }
1136
1137 public bool IsReference
1138 {
1139 get
1140 {
1141 return _helper.IsReference;
1142 }
1143 set
1144 {
1146 }
1147 }
1148
1150 {
1151 get
1152 {
1153 return _helper.StableName;
1154 }
1155 set
1156 {
1158 }
1159 }
1160
1162 {
1163 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
1164 get
1165 {
1167 }
1168 set
1169 {
1171 }
1172 }
1173
1174 public virtual bool IsISerializable
1175 {
1176 get
1177 {
1178 return _helper.IsISerializable;
1179 }
1180 set
1181 {
1183 }
1184 }
1185
1187 {
1188 get
1189 {
1190 return _name;
1191 }
1192 set
1193 {
1194 _name = value;
1195 }
1196 }
1197
1199 {
1200 get
1201 {
1202 return _ns;
1203 }
1204 set
1205 {
1206 _ns = value;
1207 }
1208 }
1209
1210 public virtual bool HasRoot
1211 {
1212 get
1213 {
1214 return true;
1215 }
1216 set
1217 {
1218 }
1219 }
1220
1222 {
1223 get
1224 {
1226 }
1227 set
1228 {
1230 }
1231 }
1232
1234 {
1235 get
1236 {
1238 }
1239 set
1240 {
1242 }
1243 }
1244
1245 internal virtual bool CanContainReferences => true;
1246
1247 internal virtual bool IsPrimitive => false;
1248
1250 {
1251 return s_dataContracts;
1252 }
1253
1255 {
1256 _helper = helper;
1257 _name = helper.Name;
1258 _ns = helper.Namespace;
1259 }
1260
1262 {
1263 if (!s_dataContracts.TryGetValue(type, out var value))
1264 {
1265 return null;
1266 }
1267 return value;
1268 }
1269
1275
1277 {
1278 return null;
1279 }
1280
1281 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
1283 {
1284 return GetDataContract(type.TypeHandle, type);
1285 }
1286
1287 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
1292
1293 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
1300
1301 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
1307
1308 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
1313
1314 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
1325
1326 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
1331
1336
1341
1343 {
1345 }
1346
1347 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
1352
1353 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
1354 public static DataContract GetBuiltInDataContract(string name, string ns)
1355 {
1357 }
1358
1359 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
1360 public static DataContract GetBuiltInDataContract(string typeName)
1361 {
1363 }
1364
1365 internal static string GetNamespace(string key)
1366 {
1368 }
1369
1371 {
1373 }
1374
1376 internal static void ThrowInvalidDataContractException(string message, Type type)
1377 {
1379 }
1380
1381 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
1386
1387 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
1392
1393 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
1398
1403
1405 {
1407 {
1408 writer.WriteStartElement("z", name, ns);
1409 }
1410 else
1411 {
1412 writer.WriteStartElement(name, ns);
1413 }
1414 }
1415
1417 {
1418 return this;
1419 }
1420
1422 {
1423 return this;
1424 }
1425
1426 internal virtual bool IsValidContract(SerializationMode mode)
1427 {
1428 return true;
1429 }
1430
1431 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
1432 internal static bool IsTypeSerializable(Type type)
1433 {
1434 return IsTypeSerializable(type, new HashSet<Type>());
1435 }
1436
1437 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
1439 {
1440 if (type.IsSerializable || type.IsEnum || type.IsDefined(Globals.TypeOfDataContractAttribute, inherit: false) || type.IsInterface || type.IsPointer || type == Globals.TypeOfDBNull || Globals.TypeOfIXmlSerializable.IsAssignableFrom(type))
1441 {
1442 return true;
1443 }
1445 {
1448 {
1449 return true;
1450 }
1451 }
1452 if (GetBuiltInDataContract(type) == null)
1453 {
1455 }
1456 return true;
1457 }
1458
1471
1473 {
1474 Type result = type;
1475 while (type.IsGenericType && type.GetGenericTypeDefinition() == Globals.TypeOfNullable)
1476 {
1477 result = type;
1479 }
1480 return result;
1481 }
1482
1484 {
1485 while (type.IsGenericType && type.GetGenericTypeDefinition() == Globals.TypeOfNullable)
1486 {
1487 type = type.GetGenericArguments()[0];
1488 }
1489 return type;
1490 }
1491
1492 private static bool IsAlpha(char ch)
1493 {
1494 if (ch < 'A' || ch > 'Z')
1495 {
1496 if (ch >= 'a')
1497 {
1498 return ch <= 'z';
1499 }
1500 return false;
1501 }
1502 return true;
1503 }
1504
1505 private static bool IsDigit(char ch)
1506 {
1507 if (ch >= '0')
1508 {
1509 return ch <= '9';
1510 }
1511 return false;
1512 }
1513
1514 private static bool IsAsciiLocalName(string localName)
1515 {
1516 if (localName.Length == 0)
1517 {
1518 return false;
1519 }
1520 if (!IsAlpha(localName[0]))
1521 {
1522 return false;
1523 }
1524 for (int i = 1; i < localName.Length; i++)
1525 {
1526 char ch = localName[i];
1527 if (!IsAlpha(ch) && !IsDigit(ch))
1528 {
1529 return false;
1530 }
1531 }
1532 return true;
1533 }
1534
1535 internal static string EncodeLocalName(string localName)
1536 {
1537 if (IsAsciiLocalName(localName))
1538 {
1539 return localName;
1540 }
1541 if (IsValidNCName(localName))
1542 {
1543 return localName;
1544 }
1545 return XmlConvert.EncodeLocalName(localName);
1546 }
1547
1548 internal static bool IsValidNCName(string name)
1549 {
1550 try
1551 {
1553 return true;
1554 }
1555 catch (XmlException)
1556 {
1557 return false;
1558 }
1559 catch (Exception)
1560 {
1561 return false;
1562 }
1563 }
1564
1565 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
1567 {
1568 bool hasDataContract;
1570 }
1571
1572 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
1593
1594 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
1596 {
1597 string text = null;
1598 string text2 = null;
1599 if (dataContractAttribute.IsNameSetExplicitly)
1600 {
1602 if (text == null || text.Length == 0)
1603 {
1605 }
1606 if (type.IsGenericType && !type.IsGenericTypeDefinition)
1607 {
1609 }
1611 }
1612 else
1613 {
1615 }
1616 if (dataContractAttribute.IsNamespaceSetExplicitly)
1617 {
1618 text2 = dataContractAttribute.Namespace;
1619 if (text2 == null)
1620 {
1622 }
1624 }
1625 else
1626 {
1628 }
1630 }
1631
1632 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
1646
1647 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
1649 {
1650 stableName = null;
1652 if (builtInDataContract != null)
1653 {
1654 stableName = builtInDataContract.StableName;
1655 }
1656 else if (Globals.TypeOfIXmlSerializable.IsAssignableFrom(type))
1657 {
1660 }
1661 else if (type.IsArray)
1662 {
1663 stableName = GetCollectionStableName(type, type.GetElementType(), out var _);
1664 }
1665 return stableName != null;
1666 }
1667
1669 {
1670 dataContractAttribute = null;
1671 object[] array = type.GetCustomAttributes(Globals.TypeOfDataContractAttribute, inherit: false).ToArray();
1672 if (array != null && array.Length != 0)
1673 {
1675 }
1676 return dataContractAttribute != null;
1677 }
1678
1679 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
1681 {
1682 object[] array = type.GetCustomAttributes(Globals.TypeOfCollectionDataContractAttribute, inherit: false).ToArray();
1683 string text;
1684 string text2;
1685 if (array != null && array.Length != 0)
1686 {
1688 if (collectionContractAttribute.IsNameSetExplicitly)
1689 {
1691 if (text == null || text.Length == 0)
1692 {
1694 }
1695 if (type.IsGenericType && !type.IsGenericTypeDefinition)
1696 {
1698 }
1700 }
1701 else
1702 {
1704 }
1705 if (collectionContractAttribute.IsNamespaceSetExplicitly)
1706 {
1708 if (text2 == null)
1709 {
1711 }
1713 }
1714 else
1715 {
1717 }
1718 }
1719 else
1720 {
1722 string text3 = "ArrayOf" + GetArrayPrefix(ref itemType);
1724 text = text3 + stableName.Name;
1726 }
1728 }
1729
1730 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
1731 private static string GetArrayPrefix(ref Type itemType)
1732 {
1733 string text = string.Empty;
1734 while (itemType.IsArray && GetBuiltInDataContract(itemType) == null)
1735 {
1736 text += "ArrayOf";
1737 itemType = itemType.GetElementType();
1738 }
1739 return text;
1740 }
1741
1742 internal static string GetCollectionNamespace(string elementNs)
1743 {
1745 {
1746 return elementNs;
1747 }
1748 return "http://schemas.microsoft.com/2003/10/Serialization/Arrays";
1749 }
1750
1751 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
1756
1757 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
1758 private static string GetDefaultStableLocalName(Type type)
1759 {
1760 if (type.IsGenericParameter)
1761 {
1762 return "{" + type.GenericParameterPosition + "}";
1763 }
1764 string text = null;
1765 if (type.IsArray)
1766 {
1768 }
1769 string text2;
1770 if (type.DeclaringType == null)
1771 {
1772 text2 = type.Name;
1773 }
1774 else
1775 {
1776 int num = ((type.Namespace != null) ? type.Namespace.Length : 0);
1777 if (num > 0)
1778 {
1779 num++;
1780 }
1781 text2 = GetClrTypeFullName(type).Substring(num).Replace('+', '.');
1782 }
1783 if (text != null)
1784 {
1785 text2 = text + text2;
1786 }
1787 if (type.IsGenericType)
1788 {
1791 bool flag = true;
1792 int num2 = text2.IndexOf('[');
1793 if (num2 >= 0)
1794 {
1795 text2 = text2.Substring(0, num2);
1796 }
1798 bool isGenericTypeDefinition = type.IsGenericTypeDefinition;
1799 Type[] genericArguments = type.GetGenericArguments();
1800 for (int i = 0; i < genericArguments.Length; i++)
1801 {
1804 {
1805 stringBuilder.Append('{').Append(i).Append('}');
1806 continue;
1807 }
1809 stringBuilder.Append(stableName.Name);
1810 stringBuilder2.Append(' ').Append(stableName.Namespace);
1811 if (flag)
1812 {
1813 flag = IsBuiltInNamespace(stableName.Namespace);
1814 }
1815 }
1817 {
1818 stringBuilder.Append("{#}");
1819 }
1820 else if (dataContractNameForGenericName.Count > 1 || !flag)
1821 {
1822 foreach (int item in dataContractNameForGenericName)
1823 {
1824 stringBuilder2.Insert(0, item.ToString(CultureInfo.InvariantCulture)).Insert(0, " ");
1825 }
1827 }
1828 text2 = stringBuilder.ToString();
1829 }
1830 return EncodeLocalName(text2);
1831 }
1832
1834 {
1835 string text = type.Namespace;
1836 if (text == null)
1837 {
1838 text = string.Empty;
1839 }
1840 string clrNs = text;
1841 object[] nsAttributes = type.Module.GetCustomAttributes(typeof(ContractNamespaceAttribute)).ToArray();
1843 if (text2 == null)
1844 {
1845 string clrNs2 = text;
1846 nsAttributes = type.Assembly.GetCustomAttributes(typeof(ContractNamespaceAttribute)).ToArray();
1848 }
1849 if (text2 == null)
1850 {
1852 }
1853 else
1854 {
1856 }
1857 return text2;
1858 }
1859
1860 internal static List<int> GetDataContractNameForGenericName(string typeName, StringBuilder localName)
1861 {
1862 List<int> list = new List<int>();
1863 int num = 0;
1864 while (true)
1865 {
1866 int num2 = typeName.IndexOf('`', num);
1867 if (num2 < 0)
1868 {
1869 localName?.Append(typeName.AsSpan(num));
1870 list.Add(0);
1871 break;
1872 }
1873 if (localName != null)
1874 {
1875 string text = typeName.Substring(num, num2 - num);
1876 localName.Append(text.Equals("KeyValuePairAdapter") ? "KeyValuePair" : text);
1877 }
1878 while ((num = typeName.IndexOf('.', num + 1, num2 - num - 1)) >= 0)
1879 {
1880 list.Add(0);
1881 }
1882 num = typeName.IndexOf('.', num2);
1883 if (num < 0)
1884 {
1885 list.Add(int.Parse(typeName.AsSpan(num2 + 1), NumberStyles.Integer, CultureInfo.InvariantCulture));
1886 break;
1887 }
1888 list.Add(int.Parse(typeName.AsSpan(num2 + 1, num - num2 - 1), NumberStyles.Integer, CultureInfo.InvariantCulture));
1889 }
1890 localName?.Append("Of");
1891 return list;
1892 }
1893
1894 internal static bool IsBuiltInNamespace(string ns)
1895 {
1896 if (!(ns == "http://www.w3.org/2001/XMLSchema"))
1897 {
1898 return ns == "http://schemas.microsoft.com/2003/10/Serialization/";
1899 }
1900 return true;
1901 }
1902
1903 internal static string GetDefaultStableNamespace(Type type)
1904 {
1905 if (type.IsGenericParameter)
1906 {
1907 return "{ns}";
1908 }
1909 return GetDefaultStableNamespace(type.Namespace);
1910 }
1911
1912 internal static XmlQualifiedName CreateQualifiedName(string localName, string ns)
1913 {
1914 return new XmlQualifiedName(localName, GetNamespace(ns));
1915 }
1916
1917 internal static string GetDefaultStableNamespace(string clrNs)
1918 {
1919 if (clrNs == null)
1920 {
1921 clrNs = string.Empty;
1922 }
1924 }
1925
1926 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
1927 internal static void GetDefaultStableName(string fullTypeName, out string localName, out string ns)
1928 {
1930 GetDefaultStableName(typeReference, out localName, out ns);
1931 }
1932
1933 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
1934 private static void GetDefaultStableName(CodeTypeReference typeReference, out string localName, out string ns)
1935 {
1936 string baseType = typeReference.BaseType;
1938 if (builtInDataContract != null)
1939 {
1940 localName = builtInDataContract.StableName.Name;
1941 ns = builtInDataContract.StableName.Namespace;
1942 return;
1943 }
1944 GetClrNameAndNamespace(baseType, out localName, out ns);
1945 if (typeReference.TypeArguments.Count > 0)
1946 {
1949 bool flag = true;
1951 foreach (CodeTypeReference typeArgument in typeReference.TypeArguments)
1952 {
1954 stringBuilder.Append(localName2);
1955 stringBuilder2.Append(' ').Append(ns2);
1956 if (flag)
1957 {
1958 flag = IsBuiltInNamespace(ns2);
1959 }
1960 }
1961 if (dataContractNameForGenericName.Count > 1 || !flag)
1962 {
1963 foreach (int item in dataContractNameForGenericName)
1964 {
1965 stringBuilder2.Insert(0, item).Insert(0, ' ');
1966 }
1968 }
1969 localName = stringBuilder.ToString();
1970 }
1971 localName = EncodeLocalName(localName);
1973 }
1974
1976 {
1977 if (dataContractNs.Length > 0)
1978 {
1979 string text = dataContractNs.Trim();
1980 if (text.Length == 0 || text.IndexOf("##", StringComparison.Ordinal) != -1)
1981 {
1983 }
1985 }
1986 if (Uri.TryCreate(dataContractNs, UriKind.RelativeOrAbsolute, out Uri result))
1987 {
1988 if (result.ToString() == "http://schemas.microsoft.com/2003/10/Serialization/")
1989 {
1990 ThrowInvalidDataContractException(System.SR.Format(System.SR.DataContractNamespaceReserved, "http://schemas.microsoft.com/2003/10/Serialization/"), type);
1991 }
1992 }
1993 else
1994 {
1996 }
1997 }
1998
1999 internal static string GetClrTypeFullName(Type type)
2000 {
2001 if (type.IsGenericTypeDefinition || !type.ContainsGenericParameters)
2002 {
2003 return type.FullName;
2004 }
2005 return type.Namespace + "." + type.Name;
2006 }
2007
2008 internal static void GetClrNameAndNamespace(string fullTypeName, out string localName, out string ns)
2009 {
2010 int num = fullTypeName.LastIndexOf('.');
2011 if (num < 0)
2012 {
2013 ns = string.Empty;
2014 localName = fullTypeName.Replace('+', '.');
2015 }
2016 else
2017 {
2018 ns = fullTypeName.Substring(0, num);
2019 localName = fullTypeName.Substring(num + 1).Replace('+', '.');
2020 }
2021 int num2 = localName.IndexOf('[');
2022 if (num2 >= 0)
2023 {
2024 localName = localName.Substring(0, num2);
2025 }
2026 }
2027
2028 internal static string GetDataContractNamespaceFromUri(string uriString)
2029 {
2030 if (!uriString.StartsWith("http://schemas.datacontract.org/2004/07/", StringComparison.Ordinal))
2031 {
2032 return uriString;
2033 }
2034 return uriString.Substring("http://schemas.datacontract.org/2004/07/".Length);
2035 }
2036
2037 private static string GetGlobalDataContractNamespace(string clrNs, object[] nsAttributes)
2038 {
2039 string text = null;
2040 for (int i = 0; i < nsAttributes.Length; i++)
2041 {
2043 string text2 = contractNamespaceAttribute.ClrNamespace;
2044 if (text2 == null)
2045 {
2046 text2 = string.Empty;
2047 }
2048 if (text2 == clrNs)
2049 {
2050 if (contractNamespaceAttribute.ContractNamespace == null)
2051 {
2053 }
2054 if (text != null)
2055 {
2057 }
2058 text = contractNamespaceAttribute.ContractNamespace;
2059 }
2060 }
2061 return text;
2062 }
2063
2064 private static string GetNamespacesDigest(string namespaces)
2065 {
2066 byte[] bytes = Encoding.UTF8.GetBytes(namespaces);
2067 byte[] inArray = ComputeHash(bytes);
2068 char[] array = new char[24];
2069 int num = Convert.ToBase64CharArray(inArray, 0, 6, array, 0);
2071 for (int i = 0; i < num; i++)
2072 {
2073 char c = array[i];
2074 switch (c)
2075 {
2076 case '/':
2077 stringBuilder.Append("_S");
2078 break;
2079 case '+':
2080 stringBuilder.Append("_P");
2081 break;
2082 default:
2083 stringBuilder.Append(c);
2084 break;
2085 case '=':
2086 break;
2087 }
2088 }
2089 return stringBuilder.ToString();
2090 }
2091
2092 private static byte[] ComputeHash(byte[] namespaces)
2093 {
2094 int[] array = new int[16]
2095 {
2096 7, 12, 17, 22, 5, 9, 14, 20, 4, 11,
2097 16, 23, 6, 10, 15, 21
2098 };
2099 uint[] array2 = new uint[64]
2100 {
2101 3614090360u, 3905402710u, 606105819u, 3250441966u, 4118548399u, 1200080426u, 2821735955u, 4249261313u, 1770035416u, 2336552879u,
2102 4294925233u, 2304563134u, 1804603682u, 4254626195u, 2792965006u, 1236535329u, 4129170786u, 3225465664u, 643717713u, 3921069994u,
2103 3593408605u, 38016083u, 3634488961u, 3889429448u, 568446438u, 3275163606u, 4107603335u, 1163531501u, 2850285829u, 4243563512u,
2104 1735328473u, 2368359562u, 4294588738u, 2272392833u, 1839030562u, 4259657740u, 2763975236u, 1272893353u, 4139469664u, 3200236656u,
2105 681279174u, 3936430074u, 3572445317u, 76029189u, 3654602809u, 3873151461u, 530742520u, 3299628645u, 4096336452u, 1126891415u,
2106 2878612391u, 4237533241u, 1700485571u, 2399980690u, 4293915773u, 2240044497u, 1873313359u, 4264355552u, 2734768916u, 1309151649u,
2107 4149444226u, 3174756917u, 718787259u, 3951481745u
2108 };
2109 int num = (namespaces.Length + 8) / 64 + 1;
2110 uint num2 = 1732584193u;
2111 uint num3 = 4023233417u;
2112 uint num4 = 2562383102u;
2113 uint num5 = 271733878u;
2114 for (int i = 0; i < num; i++)
2115 {
2116 byte[] array3 = namespaces;
2117 int num6 = i * 64;
2118 if (num6 + 64 > namespaces.Length)
2119 {
2120 array3 = new byte[64];
2121 for (int j = num6; j < namespaces.Length; j++)
2122 {
2123 array3[j - num6] = namespaces[j];
2124 }
2125 if (num6 <= namespaces.Length)
2126 {
2127 array3[namespaces.Length - num6] = 128;
2128 }
2129 if (i == num - 1)
2130 {
2131 array3[56] = (byte)(namespaces.Length << 3);
2132 array3[57] = (byte)(namespaces.Length >> 5);
2133 array3[58] = (byte)(namespaces.Length >> 13);
2134 array3[59] = (byte)(namespaces.Length >> 21);
2135 }
2136 num6 = 0;
2137 }
2138 uint num7 = num2;
2139 uint num8 = num3;
2140 uint num9 = num4;
2141 uint num10 = num5;
2142 for (int k = 0; k < 64; k++)
2143 {
2144 uint num11;
2145 int num12;
2146 if (k < 16)
2147 {
2148 num11 = (num8 & num9) | (~num8 & num10);
2149 num12 = k;
2150 }
2151 else if (k < 32)
2152 {
2153 num11 = (num8 & num10) | (num9 & ~num10);
2154 num12 = 5 * k + 1;
2155 }
2156 else if (k < 48)
2157 {
2158 num11 = num8 ^ num9 ^ num10;
2159 num12 = 3 * k + 5;
2160 }
2161 else
2162 {
2163 num11 = num9 ^ (num8 | ~num10);
2164 num12 = 7 * k;
2165 }
2166 num12 = (num12 & 0xF) * 4 + num6;
2167 uint num13 = num10;
2168 num10 = num9;
2169 num9 = num8;
2171 num8 = (num8 << array[(k & 3) | ((k >> 2) & -4)]) | (num8 >> 32 - array[(k & 3) | ((k >> 2) & -4)]);
2172 num8 += num9;
2173 num7 = num13;
2174 }
2175 num2 += num7;
2176 num3 += num8;
2177 if (i < num - 1)
2178 {
2179 num4 += num9;
2180 num5 += num10;
2181 }
2182 }
2183 return new byte[6]
2184 {
2185 (byte)num2,
2186 (byte)(num2 >> 8),
2187 (byte)(num2 >> 16),
2188 (byte)(num2 >> 24),
2189 (byte)num3,
2190 (byte)(num3 >> 8)
2191 };
2192 }
2193
2194 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
2200
2201 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
2203 {
2204 string text = null;
2206 IList<int> nestedParameterCounts = genericNameProvider.GetNestedParameterCounts();
2207 for (int i = 0; i < format.Length; i++)
2208 {
2209 char c = format[i];
2210 if (c == '{')
2211 {
2212 i++;
2213 int num = i;
2214 for (; i < format.Length && format[i] != '}'; i++)
2215 {
2216 }
2217 if (i == format.Length)
2218 {
2220 }
2221 if (format[num] == '#' && i == num + 1)
2222 {
2223 if (nestedParameterCounts.Count <= 1 && genericNameProvider.ParametersFromBuiltInNamespaces)
2224 {
2225 continue;
2226 }
2227 if (text == null)
2228 {
2230 foreach (int item in nestedParameterCounts)
2231 {
2232 stringBuilder2.Insert(0, item.ToString(CultureInfo.InvariantCulture)).Insert(0, " ");
2233 }
2235 }
2236 stringBuilder.Append(text);
2237 }
2238 else
2239 {
2240 if (!int.TryParse(format.AsSpan(num, i - num), out var result) || result < 0 || result >= genericNameProvider.GetParameterCount())
2241 {
2243 }
2244 stringBuilder.Append(genericNameProvider.GetParameterName(result));
2245 }
2246 }
2247 else
2248 {
2249 stringBuilder.Append(c);
2250 }
2251 }
2252 return stringBuilder.ToString();
2253 }
2254
2255 internal static bool IsTypeNullable(Type type)
2256 {
2257 if (type.IsValueType)
2258 {
2259 if (type.IsGenericType)
2260 {
2261 return type.GetGenericTypeDefinition() == Globals.TypeOfNullable;
2262 }
2263 return false;
2264 }
2265 return true;
2266 }
2267
2268 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
2270 {
2271 Dictionary<XmlQualifiedName, DataContract> knownDataContracts = null;
2273 ImportKnownTypeAttributes(type, typesChecked, ref knownDataContracts);
2274 return knownDataContracts;
2275 }
2276
2277 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
2279 {
2280 while (type != null && IsTypeSerializable(type) && !typesChecked.ContainsKey(type))
2281 {
2283 object[] array = type.GetCustomAttributes(Globals.TypeOfKnownTypeAttribute, inherit: false).ToArray();
2284 if (array != null)
2285 {
2286 bool flag = false;
2287 bool flag2 = false;
2288 for (int i = 0; i < array.Length; i++)
2289 {
2291 if (knownTypeAttribute.Type != null)
2292 {
2293 if (flag)
2294 {
2296 }
2297 CheckAndAdd(knownTypeAttribute.Type, typesChecked, ref knownDataContracts);
2298 flag2 = true;
2299 continue;
2300 }
2301 if (flag || flag2)
2302 {
2304 }
2305 string methodName = knownTypeAttribute.MethodName;
2306 if (methodName == null)
2307 {
2309 }
2310 if (methodName.Length == 0)
2311 {
2313 }
2314 MethodInfo method = type.GetMethod(methodName, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, Type.EmptyTypes);
2315 if (method == null)
2316 {
2318 }
2319 if (!Globals.TypeOfTypeEnumerable.IsAssignableFrom(method.ReturnType))
2320 {
2322 }
2323 object obj = method.Invoke(null, Array.Empty<object>());
2324 if (obj == null)
2325 {
2327 }
2328 foreach (Type item in (IEnumerable<Type>)obj)
2329 {
2330 if (item == null)
2331 {
2333 }
2334 CheckAndAdd(item, typesChecked, ref knownDataContracts);
2335 }
2336 flag = true;
2337 }
2338 }
2339 try
2340 {
2341 if (GetDataContract(type) is CollectionDataContract { IsDictionary: not false } collectionDataContract && collectionDataContract.ItemType.GetGenericTypeDefinition() == Globals.TypeOfKeyValue)
2342 {
2343 DataContract dataContract = GetDataContract(Globals.TypeOfKeyValuePair.MakeGenericType(collectionDataContract.ItemType.GetGenericArguments()));
2344 if (knownDataContracts == null)
2345 {
2346 knownDataContracts = new Dictionary<XmlQualifiedName, DataContract>();
2347 }
2348 knownDataContracts.TryAdd(dataContract.StableName, dataContract);
2349 }
2350 }
2352 {
2353 }
2354 type = type.BaseType;
2355 }
2356 }
2357
2358 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
2379
2380 internal static bool IsTypeVisible(Type t)
2381 {
2383 {
2384 return false;
2385 }
2387 foreach (Type type in genericArguments)
2388 {
2389 if (!type.IsGenericParameter && !IsTypeVisible(type))
2390 {
2391 return false;
2392 }
2393 }
2394 return true;
2395 }
2396
2398 {
2399 if (ctor != null && !ctor.IsPublic)
2400 {
2402 }
2403 return false;
2404 }
2405
2407 {
2408 if (method != null && !method.IsPublic)
2409 {
2411 }
2412 return false;
2413 }
2414
2416 {
2417 if (field != null && !field.IsPublic)
2418 {
2420 }
2421 return false;
2422 }
2423
2425 {
2426 if (type.Module.Equals(typeof(DataContract).Module) || IsAssemblyFriendOfSerialization(type.Assembly))
2427 {
2428 return !type.IsNestedPrivate;
2429 }
2430 return false;
2431 }
2432
2434 {
2436 {
2437 return false;
2438 }
2439 if (member is MethodInfo)
2440 {
2442 if (!methodInfo.IsAssembly)
2443 {
2444 return methodInfo.IsFamilyOrAssembly;
2445 }
2446 return true;
2447 }
2448 if (member is FieldInfo)
2449 {
2450 FieldInfo fieldInfo = (FieldInfo)member;
2451 if (fieldInfo.IsAssembly || fieldInfo.IsFamilyOrAssembly)
2452 {
2453 return IsTypeVisible(fieldInfo.FieldType);
2454 }
2455 return false;
2456 }
2457 if (member is ConstructorInfo)
2458 {
2460 if (!constructorInfo.IsAssembly)
2461 {
2462 return constructorInfo.IsFamilyOrAssembly;
2463 }
2464 return true;
2465 }
2466 return false;
2467 }
2468
2470 {
2474 {
2475 string assemblyName = internalsVisibleToAttribute.AssemblyName;
2476 if (assemblyName.Trim().Equals("System.Runtime.Serialization") || Regex.IsMatch(assemblyName, "^[\\s]*System\\.Runtime\\.Serialization[\\s]*,[\\s]*PublicKey[\\s]*=[\\s]*(?i:00240000048000009400000006020000002400005253413100040000010001008d56c76f9e8649383049f383c44be0ec204181822a6c31cf5eb7ef486944d032188ea1d3920763712ccb12d75fb77e9811149e6148e5d32fbaab37611c1878ddc19e20ef135d0cb2cff2bfec3d115810c3d9069638fe4be215dbf795861920e5ab6f7db2e2ceef136ac23d5dd2bf031700aec232f6c6b1c785b4305c123b37ab)[\\s]*$"))
2477 {
2478 return true;
2479 }
2480 }
2481 return false;
2482 }
2483
2484 internal static string SanitizeTypeName(string typeName)
2485 {
2486 return typeName.Replace('.', '_');
2487 }
2488}
static uint ReadUInt32LittleEndian(ReadOnlySpan< byte > source)
bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value)
bool ICollection< KeyValuePair< TKey, TValue > >. Contains(KeyValuePair< TKey, TValue > keyValuePair)
bool TryAdd(TKey key, TValue value)
void Add(TKey key, TValue value)
static int ToBase64CharArray(byte[] inArray, int offsetIn, int length, char[] outArray, int offsetOut)
Definition Convert.cs:2741
static CultureInfo InvariantCulture
static bool IsNonAttributedTypeValidForSerialization([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors|DynamicallyAccessedMemberTypes.NonPublicConstructors|DynamicallyAccessedMemberTypes.Interfaces)] Type type)
static bool TryCreate(Type type, [NotNullWhen(true)] out DataContract dataContract)
static bool TryCreateGetOnlyCollectionDataContract(Type type, [NotNullWhen(true)] out DataContract dataContract)
static readonly Dictionary< TypeHandleRef, IntRef > s_typeToIDCache
DataContractCriticalHelper([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors|DynamicallyAccessedMemberTypes.NonPublicConstructors|DynamicallyAccessedMemberTypes.PublicMethods|DynamicallyAccessedMemberTypes.NonPublicMethods|DynamicallyAccessedMemberTypes.PublicFields|DynamicallyAccessedMemberTypes.PublicProperties)] Type type)
static RuntimeTypeHandle GetDataContractAdapterTypeHandle(RuntimeTypeHandle typeHandle)
static DataContract CreateDataContract(int id, RuntimeTypeHandle typeHandle, Type type)
virtual Dictionary< XmlQualifiedName, DataContract > KnownDataContracts
static Dictionary< string, XmlDictionaryString > s_clrTypeStrings
static DataContract GetDataContractSkipValidation(int id, RuntimeTypeHandle typeHandle, Type type)
static DataContract CreateGetOnlyCollectionDataContract(int id, RuntimeTypeHandle typeHandle, Type type)
static void ThrowInvalidDataContractException(string message, Type type)
static void AssignDataContractToId(DataContract dataContract, int id)
void SetDataContractName(XmlDictionaryString name, XmlDictionaryString ns)
static bool TryCreateBuiltInDataContract(string name, string ns, [NotNullWhen(true)] out DataContract dataContract)
static int GetIdForInitialization(ClassDataContract classContract)
static Dictionary< Type, DataContract > s_typeToBuiltInContract
static bool ContractMatches(DataContract contract, DataContract cachedContract)
static DataContract GetGetOnlyCollectionDataContractSkipValidation(int id, RuntimeTypeHandle typeHandle, Type type)
static bool TryCreateBuiltInDataContract(Type type, [NotNullWhen(true)] out DataContract dataContract)
static Dictionary< XmlQualifiedName, DataContract > s_nameToBuiltInContract
static DataContract GetBuiltInDataContract(string name, string ns)
static void CheckAndAdd(Type type, Dictionary< Type, Type > typesChecked, [NotNullIfNotNull("nameToDataContractTable")] ref Dictionary< XmlQualifiedName, DataContract > nameToDataContractTable)
static int GetIdForInitialization(ClassDataContract classContract)
static bool FieldRequiresMemberAccess(FieldInfo field)
static DataContract GetDataContract(int id, RuntimeTypeHandle typeHandle, SerializationMode mode)
static string EncodeLocalName(string localName)
static string GetDefaultStableNamespace(Type type)
static Dictionary< XmlQualifiedName, DataContract > ImportKnownTypeAttributes(Type type)
static DataContract GetBuiltInDataContract(Type type)
static void GetDefaultStableName(CodeTypeReference typeReference, out string localName, out string ns)
static DataContract GetBuiltInDataContract(string name, string ns)
DataContract(DataContractCriticalHelper helper)
static void ImportKnownTypeAttributes(Type type, Dictionary< Type, Type > typesChecked, ref Dictionary< XmlQualifiedName, DataContract > knownDataContracts)
static bool IsAssemblyFriendOfSerialization(Assembly assembly)
static bool TryGetBuiltInXmlAndArrayTypeStableName(Type type, [NotNullWhen(true)] out XmlQualifiedName stableName)
static DataContract GetDataContract(RuntimeTypeHandle typeHandle, Type type, SerializationMode mode)
virtual bool IsValidContract(SerializationMode mode)
static DataContract GetDataContractForInitialization(int id)
static string GetDefaultStableNamespace(string clrNs)
static XmlQualifiedName GetDCTypeStableName(Type type, DataContractAttribute dataContractAttribute)
static void CheckExplicitDataContractNamespaceUri(string dataContractNs, Type type)
virtual void WriteXmlValue(XmlWriterDelegator xmlWriter, object obj, XmlObjectSerializerWriteContext context)
static int GetId(RuntimeTypeHandle typeHandle)
static DataContract GetBuiltInDataContract(string typeName)
static string GetDefaultDataContractNamespace(Type type)
static readonly Dictionary< Type, DataContract > s_dataContracts
virtual void WriteXmlElement(XmlWriterDelegator xmlWriter, object obj, XmlObjectSerializerWriteContext context, XmlDictionaryString name, XmlDictionaryString ns)
static string GetCollectionNamespace(string elementNs)
static string GetNamespacesDigest(string namespaces)
static void ValidatePreviousCollectionTypes(Type collectionType, Type itemType, HashSet< Type > previousCollectionTypes)
static string SanitizeTypeName(string typeName)
static XmlDictionaryString GetClrTypeString(string key)
static string ExpandGenericParameters(string format, Type type)
static string GetGlobalDataContractNamespace(string clrNs, object[] nsAttributes)
static XmlQualifiedName GetDefaultStableName(Type type)
static XmlQualifiedName GetCollectionStableName(Type type, Type itemType, out CollectionDataContractAttribute collectionContractAttribute)
static void GetDefaultStableName(string fullTypeName, out string localName, out string ns)
static string GetDefaultStableLocalName(Type type)
virtual object ReadXmlElement(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context)
static Dictionary< Type, DataContract > GetDataContracts()
static string GetClrTypeFullName(Type type)
static XmlQualifiedName GetStableName(Type type, out bool hasDataContract)
static string GetArrayPrefix(ref Type itemType)
virtual DataContract GetValidContract(SerializationMode mode)
static bool IsTypeSerializable(Type type, HashSet< Type > previousCollectionTypes)
static DataContract GetGeneratedDataContract(Type type)
virtual void WriteRootElement(XmlWriterDelegator writer, XmlDictionaryString name, XmlDictionaryString ns)
static bool ConstructorRequiresMemberAccess(ConstructorInfo ctor)
static XmlQualifiedName GetNonDCTypeStableName(Type type)
static bool IsMemberVisibleInSerializationModule(MemberInfo member)
static DataContract GetDataContract(Type type)
static DataContract GetDataContractSkipValidation(int id, RuntimeTypeHandle typeHandle, Type type)
virtual XmlDictionaryString TopLevelElementNamespace
static byte[] ComputeHash(byte[] namespaces)
virtual object ReadXmlValue(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context)
virtual Dictionary< XmlQualifiedName, DataContract > KnownDataContracts
static bool MethodRequiresMemberAccess(MethodInfo method)
static XmlQualifiedName CreateQualifiedName(string localName, string ns)
static void GetClrNameAndNamespace(string fullTypeName, out string localName, out string ns)
static bool TryGetDataContractFromGeneratedAssembly(Type type, out DataContract dataContract)
virtual XmlDictionaryString Namespace
static XmlQualifiedName GetStableName(Type type)
virtual XmlDictionaryString TopLevelElementName
static bool TryGetDCAttribute(Type type, [NotNullWhen(true)] out DataContractAttribute dataContractAttribute)
static string ExpandGenericParameters(string format, IGenericNameProvider genericNameProvider)
static void ThrowInvalidDataContractException(string message, Type type)
static DataContract GetDataContractFromGeneratedAssembly(Type type)
static Type UnwrapRedundantNullableType(Type type)
static string GetDataContractNamespaceFromUri(string uriString)
static DataContract GetDataContract(RuntimeTypeHandle typeHandle, Type type)
readonly DataContractCriticalHelper _helper
static bool IsTypeVisibleInSerializationModule(Type type)
static DataContract GetGetOnlyCollectionDataContractSkipValidation(int id, RuntimeTypeHandle typeHandle, Type type)
static bool IsAsciiLocalName(string localName)
static DataContract GetGetOnlyCollectionDataContract(int id, RuntimeTypeHandle typeHandle, Type type, SerializationMode mode)
static List< int > GetDataContractNameForGenericName(string typeName, StringBuilder localName)
static Exception ThrowHelperFatal(string message, Exception innerException)
static readonly XmlDictionaryString QNameLocalName
static readonly XmlDictionaryString IntLocalName
static readonly XmlDictionaryString NMTOKENLocalName
static readonly XmlDictionaryString SchemaNamespace
static readonly XmlDictionaryString gYearLocalName
static readonly XmlDictionaryString FloatLocalName
static readonly XmlDictionaryString gYearMonthLocalName
static readonly XmlDictionaryString CharLocalName
static readonly XmlDictionaryString UnsignedLongLocalName
static readonly XmlDictionaryString StringLocalName
static readonly XmlDictionaryString DateTimeLocalName
static readonly XmlDictionaryString languageLocalName
static readonly XmlDictionaryString timeLocalName
static readonly XmlDictionaryString gDayLocalName
static readonly XmlDictionaryString DoubleLocalName
static readonly XmlDictionaryString ENTITIESLocalName
static readonly XmlDictionaryString UriLocalName
static readonly XmlDictionaryString UnsignedIntLocalName
static readonly XmlDictionaryString normalizedStringLocalName
static readonly XmlDictionaryString tokenLocalName
static readonly XmlDictionaryString ByteArrayLocalName
static readonly XmlDictionaryString positiveIntegerLocalName
static readonly XmlDictionaryString LongLocalName
static readonly XmlDictionaryString integerLocalName
static readonly XmlDictionaryString ObjectLocalName
static readonly XmlDictionaryString NCNameLocalName
static readonly XmlDictionaryString GuidLocalName
static readonly XmlDictionaryString UnsignedShortLocalName
static readonly XmlDictionaryString gMonthLocalName
static readonly XmlDictionaryString negativeIntegerLocalName
static readonly XmlDictionaryString gMonthDayLocalName
static readonly XmlDictionaryString SignedByteLocalName
static readonly XmlDictionaryString UnsignedByteLocalName
static readonly XmlDictionaryString nonPositiveIntegerLocalName
static readonly XmlDictionaryString DecimalLocalName
static readonly XmlDictionaryString IDREFSLocalName
static readonly XmlDictionaryString NameLocalName
static readonly XmlDictionaryString ENTITYLocalName
static readonly XmlDictionaryString SerializationNamespace
static readonly XmlDictionaryString hexBinaryLocalName
static readonly XmlDictionaryString ShortLocalName
static readonly XmlDictionaryString NMTOKENSLocalName
static readonly XmlDictionaryString BooleanLocalName
static readonly XmlDictionaryString IDREFLocalName
static readonly XmlDictionaryString TimeSpanLocalName
static readonly XmlDictionaryString XSDIDLocalName
static readonly XmlDictionaryString AsmxTypesNamespace
static readonly XmlDictionaryString nonNegativeIntegerLocalName
static readonly XmlDictionaryString dateLocalName
static bool TypeOfScriptObject_IsAssignableFrom(Type type)
Definition Globals.cs:1209
static ClassDataContract CreateScriptObjectClassDataContract()
Definition Globals.cs:1204
static Type TypeOfCollectionDataContractAttribute
Definition Globals.cs:729
static void GetXmlTypeInfo(Type type, out XmlQualifiedName stableName, out XmlSchemaType xsdType, out bool hasRoot)
static string InvalidCollectionContractName
Definition SR.cs:126
static string InvalidGlobalDataContractNamespace
Definition SR.cs:152
static string InvalidDataContractNamespace
Definition SR.cs:140
static string KnownTypeAttributeOneScheme
Definition SR.cs:198
static string ErrorDeserializing
Definition SR.cs:88
static string InvalidDataContractName
Definition SR.cs:138
static string DataContractNamespaceReserved
Definition SR.cs:60
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string DataContractNamespaceIsNotValid
Definition SR.cs:58
static string KnownTypeAttributeUnknownMethod
Definition SR.cs:194
static string NoSetMethodForProperty
Definition SR.cs:218
static string DataContractNamespaceAlreadySet
Definition SR.cs:56
static string DataContractCacheOverflow
Definition SR.cs:54
static string GenericNameBraceMismatch
Definition SR.cs:112
static string InvalidCollectionContractNamespace
Definition SR.cs:128
static string RequiresClassDataContractToSetIsISerializable
Definition SR.cs:658
static string TypeNotSerializable
Definition SR.cs:286
static string KnownTypeAttributeNoData
Definition SR.cs:202
static string DupContractInKnownTypes
Definition SR.cs:72
static string RecursiveCollectionType
Definition SR.cs:636
static string UnexpectedContractType
Definition SR.cs:288
static string GenericParameterNotValid
Definition SR.cs:114
static string KnownTypeAttributeReturnType
Definition SR.cs:196
static string KnownTypeAttributeMethodNull
Definition SR.cs:204
static string ErrorTypeInfo
Definition SR.cs:96
static string KnownTypeAttributeValidMethodTypes
Definition SR.cs:200
static string KnownTypeAttributeEmptyString
Definition SR.cs:192
Definition SR.cs:7
static Encoding UTF8
Definition Encoding.cs:526
static bool IsMatch(string input, string pattern)
Definition Regex.cs:406
StringBuilder Append(char value, int repeatCount)
virtual Type[] GetGenericArguments()
Definition Type.cs:500
static Type GetTypeFromHandle(RuntimeTypeHandle handle)
bool IsVisible
Definition Type.cs:364
static readonly Type[] EmptyTypes
Definition Type.cs:19
MethodInfo? GetMethod(string name)
Definition Type.cs:675
static bool TryCreate([NotNullWhen(true)] string? uriString, UriKind uriKind, [NotNullWhen(true)] out Uri? result)
Definition Uri.cs:3793
string AbsoluteUri
Definition Uri.cs:266
static ? string EncodeLocalName(string? name)
Definition XmlConvert.cs:49
static string VerifyNCName(string name)
TypeCode
Definition TypeCode.cs:4
UriKind
Definition UriKind.cs:4