public string ExportAnyType(XmlMembersMapping members)
{
if (members.Count == 1 && members[0].Any && members[0].ElementName.Length == 0)
{
XmlMemberMapping member = members[0];
string ns = member.Namespace;
bool isUnbounded = member.Mapping.TypeDesc.IsArrayLike;
bool isMixed = isUnbounded && member.Mapping.TypeDesc.ArrayElementTypeDesc != null ? member.Mapping.TypeDesc.ArrayElementTypeDesc.IsMixed : member.Mapping.TypeDesc.IsMixed;
if (isMixed && member.Mapping.TypeDesc.IsMixed)
// special case of the single top-level XmlNode --> map it to node array to match the "mixed" any type for backward compatibility
isUnbounded = true;
// generate type name, make sure that it is backward compatible
string baseName = isMixed ? "any" : isUnbounded ? "anyElements" : "anyElement";
string name = baseName;
int i = 0;
XmlSchema schema = _schemas[ns];
if (schema != null)
{
while (true)
{
XmlSchemaType schemaType = FindSchemaType(name, schema.Items);
if (schemaType == null)
break;
if (IsAnyType(schemaType, isMixed, isUnbounded))
return name;
i++;
name = baseName + i.ToString(CultureInfo.InvariantCulture);
}
}
XmlSchemaComplexType type = new XmlSchemaComplexType();
type.Name = name;
type.IsMixed = isMixed;
XmlSchemaSequence seq = new XmlSchemaSequence();
XmlSchemaAny any = new XmlSchemaAny();
any.MinOccurs = 0;
if (isUnbounded)
any.MaxOccurs = decimal.MaxValue;
seq.Items.Add(any);
type.Particle = seq;
AddSchemaItem(type, ns, null);
return name;
}
else
{
return null;
}
}