private ElementAccessor ImportElement(TypeModel model, XmlRootAttribute root, string defaultNamespace, RecursionLimiter limiter)
{
XmlAttributes a = GetAttributes(model.Type, true);
if (root == null)
root = a.XmlRoot;
string ns = root == null ? null : root.Namespace;
if (ns == null) ns = defaultNamespace;
if (ns == null) ns = _defaultNs;
_arrayNestingLevel = -1;
_savedArrayItemAttributes = null;
_savedArrayNamespace = null;
ElementAccessor element = CreateElementAccessor(ImportTypeMapping(model, ns, ImportContext.Element, string.Empty, a, limiter), ns);
if (root != null)
{
if (root.ElementName.Length > 0)
element.Name = XmlConvert.EncodeLocalName(root.ElementName);
if (root.IsNullableSpecified && !root.IsNullable && model.TypeDesc.IsOptionalValue)
//XmlInvalidNotNullable=IsNullable may not be set to 'false' for a Nullable<{0}> type. Consider using '{0}' type or removing the IsNullable property from the XmlElement attribute.
throw new InvalidOperationException(SR.Format(SR.XmlInvalidNotNullable, model.TypeDesc.BaseTypeDesc.FullName, "XmlRoot"));
element.IsNullable = root.IsNullableSpecified ? root.IsNullable : model.TypeDesc.IsNullable || model.TypeDesc.IsOptionalValue;
CheckNullable(element.IsNullable, model.TypeDesc, element.Mapping);
}
else
element.IsNullable = model.TypeDesc.IsNullable || model.TypeDesc.IsOptionalValue;
element.Form = XmlSchemaForm.Qualified;
return (ElementAccessor)ReconcileAccessor(element, _elements);
}