public override void WriteStartElement(string prefix, string localName, string ns)
{
if (localName == null)
{
throw new ArgumentNullException(nameof(localName));
}
if (localName.Length == 0)
{
throw new ArgumentException(SR.JsonInvalidLocalNameEmpty, nameof(localName));
}
if (!string.IsNullOrEmpty(prefix))
{
if (string.IsNullOrEmpty(ns) || !TrySetWritingNameWithMapping(localName, ns))
{
throw new ArgumentException(SR.Format(SR.JsonPrefixMustBeNullOrEmpty, prefix), nameof(prefix));
}
}
if (!string.IsNullOrEmpty(ns))
{
if (!TrySetWritingNameWithMapping(localName, ns))
{
throw new ArgumentException(SR.Format(SR.JsonNamespaceMustBeEmpty, ns), nameof(ns));
}
}
if (IsClosed)
{
ThrowClosed();
}
if (HasOpenAttribute)
{
throw new XmlException(SR.Format(SR.JsonOpenAttributeMustBeClosedFirst, "WriteStartElement"));
}
if ((_nodeType != JsonNodeType.None) && _depth == 0)
{
throw new XmlException(SR.JsonMultipleRootElementsNotAllowedOnWriter);
}
switch (_nodeType)
{
case JsonNodeType.None:
{
if (!localName.Equals(JsonGlobals.rootString))
{
throw new XmlException(SR.Format(SR.JsonInvalidRootElementName, localName, JsonGlobals.rootString));
}
EnterScope(JsonNodeType.Element);
break;
}
case JsonNodeType.Element:
{
if ((_dataType != JsonDataType.Array) && (_dataType != JsonDataType.Object))
{
throw new XmlException(SR.JsonNodeTypeArrayOrObjectNotSpecified);
}
if (_indent)
{
WriteNewLine();
WriteIndent();
}
if (!IsWritingCollection)
{
if (_nameState != NameState.IsWritingNameWithMapping)
{
WriteJsonElementName(localName);
}
}
else if (!localName.Equals(JsonGlobals.itemString))
{
throw new XmlException(SR.Format(SR.JsonInvalidItemNameForArrayElement, localName, JsonGlobals.itemString));
}
EnterScope(JsonNodeType.Element);
break;
}
case JsonNodeType.EndElement:
{
if (_endElementBuffer)
{
_nodeWriter.WriteText(JsonGlobals.MemberSeparatorChar);
}
if (_indent)
{
WriteNewLine();
WriteIndent();
}
if (!IsWritingCollection)
{
if (_nameState != NameState.IsWritingNameWithMapping)
{
WriteJsonElementName(localName);
}
}
else if (!localName.Equals(JsonGlobals.itemString))
{
throw new XmlException(SR.Format(SR.JsonInvalidItemNameForArrayElement, localName, JsonGlobals.itemString));
}
EnterScope(JsonNodeType.Element);
break;
}
default:
throw new XmlException(SR.JsonInvalidStartElementCall);
}
_isWritingDataTypeAttribute = false;
_isWritingServerTypeAttribute = false;
_isWritingXmlnsAttribute = false;
_wroteServerTypeAttribute = false;
_serverTypeValue = null;
_dataType = JsonDataType.None;
_nodeType = JsonNodeType.Element;
}