当前位置: 首页>>代码示例>>C#>>正文


C# StringWriter.Dispose方法代码示例

本文整理汇总了C#中System.IO.StringWriter.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# StringWriter.Dispose方法的具体用法?C# StringWriter.Dispose怎么用?C# StringWriter.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.StringWriter的用法示例。


在下文中一共展示了StringWriter.Dispose方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AssinaXml

        /// <summary>
        /// Assina e salva o fonte de xml
        /// </summary>
        /// <param name="xmlSource"></param>
        /// <param name="pathXmlDestino"></param>
        /// <returns></returns>
        public static KeyValuePair<bool, string> AssinaXml(string xmlSource, string pathXmlDestino)
        {
            try
            {
                if (string.IsNullOrEmpty(xmlSource))
                {
                    throw new ArgumentNullException("xmlSource", "Parametro não pode ser nulo");
                }

                if (string.IsNullOrEmpty(pathXmlDestino))
                {
                    throw new ArgumentNullException("pathXmlDestino", "Parametro não pode ser nulo");
                }

                var xmlDoc = new XmlDocument();
                xmlDoc.LoadXml(xmlSource);

                using (var xml = new StringWriter(new StringBuilder(xmlDoc.OuterXml)))
                {
                    var rsaKey = RetornaAssinaturaRsa(xml);

                    AssinaXml(xmlDoc, rsaKey);
                    xmlDoc.Save(pathXmlDestino);
                    xml.Dispose();
                }

                return new KeyValuePair<bool, string>(true, "");
            }
            catch (Exception ex)
            {
                return new KeyValuePair<bool, string>(false, ex.Message);
            }
        }
开发者ID:RodrigoDotNet,项目名称:gerador-de-camadas,代码行数:39,代码来源:SerializerHelper.cs

示例2: AssinaXml

        /// <summary>
        /// Assina e salva o fonte de xml
        /// </summary>
        /// <param name="xmlSource"></param>
        /// <param name="pathXmlDestino"></param>
        /// <returns></returns>
        public static void AssinaXml(string xmlSource, string pathXmlDestino)
        {
            try
            {
                if (string.IsNullOrEmpty(xmlSource))
                {
                    throw new ArgumentNullException("xmlSource", "Parametro não pode ser nulo");
                }

                if (string.IsNullOrEmpty(pathXmlDestino))
                {
                    throw new ArgumentNullException("pathXmlDestino", "Parametro não pode ser nulo");
                }

                var xmlDoc = new XmlDocument();
                xmlDoc.LoadXml(xmlSource);

                var xml = new StringWriter(new StringBuilder(xmlDoc.OuterXml));

                var rsaKey = RetornaAssinaturaRSA(xml);

                AssinaXml(xmlDoc, rsaKey);
                xmlDoc.Save(pathXmlDestino);
                xml.Dispose();
            }
            catch
            {
                throw;
            }
        }
开发者ID:RodrigoDotNet,项目名称:gerador-de-camadas,代码行数:36,代码来源:emSerialize.cs

示例3: FromHashtableQueue

 public static string FromHashtableQueue(Queue<Hashtable> queue)
 {
     StringWriter textWriter = new StringWriter();
     JsonWriter jsonWriter = new JsonWriter(textWriter);
     jsonWriter.WriteStartArray();
     JsonSerializer serializer = new JsonSerializer();
     UUIDConverter UUID = new UUIDConverter();
     serializer.Converters.Add(UUID);
     while (queue.Count > 0)
     {
         try
         {
             Hashtable hashtable = queue.Dequeue();
             serializer.Serialize(jsonWriter, hashtable);
         }
         catch(Exception e)
         {
             AjaxLife.Debug("MakeJson.FromHashTable", e.Message);
         }
     }
     jsonWriter.WriteEndArray();
     jsonWriter.Flush();
     string text = textWriter.ToString();
     jsonWriter.Close();
     textWriter.Dispose();
     return text;
 }
开发者ID:AlphaStaxLLC,项目名称:AjaxLife,代码行数:27,代码来源:MakeJson.cs

