private void ImportAccessorMapping(MemberMapping accessor, FieldModel model, SoapAttributes a, string ns, XmlSchemaForm form, RecursionLimiter limiter)
{
Type accessorType = model.FieldType;
string accessorName = model.Name;
accessor.TypeDesc = _typeScope.GetTypeDesc(accessorType);
if (accessor.TypeDesc.IsVoid)
{
throw new InvalidOperationException(SR.XmlInvalidVoid);
}
SoapAttributeFlags flags = a.GetSoapFlags();
if ((flags & SoapAttributeFlags.Attribute) == SoapAttributeFlags.Attribute)
{
if (!accessor.TypeDesc.IsPrimitive && !accessor.TypeDesc.IsEnum)
{
throw new InvalidOperationException(SR.Format(SR.XmlIllegalSoapAttribute, accessorName, accessor.TypeDesc.FullName));
}
if ((flags & SoapAttributeFlags.Attribute) != flags)
{
throw new InvalidOperationException(SR.XmlInvalidElementAttribute);
}
AttributeAccessor attribute = new AttributeAccessor();
attribute.Name = Accessor.EscapeQName(a.SoapAttribute == null || a.SoapAttribute.AttributeName.Length == 0 ? accessorName : a.SoapAttribute.AttributeName);
attribute.Namespace = a.SoapAttribute == null || a.SoapAttribute.Namespace == null ? ns : a.SoapAttribute.Namespace;
attribute.Form = XmlSchemaForm.Qualified; // attributes are always qualified since they're only used for encoded soap headers
attribute.Mapping = ImportTypeMapping(_modelScope.GetTypeModel(accessorType), (a.SoapAttribute == null ? String.Empty : a.SoapAttribute.DataType), limiter);
attribute.Default = GetDefaultValue(model.FieldTypeDesc, a);
accessor.Attribute = attribute;
accessor.Elements = Array.Empty <ElementAccessor>();
}
else
{
if ((flags & SoapAttributeFlags.Element) != flags)
{
throw new InvalidOperationException(SR.XmlInvalidElementAttribute);
}
ElementAccessor element = new ElementAccessor();
element.IsSoap = true;
element.Name = XmlConvert.EncodeLocalName(a.SoapElement == null || a.SoapElement.ElementName.Length == 0 ? accessorName : a.SoapElement.ElementName);
element.Namespace = ns;
element.Form = form;
element.Mapping = ImportTypeMapping(_modelScope.GetTypeModel(accessorType), (a.SoapElement == null ? String.Empty : a.SoapElement.DataType), limiter);
if (a.SoapElement != null)
{
element.IsNullable = a.SoapElement.IsNullable;
}
accessor.Elements = new ElementAccessor[] { element };
}
}