private MemberMapping ImportMemberMapping(XmlReflectionMember xmlReflectionMember, string ns, XmlReflectionMember[] xmlReflectionMembers, bool rpc, bool openModel, RecursionLimiter limiter)
{
XmlSchemaForm form = rpc ? XmlSchemaForm.Unqualified : XmlSchemaForm.Qualified;
XmlAttributes a = xmlReflectionMember.XmlAttributes;
TypeDesc typeDesc = _typeScope.GetTypeDesc(xmlReflectionMember.MemberType);
if (a.XmlFlags == 0)
{
if (typeDesc.IsArrayLike)
{
XmlArrayAttribute xmlArray = CreateArrayAttribute(typeDesc);
xmlArray.ElementName = xmlReflectionMember.MemberName;
xmlArray.Namespace = rpc ? null : ns;
xmlArray.Form = form;
a.XmlArray = xmlArray;
}
else
{
XmlElementAttribute xmlElement = CreateElementAttribute(typeDesc);
// If there is no metadata specified on a parameter, then see if someone used
// an XmlRoot attribute on the struct or class.
if (typeDesc.IsStructLike)
{
XmlAttributes structAttrs = new XmlAttributes(xmlReflectionMember.MemberType.GetTypeInfo());
if (structAttrs.XmlRoot != null)
{
if (structAttrs.XmlRoot.ElementName.Length > 0)
xmlElement.ElementName = structAttrs.XmlRoot.ElementName;
if (rpc)
{
xmlElement.Namespace = null;
if (structAttrs.XmlRoot.IsNullableSpecified)
xmlElement.IsNullable = structAttrs.XmlRoot.IsNullable;
}
else
{
xmlElement.Namespace = structAttrs.XmlRoot.Namespace;
xmlElement.IsNullable = structAttrs.XmlRoot.IsNullable;
}
}
}
if (xmlElement.ElementName.Length == 0)
xmlElement.ElementName = xmlReflectionMember.MemberName;
if (xmlElement.Namespace == null && !rpc)
xmlElement.Namespace = ns;
xmlElement.Form = form;
a.XmlElements.Add(xmlElement);
}
}
else if (a.XmlRoot != null)
{
CheckNullable(a.XmlRoot.IsNullable, typeDesc, null);
}
MemberMapping member = new MemberMapping();
member.Name = xmlReflectionMember.MemberName;
bool checkSpecified = FindSpecifiedMember(xmlReflectionMember.MemberName, xmlReflectionMembers) != null;
FieldModel model = new FieldModel(xmlReflectionMember.MemberName, xmlReflectionMember.MemberType, _typeScope.GetTypeDesc(xmlReflectionMember.MemberType), checkSpecified, false);
member.CheckShouldPersist = model.CheckShouldPersist;
member.CheckSpecified = model.CheckSpecified;
member.ReadOnly = model.ReadOnly; // || !model.FieldTypeDesc.HasDefaultConstructor;
Type choiceIdentifierType = null;
if (a.XmlChoiceIdentifier != null)
{
choiceIdentifierType = GetChoiceIdentifierType(a.XmlChoiceIdentifier, xmlReflectionMembers, typeDesc.IsArrayLike, model.Name);
}
ImportAccessorMapping(member, model, a, ns, choiceIdentifierType, rpc, openModel, limiter);
if (xmlReflectionMember.OverrideIsNullable && member.Elements.Length > 0)
member.Elements[0].IsNullable = false;
return member;
}