System.Runtime.Serialization.Json.JsonWriter.WriteStartElement C# (CSharp) Method

WriteStartElement() public method

public WriteStartElement ( string prefix, string localName, string ns ) : void
prefix string
localName string
ns string
return void
		public override void WriteStartElement (string prefix, string localName, string ns)
		{
			CheckState ();

			if (localName == null)
				throw new ArgumentNullException ("localName");
			else if (localName.Length == 0)
				throw new ArgumentException ("Empty string is not a valid localName in this XmlDictionaryWriter");

			if (!String.IsNullOrEmpty (ns))
				throw new ArgumentException ("Non-empty namespace URI is not allowed in this XmlDictionaryWriter");
			if (!String.IsNullOrEmpty (prefix))
				throw new ArgumentException ("Non-empty prefix is not allowed in this XmlDictionaryWriter");

			if (state == WriteState.Attribute)
				WriteEndAttribute ();
			if (state == WriteState.Element)
				CloseStartElement ();

			else if (state != WriteState.Start && element_kinds.Count == 0)
				throw new XmlException ("This XmlDictionaryWriter does not support multiple top-level elements");

			if (element_kinds.Count == 0) {
				if (localName != "root")
					throw new XmlException ("Only 'root' is allowed for the name of the top-level element");
			} else {
				switch (element_kinds.Peek ()) {
				case ElementType.Array:
					if (localName != "item")
						throw new XmlException ("Only 'item' is allowed as a content element of an array");
					break;
				case ElementType.String:
					throw new XmlException ("Mixed content is not allowed in this XmlDictionaryWriter");
				case ElementType.None:
					throw new XmlException ("Before writing a child element, an element needs 'type' attribute to indicate whether the element is a JSON array or a JSON object in this XmlDictionaryWriter");
				}

				if (first_content_flags.Peek ()) {
					first_content_flags.Pop ();
					first_content_flags.Push (false);
				}
				else
					OutputAsciiChar (',');

				if (element_kinds.Peek () != ElementType.Array) {
					OutputAsciiChar ('"');
					OutputString (localName);
					OutputAsciiChar ('\"');
					OutputAsciiChar (':');
				}
			}

			element_kinds.Push (ElementType.None); // undetermined yet

			state = WriteState.Element;
		}