Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ ImportTypeMapping() [5/6]

TypeMapping System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping ( TypeModel model,
string ns,
ImportContext context,
string dataType,
XmlAttributes a,
bool repeats,
bool openModel,
RecursionLimiter limiter )
inlineprivate

Definition at line 378 of file XmlReflectionImporter.cs.

379 {
380 try
381 {
382 if (dataType.Length > 0)
383 {
384 TypeDesc typeDesc = (TypeScope.IsOptionalValue(model.Type) ? model.TypeDesc.BaseTypeDesc : model.TypeDesc);
385 if (!typeDesc.IsPrimitive)
386 {
387 throw new InvalidOperationException(System.SR.Format(System.SR.XmlInvalidDataTypeUsage, dataType, "XmlElementAttribute.DataType"));
388 }
389 TypeDesc typeDesc2 = _typeScope.GetTypeDesc(dataType, "http://www.w3.org/2001/XMLSchema");
390 if (typeDesc2 == null)
391 {
392 throw new InvalidOperationException(System.SR.Format(System.SR.XmlInvalidXsdDataType, dataType, "XmlElementAttribute.DataType", new XmlQualifiedName(dataType, "http://www.w3.org/2001/XMLSchema").ToString()));
393 }
394 if (typeDesc.FullName != typeDesc2.FullName)
395 {
396 throw new InvalidOperationException(System.SR.Format(System.SR.XmlDataTypeMismatch, dataType, "XmlElementAttribute.DataType", typeDesc.FullName));
397 }
398 }
399 if (a == null)
400 {
402 }
403 if (((uint)a.XmlFlags & 0xFFFFFF3Fu) != 0)
404 {
406 }
407 switch (model.TypeDesc.Kind)
408 {
409 case TypeKind.Enum:
410 return ImportEnumMapping((EnumModel)model, ns, repeats);
411 case TypeKind.Primitive:
412 if (a.XmlFlags != 0)
413 {
415 }
416 return ImportPrimitiveMapping((PrimitiveModel)model, context, dataType, repeats);
417 case TypeKind.Array:
418 case TypeKind.Collection:
419 case TypeKind.Enumerable:
420 {
421 if (context != ImportContext.Element)
422 {
423 throw UnsupportedException(model.TypeDesc, context);
424 }
426 ArrayMapping result = ImportArrayLikeMapping((ArrayModel)model, ns, limiter);
428 return result;
429 }
430 case TypeKind.Root:
431 case TypeKind.Struct:
432 case TypeKind.Class:
433 if (context != ImportContext.Element)
434 {
435 throw UnsupportedException(model.TypeDesc, context);
436 }
437 if (model.TypeDesc.IsOptionalValue)
438 {
439 TypeDesc typeDesc3 = (string.IsNullOrEmpty(dataType) ? model.TypeDesc.BaseTypeDesc : _typeScope.GetTypeDesc(dataType, "http://www.w3.org/2001/XMLSchema"));
440 string typeName = ((typeDesc3.DataType == null) ? typeDesc3.Name : typeDesc3.DataType.Name);
441 TypeMapping typeMapping = GetTypeMapping(typeName, ns, typeDesc3, _types, null);
442 if (typeMapping == null)
443 {
444 typeMapping = ImportTypeMapping(_modelScope.GetTypeModel(model.TypeDesc.BaseTypeDesc.Type), ns, context, dataType, null, repeats, openModel, limiter);
445 }
446 return CreateNullableMapping(typeMapping, model.TypeDesc.Type);
447 }
448 return ImportStructLikeMapping((StructModel)model, ns, openModel, a, limiter);
449 default:
450 if (model.TypeDesc.Kind == TypeKind.Serializable)
451 {
452 if (((uint)a.XmlFlags & 0xFFFFFFBFu) != 0)
453 {
454 throw new InvalidOperationException(System.SR.Format(System.SR.XmlSerializableAttributes, model.TypeDesc.FullName, "XmlSchemaProviderAttribute"));
455 }
456 }
457 else if (a.XmlFlags != 0)
458 {
460 }
461 if (model.TypeDesc.IsSpecial)
462 {
463 return ImportSpecialMapping(model.Type, model.TypeDesc, ns, context, limiter);
464 }
465 throw UnsupportedException(model.TypeDesc, context);
466 }
467 }
468 catch (Exception ex)
469 {
470 if (ex is OutOfMemoryException)
471 {
472 throw;
473 }
474 throw CreateTypeReflectionException(model.TypeDesc.FullName, ex);
475 }
476 }
static string XmlInvalidTypeAttributes
Definition SR.cs:1572
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string XmlInvalidXsdDataType
Definition SR.cs:1444
static string XmlSerializableAttributes
Definition SR.cs:1764
static string XmlDataTypeMismatch
Definition SR.cs:1446
static string XmlInvalidDataTypeUsage
Definition SR.cs:1442
Definition SR.cs:7
TypeModel GetTypeModel(Type type)
Definition ModelScope.cs:22
TypeDesc GetTypeDesc(string name, string ns)
Definition TypeScope.cs:224
NullableMapping CreateNullableMapping(TypeMapping baseMapping, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type type)
EnumMapping ImportEnumMapping(EnumModel model, string ns, bool repeats)
Exception CreateTypeReflectionException(string context, Exception e)
TypeMapping GetTypeMapping(string typeName, string ns, TypeDesc typeDesc, NameTable typeLib, Type type)
static Exception UnsupportedException(TypeDesc typeDesc, ImportContext context)
PrimitiveMapping ImportPrimitiveMapping(PrimitiveModel model, ImportContext context, string dataType, bool repeats)
SpecialMapping ImportSpecialMapping(Type type, TypeDesc typeDesc, string ns, ImportContext context, RecursionLimiter limiter)
StructMapping ImportStructLikeMapping(StructModel model, string ns, bool openModel, XmlAttributes a, RecursionLimiter limiter)
ArrayMapping ImportArrayLikeMapping(ArrayModel model, string ns, RecursionLimiter limiter)
XmlAttributes GetAttributes(Type type, bool canBeSimpleType)