示例4: btnExport_Click

 protected void btnExport_Click(object sender, EventArgs e)
 {
     int totalCount = 0;
     string kpiName = drpKPI.SelectedValue;
     string unityValue = drpUnits.SelectedValue;
     DateTime beginTime = Convert.ToDateTime(txtBeginTime.Text);
     beginTime = beginTime.AddHours(1);
     DateTime endTime = Convert.ToDateTime(txtEndTime.Text);
     endTime = endTime.AddHours(25);
     OverLimitRecordRepeater.DataSource = overLimitRecordDal.SearchOverLimitRecord(1,
         int.MaxValue, kpiName, unityValue, drpShifts.SelectedValue, beginTime, endTime, out totalCount);
     OverLimitRecordRepeater.DataBind();
     Response.ContentEncoding = Encoding.UTF8;
     Response.ContentType = "application/ms-excel";
     Response.Charset = "utf-8";
     Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode("超限明细报表.xls", System.Text.Encoding.UTF8).ToString());
     StringWriter sw = new StringWriter();
     HtmlTextWriter htw = new HtmlTextWriter(sw);
     OverLimitRecordRepeater.RenderControl(htw);
     Response.Write(sw.ToString());
     Response.Flush();
     Response.End();
     sw.Close();
     sw.Dispose();
     DataBind();
 }
开发者ID:JackSunny1980,项目名称:SISKPI,代码行数:26,代码来源:KPI_OverLimitRecord.aspx.cs

示例5: RunTest

 void RunTest(string c_code, string expectedXml)
 {
     StringReader reader = null;
     StringWriter writer = null;
     try
     {
         reader = new StringReader(c_code);
         writer = new StringWriter();
         var xWriter = new XmlnsHidingWriter(writer)
         {
             Formatting = Formatting.Indented
         };
         var xc = new XmlConverter(reader, xWriter);
         xc.Convert();
         writer.Flush();
         Assert.AreEqual(expectedXml, writer.ToString());
     }
     catch
     {
         Debug.WriteLine(writer.ToString());
         throw;
     }
     finally
     {
         if (writer != null)
             writer.Dispose();
         if (reader != null)
             reader.Dispose();
     }
 }
开发者ID:gh0std4ncer,项目名称:reko,代码行数:30,代码来源:XmlConverterTests.cs

示例6: btnExport_Click

        protected void btnExport_Click(Object sender, EventArgs e)
        {
            Response.ContentEncoding = Encoding.UTF8;
            Response.ContentType = "application/ms-excel";
            Response.Charset = "utf-8";
            Response.AppendHeader("Content-Disposition",
                "attachment;filename=" + HttpUtility.UrlEncode("指标历史数据.xls",
                System.Text.Encoding.UTF8).ToString());
            StringWriter sw = new StringWriter();
            HtmlTextWriter htw = new HtmlTextWriter(sw);

            int RecordCount = 0;
            DateTime StartDate = Convert.ToDateTime(txtStartDate.Text);
            DateTime EndDate = Convert.ToDateTime(txtEndDate.Text);
            String ECID = Request.Params["ECID"];
            using (ECHistoryDataAccess DataAccess = new ECHistoryDataAccess()) {
                ECDataRepeater.DataSource = DataAccess.GetECHourData(ECID, StartDate, EndDate,
                   1, 20000, out RecordCount);
                ECDataRepeater.DataBind();
                ECDataRepeater.RenderControl(htw);
                Response.Write(sw.ToString());
                Response.Flush();
                Response.End();
                sw.Close();
                sw.Dispose();
            }
            DataBind();
        }
开发者ID:JackSunny1980,项目名称:SISKPI,代码行数:28,代码来源:ECChartPage.aspx.cs

