public override void WriteString (string text)
{
CheckState ();
if (state == WriteState.Start)
throw new InvalidOperationException ("Top-level content string is not allowed in this XmlDictionaryWriter");
if (state == WriteState.Element) {
CloseStartElement ();
state = WriteState.Content;
}
if (state == WriteState.Attribute)
attr_value += text;
else if (text == null) {
no_string_yet = false;
is_null = true;
OutputString ("null");
} else {
switch (element_kinds.Peek ()) {
case ElementType.String:
if (no_string_yet) {
OutputAsciiChar ('"');
no_string_yet = false;
}
break;
case ElementType.Number:
// .NET is buggy here, it just outputs raw string, which results in invalid JSON format.
bool isString = false;
switch (text) {
case "INF":
case "-INF":
case "NaN":
isString = true;
break;
}
if (isString) {
element_kinds.Pop ();
element_kinds.Push (ElementType.String);
goto case ElementType.String;
}
break;
case ElementType.Boolean:
break;
default:
throw new XmlException (String.Format ("Simple content string is allowed only for string, number and boolean types and not for {0} type", element_kinds.Peek ()));
}
OutputString (EscapeStringLiteral (text));
}
}