References System.Xml.Serialization.XmlReflectionImporter._arrayNestingLevel, System.Xml.Serialization.XmlReflectionImporter._modelScope, System.Xml.Serialization.XmlReflectionImporter._types, System.Xml.Serialization.XmlReflectionImporter._typeScope, System.Xml.Serialization.XmlReflectionImporter.CreateNullableMapping(), System.Xml.Serialization.XmlReflectionImporter.CreateTypeReflectionException(), System.Xml.Dictionary, System.SR.Format(), System.Xml.Serialization.XmlReflectionImporter.GetAttributes(), System.Xml.Serialization.TypeScope.GetTypeDesc(), System.Xml.Serialization.XmlReflectionImporter.GetTypeMapping(), System.Xml.Serialization.ModelScope.GetTypeModel(), System.Xml.Serialization.XmlReflectionImporter.ImportArrayLikeMapping(), System.Xml.Serialization.XmlReflectionImporter.ImportEnumMapping(), System.Xml.Serialization.XmlReflectionImporter.ImportPrimitiveMapping(), System.Xml.Serialization.XmlReflectionImporter.ImportSpecialMapping(), System.Xml.Serialization.XmlReflectionImporter.ImportStructLikeMapping(), System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(), System.Xml.Serialization.XmlReflectionImporter.InvalidAttributeUseException(), System.Xml.Serialization.TypeScope.IsOptionalValue(), System.ToString, System.Xml.Serialization.XmlReflectionImporter.UnsupportedException(), System.SR.XmlDataTypeMismatch, System.SR.XmlInvalidDataTypeUsage, System.SR.XmlInvalidTypeAttributes, System.SR.XmlInvalidXsdDataType, and System.SR.XmlSerializableAttributes.