示例7: ToJsonString

        public static string ToJsonString(this JToken token)
        {
            if (token == null)
            {
                throw new ArgumentNullException("token");
            }

            // The following code is different from token.ToString(), which special-cases null to return "" instead of
            // "null".
            StringWriter stringWriter = new StringWriter(CultureInfo.InvariantCulture);
            try
            {
                using (JsonWriter jsonWriter = JsonSerialization.CreateJsonTextWriter(stringWriter))
                {
                    token.WriteTo(jsonWriter);
                    jsonWriter.Flush();
                    stringWriter.Flush();

                    string result = stringWriter.ToString();
                    stringWriter = null;

                    return result;
                }
            }
            finally
            {
                if (stringWriter != null)
                {
                    stringWriter.Dispose();
                }
            }
        }
开发者ID:ConnorMcMahon,项目名称:azure-webjobs-sdk,代码行数:32,代码来源:JTokenExtensions.cs

示例8: Transform

        /// <summary>
        /// Transforms the specified XML string
        /// </summary>
        /// <param name="xmlString"></param>
        /// <param name="embeddedResourcePath"></param>
        /// <returns></returns>
		public static string Transform(string xmlString, string embeddedResourcePath)
		{
            string xslString = ResourceReader.ReadFromResource(embeddedResourcePath);

            string result = string.Empty;

            try
            {
                XmlDocument xsl = new XmlDocument();
                xsl.LoadXml(xslString);

                StringWriter sw = new StringWriter();
                XmlTextReader xtr = new XmlTextReader(new StringReader(xmlString));
                XmlTextWriter xtw = new XmlTextWriter(sw);
                XslCompiledTransform t = new XslCompiledTransform();
                t.Load((IXPathNavigable)xsl, null, null);
                t.Transform(xtr, null, xtw, null);
                result = sw.ToString();
                sw.Flush();
                sw.Close();
                sw.Dispose();
            }
            catch(Exception ex) 
            {
                result = string.Format("{0} had the following error with the XML file:\n{1}\n{2}", ex.Source, ex.Message, xmlString);
            }

			return result;

		}
开发者ID:ViniciusConsultor,项目名称:sqlschematool,代码行数:36,代码来源:XsltHelper.cs

