TypeMapping ImportTypeMapping(TypeModel model, string dataType) {
if (dataType.Length > 0) {
if (!model.TypeDesc.IsPrimitive) {
throw new InvalidOperationException(Res.GetString(Res.XmlInvalidDataTypeUsage, dataType, "SoapElementAttribute.DataType"));
}
TypeDesc td = typeScope.GetTypeDesc(dataType, XmlSchema.Namespace);
if (td == null) {
throw new InvalidOperationException(Res.GetString(Res.XmlInvalidXsdDataType, dataType, "SoapElementAttribute.DataType", new XmlQualifiedName(dataType, XmlSchema.Namespace).ToString()));
}
if (model.TypeDesc.FullName != td.FullName) {
throw new InvalidOperationException(Res.GetString(Res.XmlDataTypeMismatch, dataType, "SoapElementAttribute.DataType", model.TypeDesc.FullName));
}
}
SoapAttributes a = GetAttributes(model.Type);
if ((a.SoapFlags & ~SoapAttributeFlags.Type) != 0)
throw new InvalidOperationException(Res.GetString(Res.XmlInvalidTypeAttributes, model.Type.FullName));
switch (model.TypeDesc.Kind) {
case TypeKind.Enum:
return ImportEnumMapping((EnumModel)model);
case TypeKind.Primitive:
return ImportPrimitiveMapping((PrimitiveModel)model, dataType);
case TypeKind.Array:
case TypeKind.Collection:
case TypeKind.Enumerable:
return ImportArrayLikeMapping((ArrayModel)model);
case TypeKind.Root:
case TypeKind.Class:
case TypeKind.Struct:
if (model.TypeDesc.IsOptionalValue) {
TypeDesc baseTypeDesc = model.TypeDesc.BaseTypeDesc;
SoapAttributes baseAttributes = GetAttributes(baseTypeDesc.Type);
string typeNs = defaultNs;
if (baseAttributes.SoapType != null && baseAttributes.SoapType.Namespace != null)
typeNs = baseAttributes.SoapType.Namespace;
TypeMapping baseMapping = GetTypeMapping(baseTypeDesc.Name, typeNs, baseTypeDesc);
if (baseMapping == null)
baseMapping = ImportTypeMapping(modelScope.GetTypeModel(baseTypeDesc.Type, true), dataType);
return CreateNullableMapping(baseMapping, model.TypeDesc);
}
else {
return ImportStructLikeMapping((StructModel)model);
}
default:
throw new NotSupportedException(Res.GetString(Res.XmlUnsupportedSoapTypeKind, model.TypeDesc.FullName));
}
}