System.IO.StringWriter.Dispose C# (CSharp) Méthode

Dispose() protected méthode

protected Dispose ( bool disposing ) : void
disposing bool
Résultat void
        protected override void Dispose(bool disposing)
        {
            // Do not destroy _sb, so that we can extract this after we are
            // done writing (similar to MemoryStream's GetBuffer & ToArray methods)
            _isOpen = false;
            base.Dispose(disposing);
        }

Usage Example

Exemple #1
0
 /// <summary>
 /// 将xml字符串格式化
 /// </summary>
 /// <param name="originalString">原始字符串</param>
 /// <param name="formatString">格式化后的数据,或错误信息</param>
 /// <returns>是否成功</returns>
 public static bool FormatXmlString(string originalString, out string formatString)
 {
     System.Xml.XmlDocument   xmlDoc = new System.Xml.XmlDocument();
     System.IO.StringWriter   sw     = new System.IO.StringWriter();
     System.Xml.XmlTextWriter xtw    = new System.Xml.XmlTextWriter(sw);
     xtw.Formatting  = System.Xml.Formatting.Indented;
     xtw.Indentation = 1;
     xtw.IndentChar  = '\t';
     try
     {
         xmlDoc.LoadXml(originalString);
         xmlDoc.WriteTo(xtw);
         formatString = sw.ToString();
         return(true);
     }
     catch (Exception ex)
     {
         formatString = ex.Message;
         return(false);
     }
     finally
     {
         sw.Dispose();
     }
 }
All Usage Examples Of System.IO.StringWriter::Dispose