System.Xml.XmlReaderBinarySupport.CheckState C# (CSharp) Method

CheckState() private method

private CheckState ( bool element, CommandState action ) : void
element bool
action CommandState
return void
		private void CheckState (bool element, CommandState action)
		{
			if (state == CommandState.None) {
				if (textCache == null)
					textCache = new StringBuilder ();
				else
					textCache.Length = 0;
				if (action == CommandState.None)
					return; // for ReadValueChunk()
				if (reader.ReadState != ReadState.Interactive)
					return;
				switch (reader.NodeType) {
				case XmlNodeType.Text:
				case XmlNodeType.CDATA:
				case XmlNodeType.SignificantWhitespace:
				case XmlNodeType.Whitespace:
					if (!element) {
						state = action;
						return;
					}
					break;
				case XmlNodeType.Element:
					if (element) {
						if (!reader.IsEmptyElement)
							reader.Read ();
						state = action;
						return;
					}
					break;
				}
				throw new XmlException ((element ? 
					"Reader is not positioned on an element."
					: "Reader is not positioned on a text node."));
			}
			if (state == action)
				return;
			throw StateError (action);
		}