示例9: SaveXElementUsingXmlWriter

 private string SaveXElementUsingXmlWriter(XElement elem, NamespaceHandling nsHandling)
 {
     StringWriter sw = new StringWriter();
     using (XmlWriter w = XmlWriter.Create(sw, new XmlWriterSettings() { NamespaceHandling = nsHandling, OmitXmlDeclaration = true }))
     {
         elem.WriteTo(w);
     }
     sw.Dispose();
     return sw.ToString();
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:10,代码来源:OmitDuplicateNamespaceDecl.cs

示例10: CreateMemWriter

        private XmlWriter CreateMemWriter(XmlWriterSettings settings)
        {
            XmlWriterSettings wSettings = settings.Clone();
            wSettings.CloseOutput = false;
            wSettings.OmitXmlDeclaration = true;
            wSettings.CheckCharacters = false;
            XmlWriter w = null;

            switch (WriterType)
            {
                case WriterType.UTF8Writer:
                    wSettings.Encoding = Encoding.UTF8;
                    if (_strWriter != null) _strWriter.Dispose();
                    _strWriter = new StringWriter();
                    w = WriterHelper.Create(_strWriter, wSettings);
                    break;
                case WriterType.UnicodeWriter:
                    wSettings.Encoding = Encoding.Unicode;
                    if (_strWriter != null) _strWriter.Dispose();
                    _strWriter = new StringWriter();
                    w = WriterHelper.Create(_strWriter, wSettings);
                    break;
                case WriterType.WrappedWriter:
                    if (_strWriter != null) _strWriter.Dispose();
                    _strWriter = new StringWriter();
                    XmlWriter ww = WriterHelper.Create(_strWriter, wSettings);
                    w = WriterHelper.Create(ww, wSettings);
                    break;
                case WriterType.CharCheckingWriter:
                    if (_strWriter != null) _strWriter.Dispose();
                    _strWriter = new StringWriter();
                    XmlWriter cw = WriterHelper.Create(_strWriter, wSettings);
                    XmlWriterSettings cws = settings.Clone();
                    cws.CheckCharacters = true;
                    w = WriterHelper.Create(cw, cws);
                    break;
                case WriterType.UTF8WriterIndent:
                    wSettings.Encoding = Encoding.UTF8;
                    wSettings.Indent = true;
                    if (_strWriter != null) _strWriter.Dispose();
                    _strWriter = new StringWriter();
                    w = WriterHelper.Create(_strWriter, wSettings);
                    break;
                case WriterType.UnicodeWriterIndent:
                    wSettings.Encoding = Encoding.Unicode;
                    wSettings.Indent = true;
                    if (_strWriter != null) _strWriter.Dispose();
                    _strWriter = new StringWriter();
                    w = WriterHelper.Create(_strWriter, wSettings);
                    break;
                default:
                    throw new Exception("Unknown writer type");
            }
            return w;
        }
开发者ID:jmhardison,项目名称:corefx,代码行数:55,代码来源:EndOfLineHandlingTests.cs

示例11: IfNoLoggerIsAttachedWeGetAWarning

 public void IfNoLoggerIsAttachedWeGetAWarning()
 {
     const string Warning = "Ohoh";
     const string Message = "No loggers have been created for this message: " + Warning;
     var defaultOut = Console.Out;
     var console = new StringWriter();
     Console.SetOut(console);
     Logger.Warning(Warning);
     Assert.IsTrue(console.ToString().Contains(Message), console.ToString());
     Console.SetOut(defaultOut);
     console.Dispose();
 }
开发者ID:remy22,项目名称:DeltaEngine,代码行数:12,代码来源:LoggerTests.cs

示例12: Compression

 public void Compression(System.Web.UI.HtmlTextWriter writer)
 {
     StringWriter sr = new StringWriter();
     HtmlTextWriter tw = new HtmlTextWriter(sr);
     base.Render(tw);
     tw.Flush();
     tw.Dispose();
     StringBuilder sb = new StringBuilder(sr.ToString());
     string outhtml = Regex.Replace(sb.ToString(), "\\r+\\n+\\s+", string.Empty);
     writer.Write(outhtml);
     sr.Dispose();
 }
开发者ID:ReinhardHsu,项目名称:devfw,代码行数:12,代码来源:Page.cs

示例13: Serializar

        public string Serializar()
        {
            string retorno;

            TextWriter salida = new StringWriter();
            XmlSerializer serializador = new XmlSerializer(this.GetType());
            serializador.Serialize(salida, this);
            retorno = salida.ToString();
            salida.Dispose();

            return retorno;
        }
开发者ID:GonzaloFernandoA,项目名称:FacturacionElectronica,代码行数:12,代码来源:FeCabecera.cs

示例14: JsonMessageSerializer_WhenUnderlyingMediumFails_ThrowsMessageException

        public void JsonMessageSerializer_WhenUnderlyingMediumFails_ThrowsMessageException() {
            // given
            IMessageTypeResolver resolver = new UnitTestMessageTypeResolver();
            TextWriter textWriter = new StringWriter();
            textWriter.Dispose(); // so stringwriter will throw ObjectDisposedException

            // when / then
            MessageTransferException exception =
                Assert.Throws<MessageTransferException>(
                    () => new JsonMessageSerializer(resolver, textWriter).SerializeMessage(new FakeMessage()));

            // then
            Assert.That(() => exception.InnerException, Is.InstanceOf<ObjectDisposedException>());
        }
开发者ID:julianpaulozzi,项目名称:EntityProfiler,代码行数:14,代码来源:JsonMessageSerializerTests.cs

示例15: FromObject

 public static string FromObject(object obj)
 {
     StringWriter textWriter = new StringWriter();
     JsonWriter jsonWriter = new JsonWriter(textWriter);
     JsonSerializer serializer = new JsonSerializer();
     LLUUIDConverter UUID = new LLUUIDConverter();
     serializer.Converters.Add(UUID);
     serializer.Serialize(jsonWriter, obj);
     jsonWriter.Flush();
     string text = textWriter.ToString();
     jsonWriter.Close();
     textWriter.Dispose();
     return text;
 }
开发者ID:cfire24,项目名称:ajaxlife,代码行数:14,代码来源:MakeJson.cs


注:本文中的System.IO.StringWriter.Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。