public override void WriteEndAttribute()
{
if (IsClosed)
{
ThrowClosed();
}
if (!HasOpenAttribute)
{
throw new XmlException(SR.JsonNoMatchingStartAttribute);
}
Fx.Assert(!(_isWritingDataTypeAttribute && _isWritingServerTypeAttribute),
"Can not write type attribute and __type attribute at the same time.");
if (_isWritingDataTypeAttribute)
{
switch (_attributeText)
{
case JsonGlobals.numberString:
{
ThrowIfServerTypeWritten(JsonGlobals.numberString);
_dataType = JsonDataType.Number;
break;
}
case JsonGlobals.stringString:
{
ThrowIfServerTypeWritten(JsonGlobals.stringString);
_dataType = JsonDataType.String;
break;
}
case JsonGlobals.arrayString:
{
ThrowIfServerTypeWritten(JsonGlobals.arrayString);
_dataType = JsonDataType.Array;
break;
}
case JsonGlobals.objectString:
{
_dataType = JsonDataType.Object;
break;
}
case JsonGlobals.nullString:
{
ThrowIfServerTypeWritten(JsonGlobals.nullString);
_dataType = JsonDataType.Null;
break;
}
case JsonGlobals.booleanString:
{
ThrowIfServerTypeWritten(JsonGlobals.booleanString);
_dataType = JsonDataType.Boolean;
break;
}
default:
throw new XmlException(SR.Format(SR.JsonUnexpectedAttributeValue, _attributeText));
}
_attributeText = null;
_isWritingDataTypeAttribute = false;
if (!IsWritingNameWithMapping || WrittenNameWithMapping)
{
WriteDataTypeServerType();
}
}
else if (_isWritingServerTypeAttribute)
{
_serverTypeValue = _attributeText;
_attributeText = null;
_isWritingServerTypeAttribute = false;
// we are writing __type after type="object" (enforced by WSE)
if ((!IsWritingNameWithMapping || WrittenNameWithMapping) && _dataType == JsonDataType.Object)
{
WriteServerTypeAttribute();
}
}
else if (IsWritingNameAttribute)
{
WriteJsonElementName(_attributeText);
_attributeText = null;
_nameState = NameState.IsWritingNameWithMapping | NameState.WrittenNameWithMapping;
WriteDataTypeServerType();
}
else if (_isWritingXmlnsAttribute)
{
if (!string.IsNullOrEmpty(_attributeText) && _isWritingXmlnsAttributeDefaultNs)
{
throw new ArgumentException(SR.Format(SR.JsonNamespaceMustBeEmpty, _attributeText));
}
_attributeText = null;
_isWritingXmlnsAttribute = false;
_isWritingXmlnsAttributeDefaultNs = false;
}
}