本文整理汇总了C#中WriteState类的典型用法代码示例。如果您正苦于以下问题:C# WriteState类的具体用法?C# WriteState怎么用?C# WriteState使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WriteState类属于命名空间,在下文中一共展示了WriteState类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Close
public override void Close()
{
if (!this.closed)
{
this.closed = true;
this.state = WriteState.Closed;
this.rawWritingEnabled = false;
}
}
示例2: RawXmlWriter
public RawXmlWriter(Stream stream)
{
if (stream == null)
{
throw new ArgumentNullException("Stream");
}
this.stream = stream;
this.state = WriteState.Start;
}
示例3: SetOutput
protected void SetOutput(XmlStreamNodeWriter writer)
{
_inList = false;
_writer = writer;
_nodeWriter = writer;
_writeState = WriteState.Start;
_documentState = DocumentState.None;
_nsMgr.Clear();
if (_depth != 0)
{
_elements = null;
_depth = 0;
}
_attributeLocalName = null;
_attributeValue = null;
}
示例4: SetOutput
protected void SetOutput(XmlStreamNodeWriter writer)
{
this.inList = false;
this.writer = writer;
this.nodeWriter = writer;
this.writeState = WriteState.Start;
this.documentState = DocumentState.None;
this.nsMgr.Clear();
if (this.depth != 0)
{
this.elements = null;
this.depth = 0;
}
this.attributeLocalName = null;
this.attributeValue = null;
this.oldWriter = null;
this.oldStream = null;
}
示例5: setMode
private static WriteState setMode(WriteState newState, WriteState fromState, StringBuilder sb)
{
if (newState == fromState)
return newState;
if (fromState != WriteState.Normal)
{
// needs to close the old state
sb.Append(@"\X0\");
}
if (newState == WriteState.TwoBytes)
{
sb.Append(@"\X2\");
}
else if (newState == WriteState.FourBytes)
{
sb.Append(@"\X4\");
}
return newState;
}
示例6: Init
private void Init(XmlNode root, bool clearCurrentContents)
{
this.root = root;
if (clearCurrentContents)
this.root.RemoveAll();
if (root is XmlDocument)
{
owner = (XmlDocument)root;
state = WriteState.Start;
}
else
{
owner = root.OwnerDocument;
state = WriteState.Content;
}
current = root;
}
示例7: WriteString
/// <summary>
/// Creates a System.Xml.XmlText node. If the current node is already an XmlText
/// node it appends the text to that node.
/// </summary>
public override void WriteString(string text)
{
XmlNode parent = current;
if (state == WriteState.Attribute)
{
parent = ca;
}
else if (state == WriteState.Element)
{
state = WriteState.Content;
}
if (state != WriteState.Attribute && state != WriteState.Content)
throw new InvalidOperationException("Writer is in the wrong state to be writing text content");
XmlNode last = parent.LastChild;
if (last == null || !(last is XmlText))
{
last = owner.CreateTextNode(text);
parent.AppendChild(last);
}
else
{
XmlText t = last as XmlText;
t.AppendData(text);
}
}
示例8: WriteStartDocument
/// <summary>
/// Writes the XmlDeclaration node with a standalone attribute. This is only allowed when the
/// writer is in the Start state, which only happens if the writer was constructed with an
/// XmlDocument object.
/// </summary>
/// <param name="standalone">If true, standalone attribute has value "yes" otherwise it has the value "no".</param>
public override void WriteStartDocument(bool standalone)
{
if (state != WriteState.Start)
throw new InvalidOperationException("Writer is not in the Start state or root node is not an XmlDocument object");
current.AppendChild(owner.CreateXmlDeclaration("1.0", null, standalone ? "yes" : "no"));
state = WriteState.Prolog;
}
示例9: WriteRaw
/// <summary>
/// WriteRaw writes out the given string "unescaped", in other words it better be well formed XML markup.
/// So for the XmlNodeWriter we parse this string and build the resulting tree, so it maps to setting the
/// InnerXml property.
/// </summary>
/// <param name="data"></param>
public override void WriteRaw(string data)
{
if (data.IndexOf("<")<0)
{
WriteString(data);
return;
}
switch (state)
{
case WriteState.Start:
goto case WriteState.Content;
case WriteState.Prolog:
goto case WriteState.Content;
case WriteState.Element:
state = WriteState.Content;
goto case WriteState.Content;
case WriteState.Attribute:
{
ArrayList saved = new ArrayList();
if (ca.HasChildNodes)
{
while (ca.FirstChild != null)
{
saved.Add(ca.FirstChild);
ca.RemoveChild(ca.FirstChild);
}
}
ca.InnerXml = data;
for (int i = saved.Count-1; i>=0; i--)
{
ca.PrependChild((XmlNode)saved[i]);
}
}
break;
case WriteState.Content:
{
ArrayList saved = new ArrayList();
if (current.HasChildNodes)
{
while (current.FirstChild != null)
{
saved.Add(current.FirstChild);
current.RemoveChild(current.FirstChild);
}
}
current.InnerXml = data;
for (int i = saved.Count-1; i>=0; i--)
{
current.PrependChild((XmlNode)saved[i]);
}
state = WriteState.Content;
}
break;
case WriteState.Closed:
throw new InvalidOperationException("Writer is closed");
}
}
示例10: WriteEntityRef
/// <summary>
/// Creates a System.Xml.XmlEntityReference node.
/// </summary>
/// <param name="name">The name of the entity reference</param>
public override void WriteEntityRef(string name)
{
if (state == WriteState.Element)
state = WriteState.Content;
XmlNode n = current;
if (state == WriteState.Attribute)
{
n = ca;
}
else if (state != WriteState.Content)
{
throw new InvalidOperationException("Invalid state '"+WriteState.ToString()+"' for entity reference");
}
n.AppendChild(owner.CreateEntityReference(name));
}
示例11: WriteEndDocument
/// <summary>
/// Closes any open elements and puts the writer back in the Start state.
/// </summary>
public override void WriteEndDocument()
{
current = root;
state = WriteState.Start;
}
示例12: Close
public override void Close()
{
if (!IsClosed)
{
try
{
WriteEndDocument();
}
finally
{
try
{
nodeWriter.Flush();
nodeWriter.Close();
}
finally
{
writeState = WriteState.Closed;
if (depth != 0)
{
depth = 0;
}
}
}
}
}
示例13: InitializeWriter
void InitializeWriter()
{
nodeType = JsonNodeType.None;
dataType = JsonDataType.None;
isWritingDataTypeAttribute = false;
wroteServerTypeAttribute = false;
isWritingServerTypeAttribute = false;
serverTypeValue = null;
attributeText = null;
if (depth != 0)
{
depth = 0;
}
if ((scopes != null) && (scopes.Length > JsonGlobals.maxScopeSize))
{
scopes = null;
}
// Can't let writeState be at Closed if reinitializing.
writeState = WriteState.Start;
endElementBuffer = false;
indentLevel = 0;
}
示例14: WriteEndAttribute
public override void WriteEndAttribute ()
{
if (state != WriteState.Attribute)
throw StateError ("End of attribute");
if (writer.Wrapped == preserver) {
writer = writer.PreviousWrapper ?? new TextWriterWrapper (source, this);
string value = preserver.ToString ();
if (is_preserved_xmlns) {
if (preserved_name.Length > 0 &&
value.Length == 0)
throw ArgumentError ("Non-empty prefix must be mapped to non-empty namespace URI.");
string existing = nsmanager.LookupNamespace (preserved_name, false);
explicit_nsdecls.Add (preserved_name);
if (open_count > 0) {
if (v2 &&
elements [open_count - 1].Prefix == preserved_name &&
elements [open_count - 1].NS != value)
throw new XmlException (String.Format ("Cannot redefine the namespace for prefix '{0}' used at current element", preserved_name));
if (elements [open_count - 1].NS != String.Empty ||
elements [open_count - 1].Prefix != preserved_name) {
if (existing != value)
nsmanager.AddNamespace (preserved_name, value);
}
}
} else {
switch (preserved_name) {
case "lang":
if (open_count > 0)
elements [open_count - 1].XmlLang = value;
break;
case "space":
switch (value) {
case "default":
if (open_count > 0)
elements [open_count - 1].XmlSpace = XmlSpace.Default;
break;
case "preserve":
if (open_count > 0)
elements [open_count - 1].XmlSpace = XmlSpace.Preserve;
break;
default:
throw ArgumentError ("Invalid value for xml:space.");
}
break;
}
}
writer.Write (value);
}
writer.Write (formatSettings.QuoteChar);
if (writer.InBlock) {
writer.MarkBlockEnd ();
if (writer.Column > TextPolicy.FileWidth) {
WriteIndentAttribute ();
writer.WriteBlock (true);
writer.AttributesPerLine++;
} else {
writer.WriteBlock (false);
}
}
state = WriteState.Element;
}
示例15: WriteDocType
/// <summary>
/// Creates an System.Xml.XmlDocumentType node.
/// </summary>
public override void WriteDocType(string name, string pubid, string sysid, string subset)
{
if (state != WriteState.Prolog && state != WriteState.Start)
throw new InvalidOperationException("Writer is not in the Start or Prolog state, or root node is not an XmlDocument object");
if (owner.DocumentType != null)
owner.RemoveChild(owner.DocumentType);
owner.XmlResolver = null;
current.AppendChild(owner.CreateDocumentType(name, pubid, sysid, subset));
state = WriteState.Prolog;
}