Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
ClassDataContract.cs
Go to the documentation of this file.
3using System.Linq;
7using System.Xml;
8
10
11internal sealed class ClassDataContract : DataContract
12{
14 {
15 internal struct Member
16 {
18
19 internal string ns;
20
21 internal int baseTypeIndex;
22
29 }
30
31 internal sealed class DataMemberConflictComparer : IComparer<Member>
32 {
34
35 public int Compare(Member x, Member y)
36 {
37 int num = string.CompareOrdinal(x.ns, y.ns);
38 if (num != 0)
39 {
40 return num;
41 }
42 int num2 = string.CompareOrdinal(x.member.Name, y.member.Name);
43 if (num2 != 0)
44 {
45 return num2;
46 }
48 }
49 }
50
51 private static Type[] s_serInfoCtorArgs;
52
53 private static readonly MethodInfo s_getKeyValuePairMethod = typeof(KeyValuePairAdapter<, >).GetMethod("GetKeyValuePair", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
54
55 private static readonly ConstructorInfo s_ctorGenericMethod = typeof(KeyValuePairAdapter<, >).GetConstructor(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, new Type[1] { typeof(KeyValuePair<, >).MakeGenericType(typeof(KeyValuePairAdapter<, >).GetGenericArguments()) });
56
58
60
62
64
66
68
70
72
73 private bool _isISerializable;
74
76
77 private bool _isMethodChecked;
78
80
81 private bool _hasDataContract;
82
83 private bool _hasExtensionData;
84
85 private readonly bool _isScriptObject;
86
88
89 private XmlFormatClassReaderDelegate _xmlFormatReaderDelegate;
90
91 private XmlFormatClassWriterDelegate _xmlFormatWriterDelegate;
92
94
96
98
100
102
104
106
108 {
109 get
110 {
111 return _baseContract;
112 }
113 set
114 {
116 if (_baseContract != null && base.IsValueType)
117 {
119 }
120 }
121 }
122
124
126 {
127 get
128 {
130 return _onSerializing;
131 }
132 }
133
135 {
136 get
137 {
139 return _onSerialized;
140 }
141 }
142
144 {
145 get
146 {
148 return _onDeserializing;
149 }
150 }
151
153 {
154 get
155 {
157 return _onDeserialized;
158 }
159 }
160
162 {
163 get
164 {
167 }
168 }
169
171 {
172 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
173 get
174 {
175 if (_knownDataContracts != null)
176 {
177 return _knownDataContracts;
178 }
179 if (!_isKnownTypeAttributeChecked && base.UnderlyingType != null)
180 {
181 lock (this)
182 {
184 {
188 }
189 }
190 }
191 return _knownDataContracts;
192 }
193 set
194 {
196 }
197 }
198
199 internal override bool IsISerializable
200 {
201 get
202 {
203 return _isISerializable;
204 }
205 set
206 {
208 }
209 }
210
212
213 internal bool HasExtensionData
214 {
215 get
216 {
217 return _hasExtensionData;
218 }
219 set
220 {
222 }
223 }
224
226
228
230
232
234
236
237 internal XmlFormatClassWriterDelegate XmlFormatWriterDelegate
238 {
239 get
240 {
242 }
243 set
244 {
246 }
247 }
248
249 internal XmlFormatClassReaderDelegate XmlFormatReaderDelegate
250 {
251 get
252 {
254 }
255 set
256 {
258 }
259 }
260
262 {
263 get
264 {
266 }
267 set
268 {
270 }
271 }
272
273 private static Type[] SerInfoCtorArgs
274 {
275 get
276 {
277 if (s_serInfoCtorArgs == null)
278 {
279 s_serInfoCtorArgs = new Type[2]
280 {
283 };
284 }
285 return s_serInfoCtorArgs;
286 }
287 }
288
289 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
291 : base(type)
292 {
295 {
299 base.Name = xmlDictionary.Add(base.StableName.Name);
300 base.Namespace = xmlDictionary.Add(base.StableName.Namespace);
303 return;
304 }
305 Type type2 = type.BaseType;
309 {
310 if (HasDataContract)
311 {
313 }
314 if (type2 != null && (!type2.IsSerializable || !Globals.TypeOfISerializable.IsAssignableFrom(type2)))
315 {
316 type2 = null;
317 }
318 }
320 base.IsValueType = type.IsValueType;
322 {
325 {
327 }
328 else
329 {
331 }
333 {
335 }
336 }
337 else
338 {
339 BaseContract = null;
340 }
343 {
345 }
347 {
349 }
350 else
351 {
355 base.Name = xmlDictionary2.Add(base.StableName.Name);
356 base.Namespace = xmlDictionary2.Add(base.StableName.Namespace);
357 int num = 0;
358 int num2 = 0;
359 if (BaseContract == null)
360 {
364 }
365 else
366 {
367 num = BaseContract.MemberNames.Length;
375 }
376 ContractNamespaces[num2] = base.Namespace;
377 for (int i = 0; i < Members.Count; i++)
378 {
380 MemberNamespaces[i + num] = base.Namespace;
381 }
382 }
385 }
386
387 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
407
409 {
410 bool flag = false;
413 if (BaseContract != null)
414 {
415 if (flag2 && dataContractAttribute.IsReferenceSetExplicitly)
416 {
418 if ((isReference && !dataContractAttribute.IsReference) || (!isReference && dataContractAttribute.IsReference))
419 {
421 }
422 else
423 {
424 flag = dataContractAttribute.IsReference;
425 }
426 }
427 else
428 {
430 }
431 }
432 else if (flag2 && dataContractAttribute.IsReference)
433 {
434 flag = dataContractAttribute.IsReference;
435 }
436 if (flag && type.IsValueType)
437 {
439 }
440 else
441 {
442 base.IsReference = flag;
443 }
444 }
445
446 [MemberNotNull("_members")]
447 [MemberNotNull("Members")]
448 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
449 private void ImportDataMembers()
450 {
451 Type underlyingType = base.UnderlyingType;
456 MemberInfo[] array = (flag ? underlyingType.GetMembers(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) : underlyingType.GetMembers(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public));
457 foreach (MemberInfo memberInfo in array)
458 {
459 if (HasDataContract)
460 {
461 object[] array2 = memberInfo.GetCustomAttributes(typeof(DataMemberAttribute), inherit: false).ToArray();
462 if (array2 == null || array2.Length == 0)
463 {
464 continue;
465 }
466 if (array2.Length > 1)
467 {
469 }
472 {
473 PropertyInfo propertyInfo = (PropertyInfo)memberInfo;
474 MethodInfo getMethod = propertyInfo.GetMethod;
475 if (getMethod != null && IsMethodOverriding(getMethod))
476 {
477 continue;
478 }
479 MethodInfo setMethod = propertyInfo.SetMethod;
480 if (setMethod != null && IsMethodOverriding(setMethod))
481 {
482 continue;
483 }
484 if (getMethod == null)
485 {
487 }
489 {
491 }
492 if (getMethod.GetParameters().Length != 0)
493 {
495 }
496 }
497 else if (!(memberInfo is FieldInfo))
498 {
500 }
502 if (dataMemberAttribute.IsNameSetExplicitly)
503 {
504 if (dataMemberAttribute.Name == null || dataMemberAttribute.Name.Length == 0)
505 {
507 }
509 }
510 else
511 {
513 }
517 if (dataMemberAttribute.IsRequired && base.IsReference)
518 {
520 }
524 continue;
525 }
526 if (!flag)
527 {
530 if ((fieldInfo == null && propertyInfo2 == null) || (fieldInfo != null && fieldInfo.IsInitOnly))
531 {
532 continue;
533 }
534 object[] array3 = memberInfo.GetCustomAttributes(typeof(IgnoreDataMemberAttribute), inherit: false).ToArray();
535 if (array3 != null && array3.Length != 0)
536 {
537 if (array3.Length <= 1)
538 {
539 continue;
540 }
542 }
544 if (propertyInfo2 != null)
545 {
546 MethodInfo getMethod2 = propertyInfo2.GetGetMethod();
547 if (getMethod2 == null || IsMethodOverriding(getMethod2) || getMethod2.GetParameters().Length != 0)
548 {
549 continue;
550 }
552 if (setMethod2 == null)
553 {
555 {
556 continue;
557 }
558 }
559 else if (!setMethod2.IsPublic || IsMethodOverriding(setMethod2))
560 {
561 continue;
562 }
563 }
567 continue;
568 }
570 if (!((!IsKnownSerializableType(underlyingType)) ? (fieldInfo2 != null && !fieldInfo2.IsNotSerialized) : CanSerializeMember(fieldInfo2)))
571 {
572 continue;
573 }
576 object[] customAttributes = fieldInfo2.GetCustomAttributes(Globals.TypeOfOptionalFieldAttribute, inherit: false);
577 if (customAttributes == null || customAttributes.Length == 0)
578 {
579 if (base.IsReference)
580 {
582 }
584 }
587 }
588 if (list.Count > 1)
589 {
591 }
594 _members = list;
595 }
596
597 private static bool CanSerializeMember(FieldInfo field)
598 {
599 if (field != null)
600 {
601 return !IsNonSerializedMember(field.DeclaringType, field.Name);
602 }
603 return false;
604 }
605
606 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
608 {
609 if (CollectionDataContract.IsCollection(memberContract.MemberType, constructorRequired: false) && !memberContract.MemberType.IsValueType)
610 {
612 return true;
613 }
614 return false;
615 }
616
618 {
619 if (BaseContract == null)
620 {
621 return;
622 }
623 int num = 0;
625 foreach (DataMember member in members)
626 {
627 list.Add(new Member(member, base.StableName.Namespace, num));
628 }
630 {
631 num++;
632 foreach (DataMember member2 in baseContract.Members)
633 {
634 list.Add(new Member(member2, baseContract.StableName.Namespace, num));
635 }
636 }
638 list.Sort(singleton);
639 int num2;
640 for (num2 = 0; num2 < list.Count - 1; num2++)
641 {
642 int num3 = num2;
643 int i = num2;
644 bool flag = false;
645 for (; i < list.Count - 1 && string.CompareOrdinal(list[i].member.Name, list[i + 1].member.Name) == 0 && string.CompareOrdinal(list[i].ns, list[i + 1].ns) == 0; i++)
646 {
647 list[i].member.ConflictingMember = list[i + 1].member;
648 if (!flag)
649 {
650 flag = list[i + 1].member.HasConflictingNameAndType || list[i].member.MemberType != list[i + 1].member.MemberType;
651 }
652 }
653 if (flag)
654 {
655 for (int j = num3; j <= i; j++)
656 {
657 list[j].member.HasConflictingNameAndType = true;
658 }
659 }
660 num2 = i + 1;
661 }
662 }
663
664 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
669
674
676 {
677 if (method.IsVirtual)
678 {
679 return (method.Attributes & MethodAttributes.VtableLayoutMask) == 0;
680 }
681 return false;
682 }
683
684 internal void EnsureMethodsImported()
685 {
686 if (_isMethodChecked || !(base.UnderlyingType != null))
687 {
688 return;
689 }
690 lock (this)
691 {
693 {
694 return;
695 }
696 Type underlyingType = base.UnderlyingType;
697 MethodInfo[] methods = underlyingType.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
698 foreach (MethodInfo methodInfo in methods)
699 {
700 Type prevAttributeType = null;
701 ParameterInfo[] parameters = methodInfo.GetParameters();
703 {
704 if (methodInfo.Name == "System.Runtime.Serialization.IExtensibleDataObject.set_ExtensionData" || !methodInfo.IsPublic)
705 {
707 }
708 else
709 {
711 }
712 }
714 {
716 }
718 {
720 }
722 {
724 }
726 {
728 }
729 }
731 _isMethodChecked = true;
732 }
733 }
734
736 {
737 if (method.Name == "System.Runtime.Serialization.IExtensibleDataObject.set_ExtensionData" || method.Name == "set_ExtensionData")
738 {
739 if (_extensionDataSetMethod != null)
740 {
742 }
743 if (method.ReturnType != Globals.TypeOfVoid)
744 {
746 }
747 if (parameters == null || parameters.Length != 1 || parameters[0].ParameterType != Globals.TypeOfExtensionDataObject)
748 {
750 }
751 return true;
752 }
753 return false;
754 }
755
757 {
758 if (method.IsDefined(attributeType, inherit: false))
759 {
760 if (currentCallback != null)
761 {
763 }
764 else if (prevAttributeType != null)
765 {
767 }
768 else if (method.IsVirtual)
769 {
771 }
772 else
773 {
774 if (method.ReturnType != Globals.TypeOfVoid)
775 {
777 }
778 if (parameters == null || parameters.Length != 1 || parameters[0].ParameterType != Globals.TypeOfStreamingContext)
779 {
781 }
782 prevAttributeType = attributeType;
783 }
784 return true;
785 }
786 return false;
787 }
788
789 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
791 {
792 if (type.IsGenericType && type.GetGenericTypeDefinition() == Globals.TypeOfKeyValuePairAdapter)
793 {
796 _keyValuePairCtorInfo = (ConstructorInfo)type.GetMemberWithSameMetadataDefinitionAs(s_ctorGenericMethod);
797 _getKeyValuePairMethodInfo = (MethodInfo)type.GetMemberWithSameMetadataDefinitionAs(s_getKeyValuePairMethod);
798 }
799 }
800
814
816 {
818 {
819 return null;
820 }
821 Type underlyingType = base.UnderlyingType;
822 if (underlyingType.IsValueType)
823 {
824 return null;
825 }
826 ConstructorInfo constructor = underlyingType.GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, Type.EmptyTypes);
827 if (constructor == null)
828 {
830 }
831 return constructor;
832 }
833
834 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
836 {
861 }
862 }
863
864 internal sealed class DataMemberComparer : IComparer<DataMember>
865 {
867
869 {
870 int num = x.Order - y.Order;
871 if (num != 0)
872 {
873 return num;
874 }
875 return string.CompareOrdinal(x.Name, y.Name);
876 }
877 }
878
880
882
884
886
888
889 private bool _isScriptObject;
890
892
894
896
898 {
899 {
900 "System.Collections.Generic.KeyValuePair`2",
901 Array.Empty<string>()
902 },
903 {
904 "System.Collections.Generic.Queue`1",
905 new string[1] { "_syncRoot" }
906 },
907 {
908 "System.Collections.Generic.Stack`1",
909 new string[1] { "_syncRoot" }
910 },
911 {
912 "System.Collections.ObjectModel.ReadOnlyCollection`1",
913 new string[1] { "_syncRoot" }
914 },
915 {
916 "System.Collections.ObjectModel.ReadOnlyDictionary`2",
917 new string[3] { "_syncRoot", "_keys", "_values" }
918 },
919 {
920 "System.Tuple`1",
921 Array.Empty<string>()
922 },
923 {
924 "System.Tuple`2",
925 Array.Empty<string>()
926 },
927 {
928 "System.Tuple`3",
929 Array.Empty<string>()
930 },
931 {
932 "System.Tuple`4",
933 Array.Empty<string>()
934 },
935 {
936 "System.Tuple`5",
937 Array.Empty<string>()
938 },
939 {
940 "System.Tuple`6",
941 Array.Empty<string>()
942 },
943 {
944 "System.Tuple`7",
945 Array.Empty<string>()
946 },
947 {
948 "System.Tuple`8",
949 Array.Empty<string>()
950 },
951 {
952 "System.Collections.Queue",
953 new string[1] { "_syncRoot" }
954 },
955 {
956 "System.Collections.Stack",
957 new string[1] { "_syncRoot" }
958 },
959 {
960 "System.Globalization.CultureInfo",
961 Array.Empty<string>()
962 },
963 {
964 "System.Version",
965 Array.Empty<string>()
966 }
967 };
968
970
972
974 {
975 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
976 get
977 {
978 if (_childElementNamespaces == null)
979 {
980 lock (this)
981 {
982 if (_childElementNamespaces == null)
983 {
985 {
989 }
991 }
992 }
993 }
995 }
996 set
997 {
999 }
1000 }
1001
1003
1005
1007
1009
1011
1013 {
1014 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
1015 get
1016 {
1018 }
1019 }
1020
1021 public override bool IsISerializable
1022 {
1023 get
1024 {
1025 return _helper.IsISerializable;
1026 }
1027 set
1028 {
1030 }
1031 }
1032
1034
1036 {
1037 get
1038 {
1040 }
1041 set
1042 {
1044 }
1045 }
1046
1047 [MemberNotNullWhen(true, "KeyValuePairGenericArguments")]
1048 [MemberNotNullWhen(true, "KeyValuePairAdapterConstructorInfo")]
1049 [MemberNotNullWhen(true, "GetKeyValuePairMethodInfo")]
1051 {
1052 [MemberNotNullWhen(true, "KeyValuePairGenericArguments")]
1053 [MemberNotNullWhen(true, "KeyValuePairAdapterConstructorInfo")]
1054 [MemberNotNullWhen(true, "GetKeyValuePairMethodInfo")]
1055 get
1056 {
1058 }
1059 }
1060
1062
1064
1066
1068 {
1069 get
1070 {
1071 if (_makeNewInstance == null)
1072 {
1074 }
1075 return _makeNewInstance;
1076 }
1077 }
1078
1079 internal XmlFormatClassWriterDelegate XmlFormatWriterDelegate
1080 {
1081 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
1082 get
1083 {
1084 if (_helper.XmlFormatWriterDelegate == null)
1085 {
1086 lock (this)
1087 {
1088 if (_helper.XmlFormatWriterDelegate == null)
1089 {
1090 XmlFormatClassWriterDelegate xmlFormatWriterDelegate = CreateXmlFormatWriterDelegate();
1093 }
1094 }
1095 }
1097 }
1098 set
1099 {
1100 }
1101 }
1102
1103 internal XmlFormatClassReaderDelegate XmlFormatReaderDelegate
1104 {
1105 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
1106 get
1107 {
1108 if (_helper.XmlFormatReaderDelegate == null)
1109 {
1110 lock (this)
1111 {
1112 if (_helper.XmlFormatReaderDelegate == null)
1113 {
1114 XmlFormatClassReaderDelegate xmlFormatReaderDelegate = CreateXmlFormatReaderDelegate();
1117 }
1118 }
1119 }
1121 }
1122 set
1123 {
1124 }
1125 }
1126
1128 {
1129 get
1130 {
1131 Type type = base.UnderlyingType;
1132 if (type.IsValueType && !IsNonAttributedType)
1133 {
1135 }
1136 return type;
1137 }
1138 }
1139
1141 {
1142 get
1143 {
1145 {
1147 }
1148 return base.UnderlyingType;
1149 }
1150 }
1151
1152 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
1158
1159 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
1165
1166 [MemberNotNull("_helper")]
1175
1180
1189
1191 {
1193 if (nonAttributedTypeConstructor == null)
1194 {
1195 obj = null;
1196 return false;
1197 }
1198 if (nonAttributedTypeConstructor.IsPublic)
1199 {
1200 obj = MakeNewInstance();
1201 }
1202 else
1203 {
1204 obj = nonAttributedTypeConstructor.Invoke(Array.Empty<object>());
1205 }
1206 return true;
1207 }
1208
1209 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
1210 private XmlFormatClassWriterDelegate CreateXmlFormatWriterDelegate()
1211 {
1213 }
1214
1215 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
1216 private XmlFormatClassReaderDelegate CreateXmlFormatReaderDelegate()
1217 {
1219 }
1220
1221 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
1233
1244
1245 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
1247 {
1250 {
1251 string @namespace = DataContract.GetStableName(childType).Namespace;
1252 if (@namespace.Length > 0 && @namespace != dataContract.Namespace.Value)
1253 {
1254 return dictionary.Add(@namespace);
1255 }
1256 }
1257 return null;
1258 }
1259
1260 private static bool IsArraySegment(Type t)
1261 {
1262 if (t.IsGenericType)
1263 {
1265 }
1266 return false;
1267 }
1268
1270 {
1271 if (type.IsArray)
1272 {
1273 return false;
1274 }
1275 if (type.IsEnum)
1276 {
1277 return false;
1278 }
1279 if (type.IsGenericParameter)
1280 {
1281 return false;
1282 }
1283 if (Globals.TypeOfIXmlSerializable.IsAssignableFrom(type))
1284 {
1285 return false;
1286 }
1287 if (type.IsPointer)
1288 {
1289 return false;
1290 }
1292 {
1293 return false;
1294 }
1295 Type[] interfaces = type.GetInterfaces();
1296 if (!IsArraySegment(type))
1297 {
1298 Type[] array = interfaces;
1299 foreach (Type type2 in array)
1300 {
1302 {
1303 return false;
1304 }
1305 }
1306 }
1307 if (type.IsSerializable)
1308 {
1309 return false;
1310 }
1311 if (Globals.TypeOfISerializable.IsAssignableFrom(type))
1312 {
1313 return false;
1314 }
1315 if (type.IsDefined(Globals.TypeOfDataContractAttribute, inherit: false))
1316 {
1317 return false;
1318 }
1319 if (type.IsValueType)
1320 {
1321 return type.IsVisible;
1322 }
1323 if (type.IsVisible)
1324 {
1325 return type.GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, Type.EmptyTypes) != null;
1326 }
1327 return false;
1328 }
1329
1330 private static string GetGeneralTypeName(Type type)
1331 {
1332 if (!type.IsGenericType || type.IsGenericParameter)
1333 {
1334 return type.FullName;
1335 }
1336 return type.GetGenericTypeDefinition().FullName;
1337 }
1338
1339 internal static bool IsKnownSerializableType(Type type)
1340 {
1343 }
1344
1345 internal static bool IsNonSerializedMember(Type type, string memberName)
1346 {
1349 {
1350 return value.Contains(memberName);
1351 }
1352 return false;
1353 }
1354
1355 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
1357 {
1358 if (Members == null)
1359 {
1360 return null;
1361 }
1362 XmlDictionaryString[] array = null;
1363 if (BaseContract != null)
1364 {
1366 }
1367 int num = ((array != null) ? array.Length : 0);
1369 if (num > 0)
1370 {
1371 Array.Copy(array, array2, array.Length);
1372 }
1374 for (int i = 0; i < Members.Count; i++)
1375 {
1376 array2[i + num] = GetChildNamespaceToDeclare(this, Members[i].MemberType, dictionary);
1377 }
1378 return array2;
1379 }
1380
1382 {
1384 }
1385
1386 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
1395
1396 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
1398 {
1399 if (_isScriptObject)
1400 {
1402 }
1403 xmlReader.Read();
1405 xmlReader.ReadEndElement();
1406 return result;
1407 }
1408
1410 {
1412 if (!DataContract.IsTypeVisible(base.UnderlyingType))
1413 {
1414 if (securityException != null)
1415 {
1417 }
1418 return true;
1419 }
1421 {
1422 return true;
1423 }
1425 {
1427 {
1428 return true;
1429 }
1430 if (securityException != null)
1431 {
1433 }
1434 return true;
1435 }
1437 {
1438 if (securityException != null)
1439 {
1441 }
1442 return true;
1443 }
1445 {
1446 if (securityException != null)
1447 {
1449 }
1450 return true;
1451 }
1452 if (Members != null)
1453 {
1454 for (int i = 0; i < Members.Count; i++)
1455 {
1456 if (!Members[i].RequiresMemberAccessForSet())
1457 {
1458 continue;
1459 }
1460 if (securityException != null)
1461 {
1463 {
1465 }
1467 }
1468 return true;
1469 }
1470 }
1471 return false;
1472 }
1473
1475 {
1477 if (!DataContract.IsTypeVisible(base.UnderlyingType))
1478 {
1479 if (securityException != null)
1480 {
1482 }
1483 return true;
1484 }
1486 {
1487 return true;
1488 }
1490 {
1491 if (securityException != null)
1492 {
1494 }
1495 return true;
1496 }
1498 {
1499 if (securityException != null)
1500 {
1502 }
1503 return true;
1504 }
1505 if (Members != null)
1506 {
1507 for (int i = 0; i < Members.Count; i++)
1508 {
1509 if (!Members[i].RequiresMemberAccessForGet())
1510 {
1511 continue;
1512 }
1513 if (securityException != null)
1514 {
1516 {
1518 }
1520 }
1521 return true;
1522 }
1523 }
1524 return false;
1525 }
1526
1527 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
1540
1541 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
1543 {
1545 Namespace = ns;
1547 base.Name = xmlDictionary.Add(base.StableName.Name);
1548 Namespace = ns;
1552 for (int i = 0; i < memberNames.Length; i++)
1553 {
1555 MemberNamespaces[i] = ns;
1556 }
1557 }
1558}
static unsafe void Copy(Array sourceArray, Array destinationArray, int length)
Definition Array.cs:624
bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value)
void Add(TKey key, TValue value)
virtual ? MethodInfo GetMethod
virtual ? MethodInfo SetMethod
void SetIsNonAttributedType([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors|DynamicallyAccessedMemberTypes.NonPublicConstructors|DynamicallyAccessedMemberTypes.Interfaces)] Type type)
ClassDataContractCriticalHelper([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors|DynamicallyAccessedMemberTypes.NonPublicConstructors|DynamicallyAccessedMemberTypes.PublicMethods|DynamicallyAccessedMemberTypes.NonPublicMethods|DynamicallyAccessedMemberTypes.PublicFields|DynamicallyAccessedMemberTypes.PublicProperties)] Type type, XmlDictionaryString ns, string[] memberNames)
void SetKeyValuePairAdapterFlags([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors|DynamicallyAccessedMemberTypes.NonPublicConstructors|DynamicallyAccessedMemberTypes.PublicMethods|DynamicallyAccessedMemberTypes.NonPublicMethods|DynamicallyAccessedMemberTypes.PublicFields|DynamicallyAccessedMemberTypes.PublicProperties)] Type type)
bool IsValidExtensionDataSetMethod(MethodInfo method, ParameterInfo[] parameters)
static bool IsValidCallback(MethodInfo method, ParameterInfo[] parameters, Type attributeType, MethodInfo currentCallback, ref Type prevAttributeType)
override Dictionary< XmlQualifiedName, DataContract > KnownDataContracts
ClassDataContractCriticalHelper([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors|DynamicallyAccessedMemberTypes.NonPublicConstructors|DynamicallyAccessedMemberTypes.PublicMethods|DynamicallyAccessedMemberTypes.NonPublicMethods|DynamicallyAccessedMemberTypes.PublicFields|DynamicallyAccessedMemberTypes.PublicProperties)] Type type)
XmlFormatClassWriterDelegate CreateXmlFormatWriterDelegate()
static readonly Dictionary< string, string[]> s_knownSerializableTypeInfos
override object ReadXmlValue(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context)
static void CheckAndAddMember(List< DataMember > members, DataMember memberContract, Dictionary< string, DataMember > memberNamesTable)
bool CreateNewInstanceViaDefaultConstructor([NotNullWhen(true)] out object obj)
bool RequiresMemberAccessForWrite(SecurityException securityException)
static XmlDictionaryString GetChildNamespaceToDeclare(DataContract dataContract, Type childType, XmlDictionary dictionary)
const DynamicallyAccessedMemberTypes DataContractPreserveMemberTypes
XmlFormatClassReaderDelegate CreateXmlFormatReaderDelegate()
static bool IsNonSerializedMember(Type type, string memberName)
bool RequiresMemberAccessForRead(SecurityException securityException)
ClassDataContract(Type type, XmlDictionaryString ns, string[] memberNames)
override Dictionary< XmlQualifiedName, DataContract > KnownDataContracts
static bool IsNonAttributedTypeValidForSerialization([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors|DynamicallyAccessedMemberTypes.NonPublicConstructors|DynamicallyAccessedMemberTypes.Interfaces)] Type type)
static ClassDataContract CreateClassDataContractForKeyValue(Type type, XmlDictionaryString ns, string[] memberNames)
void UpdateNamespaceAndMembers(Type type, XmlDictionaryString ns, string[] memberNames)
override void WriteXmlValue(XmlWriterDelegator xmlWriter, object obj, XmlObjectSerializerWriteContext context)
static void ThrowInvalidDataContractException(string message, Type type)
static string EncodeLocalName(string localName)
static Dictionary< XmlQualifiedName, DataContract > ImportKnownTypeAttributes(Type type)
static DataContract GetBuiltInDataContract(Type type)
static string GetClrTypeFullName(Type type)
static bool ConstructorRequiresMemberAccess(ConstructorInfo ctor)
static DataContract GetDataContract(Type type)
static bool MethodRequiresMemberAccess(MethodInfo method)
virtual XmlDictionaryString Namespace
static XmlQualifiedName GetStableName(Type type)
static bool TryGetDCAttribute(Type type, [NotNullWhen(true)] out DataContractAttribute dataContractAttribute)
static void ThrowInvalidDataContractException(string message, Type type)
static DataContract GetDataContractFromGeneratedAssembly(Type type)
static Func< object > GetMakeNewInstanceFunc([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] Type type)
static bool TypeOfScriptObject_IsAssignableFrom(Type type)
Definition Globals.cs:1209
static Type TypeOfCollectionDataContractAttribute
Definition Globals.cs:729
XmlFormatClassReaderDelegate GenerateClassReader(ClassDataContract classContract)
XmlFormatClassWriterDelegate GenerateClassWriter(ClassDataContract classContract)
static SerializationException CreateSerializationException(string errorMessage)
static string NonAttributedSerializableTypesMustHaveDefaultConstructor
Definition SR.cs:258
static string PartialTrustDataContractFieldGetNotPublic
Definition SR.cs:242
static string DuplicateExtensionDataSetMethod
Definition SR.cs:670
static string TooManyDataMembers
Definition SR.cs:280
static string InvalidDataMemberName
Definition SR.cs:142
static string ValueTypeCannotHaveIsReference
Definition SR.cs:304
static string PartialTrustDataContractPropertyGetNotPublic
Definition SR.cs:246
static string CallbackMustReturnVoid
Definition SR.cs:30
static string DupEnumMemberValue
Definition SR.cs:76
static string DupMemberName
Definition SR.cs:78
static string PartialTrustDataContractOnSerializingNotPublic
Definition SR.cs:234
static string NoGetMethodForProperty
Definition SR.cs:216
static string ExtensionDataSetMustReturnVoid
Definition SR.cs:672
static string CallbacksCannotBeVirtualMethods
Definition SR.cs:34
static string DuplicateAttribute
Definition SR.cs:80
static string PartialTrustDataContractTypeNotPublic
Definition SR.cs:250
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string DuplicateCallback
Definition SR.cs:82
static string IsRequiredDataMemberOnIsReferenceDataContractType
Definition SR.cs:178
static string PartialTrustDataContractFieldSetNotPublic
Definition SR.cs:244
static string NoSetMethodForProperty
Definition SR.cs:218
static string PartialTrustDataContractOnDeserializingNotPublic
Definition SR.cs:238
static string PartialTrustNonAttributedSerializableTypeNoPublicConstructor
Definition SR.cs:252
static string PartialTrustDataContractOnDeserializedNotPublic
Definition SR.cs:240
static string PartialTrustDataContractPropertySetNotPublic
Definition SR.cs:248
static string InconsistentIsReference
Definition SR.cs:116
static string ExtensionDataSetParameterInvalid
Definition SR.cs:674
static string CallbackParameterInvalid
Definition SR.cs:32
static string ISerializableCannotHaveDataContract
Definition SR.cs:660
static string TooManyIgnoreDataMemberAttributes
Definition SR.cs:284
static string InvalidMember
Definition SR.cs:154
static string AttributedTypesCannotInheritFromNonAttributedSerializableTypes
Definition SR.cs:260
static string OnlyDataContractTypesCanHaveExtensionData
Definition SR.cs:676
static string NonOptionalFieldMemberOnIsReferenceSerializableType
Definition SR.cs:320
static string SerializationInfo_ConstructorNotFound
Definition SR.cs:662
static string ValueTypeCannotHaveBaseType
Definition SR.cs:300
static string UnexpectedContractType
Definition SR.cs:288
static string IndexedPropertyCannotBeSerialized
Definition SR.cs:118
static string PartialTrustDataContractOnSerializedNotPublic
Definition SR.cs:236
Definition SR.cs:7
virtual Type[] GetGenericArguments()
Definition Type.cs:500
virtual bool IsGenericType
Definition Type.cs:111
bool IsVisible
Definition Type.cs:364
Type[] GetInterfaces()
static readonly Type[] EmptyTypes
Definition Type.cs:19
virtual Type GetGenericTypeDefinition()
Definition Type.cs:495