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


C# IO.StringWriter类代码示例

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


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

示例1: GetHtml

		public static string GetHtml (string url, HelpSource helpSource, out Node match)
		{
			string htmlContent = null;
			match = null;
			
			if (helpSource != null)
				htmlContent = AppDelegate.Root.RenderUrl (url, generator, out match, helpSource);
			if (htmlContent == null) {
				// the displayed url have a lower case type code (e.g. t: instead of T:) which confuse monodoc
				if (url.Length > 2 && url[1] == ':')
					url = char.ToUpperInvariant (url[0]) + url.Substring (1);
				// It may also be url encoded so decode it
				url = Uri.UnescapeDataString (url);
				htmlContent = AppDelegate.Root.RenderUrl (url, generator, out match, helpSource);
				if (htmlContent != null && match != null && match.Tree != null)
					helpSource = match.Tree.HelpSource;
			}
			if (htmlContent == null)
				return null;
			
			var html = new StringWriter ();
   			html.Write ("<html>\n<head><title>{0}</title>", url);
			
			if (helpSource != null) {
				if (HtmlGenerator.InlineCss != null)
                    html.Write (" <style type=\"text/css\">{0}</style>\n", HtmlGenerator.InlineCss);
				/*if (helpSource.InlineJavaScript != null)
                    html.Write ("<script type=\"text/JavaScript\">{0}</script>\n", helpSource.InlineJavaScript);*/
            }

            html.Write ("</head><body>");
            html.Write (htmlContent);
            html.Write ("</body></html>\n");
            return html.ToString ();
		}
开发者ID:Anomalous-Software,项目名称:monomac,代码行数:35,代码来源:DocTools.cs

示例2: ObjetoSerializado

 public static string ObjetoSerializado(Object Objeto)
 {
     System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(Objeto.GetType());
     System.IO.StringWriter textWriter = new System.IO.StringWriter();
     x.Serialize(textWriter, Objeto);
     return textWriter.ToString();
 }
开发者ID:pjeconde,项目名称:CedServicios,代码行数:7,代码来源:Funciones.cs

示例3: NormalSectionAndKey

        public void NormalSectionAndKey() {
            StringWriter writer = new StringWriter();
            writer.WriteLine("[Logging]");
            writer.WriteLine(" great logger =   log4net  ");
            writer.WriteLine("  [Pets] ; pets comment  ");
            IniReader reader = new IniReader(new StringReader(writer.ToString()));

            Assert.AreEqual(IniReadState.Initial, reader.ReadState);
            Assert.IsTrue(reader.Read());
            Assert.AreEqual(IniReadState.Interactive, reader.ReadState);
            Assert.AreEqual(IniType.Section, reader.Type);
            Assert.AreEqual("Logging", reader.Name);
            Assert.AreEqual("", reader.Value);
            Assert.IsNull(reader.Comment);

            Assert.IsTrue(reader.Read());
            Assert.AreEqual(IniType.Key, reader.Type);
            Assert.AreEqual("great logger", reader.Name);
            Assert.AreEqual("log4net", reader.Value);
            Assert.AreEqual(null, reader.Comment);

            Assert.IsTrue(reader.Read());
            Assert.AreEqual(IniType.Section, reader.Type);
            Assert.AreEqual("Pets", reader.Name);
            Assert.AreEqual("", reader.Value);
            Assert.IsNull(reader.Comment);
        }
开发者ID:debop,项目名称:NFramework,代码行数:27,代码来源:IniReaderTests.cs

示例4: InjectAssets

        protected string InjectAssets(string markup, Match match)
        {
            if (match == null)
            {
                return markup;
            }

            using (var writer = new StringWriter())
            {
                writer.Write(markup.Substring(0, match.Index));

                WriteLinks(writer, @"<link type=""text/css"" rel=""stylesheet"" href=""{0}"" />",
                           Compressor.CompressCss(GetSources(CssLinks)));
                WriteInlines(writer, "<style>", "</style>", CssInlines);
                WriteLinks(writer, @"<script type=""text/javascript"" src=""{0}""></script>",
                           Compressor.CompressJavascript(GetSources(JavascriptLinks)));
                WriteInlines(writer, @"<script type=""text/javascript"">", "</script>", JavascriptInlines);

                WriteInlines(
                    writer,
                    @"<script type=""text/javascript"">jQuery(document).ready(function () {",
                    "});</script>",
                    DomReadyInlines);

                writer.Write(markup.Substring(match.Index));
                return writer.ToString();
            }
        }
开发者ID:jlarsson,项目名称:MvcAssets,代码行数:28,代码来源:AssetsInjectorBase.cs

示例5: ParsedArguments

        public ParsedArguments(string[] args) {
            var p = new OptionSet {
                {"sum", "If set Sum will be calculated", _ => _SumValues = true},
                {"max", "If set show Max value", _ => _MaxValue = true},
                {"min", "If set show Min value", _ => _MinValue = true},
                {"dir=", "Output directory", dir => _OutputDirectory = GetValidPath(dir)}, {
                    "count=", "Count of items to be generated. This value is mandatory.", count => {
                        if (!_CountIsSet && int.TryParse(count, out _Count) && _Count > 0) {
                            _CountIsSet = true;
                        }
                    }
                }
            };

            p.Parse(args);

            if (!ArgsAreValid) {
                Trace.WriteLine("Parameter args does not contain valid value for count.");

                using (var stringWriter = new StringWriter()) {
                    p.WriteOptionDescriptions(stringWriter);
                    _ErrorMessage = stringWriter.ToString();
                }
            }
        }
开发者ID:matafonoff,项目名称:Brokeree.Test,代码行数:25,代码来源:ParsedArguments.cs

示例6: Boton_Excel_Dios_Click

        protected void Boton_Excel_Dios_Click(object sender, EventArgs e)
        {
            StringBuilder sb = new StringBuilder();
            StringWriter sw = new StringWriter(sb);
            HtmlTextWriter htw = new HtmlTextWriter(sw);

            Page page = new Page();
            HtmlForm form = new HtmlForm();
            GridView_Dios.DataSourceID = string.Empty;
            GridView_Dios.EnableViewState = false;
            GridView_Dios.AllowPaging = false;
            GridView_Dios.DataSource = LBPD.Logica_Mostrar_Precios();
            GridView_Dios.DataBind();
            page.EnableEventValidation = false;
            page.DesignerInitialize();
            page.Controls.Add(form);
            form.Controls.Add(GridView_Dios);
            page.RenderControl(htw);
            Response.Clear();
            Response.Buffer = true;
            Response.ContentType = "applicattion/vnd.ms-excel";
            Response.AddHeader("Content-Disposition", "attachment;filename=data.xls");
            Response.Charset = "UTF-8";
            Response.ContentEncoding = Encoding.Default;
            Response.Write(sb.ToString());
            Response.End();
        }
开发者ID:Gutylic,项目名称:Proyecto-Alfa,代码行数:27,代码来源:Precios_Dios.aspx.cs

示例7: PrimitiveLiteral

 /// <summary>
 /// Returns the C# literal representation of a given primitive expression.
 /// (Useful for escaping strings)
 /// </summary>
 private static string PrimitiveLiteral(this string input)
 {
     var writer = new StringWriter();
     var provider = new CSharpCodeProvider();
     provider.GenerateCodeFromExpression(new CodePrimitiveExpression(input), writer, null);
     return writer.ToString();
 }
开发者ID:ChrisFulstow,项目名称:CSharpCodeGen,代码行数:11,代码来源:CodeGenerator.cs

示例8: HtmlToWord

        /// <summary>
        /// html标签导出到word
        /// </summary>
        /// <param name="html"></param>
        /// <param name="fileName">带后缀</param>
        /// <param name="IsWord2003"></param>
        /// <param name="ext"></param>
        public static void HtmlToWord(string html, string fileName, bool IsWord2003 = true)
        {
            try
            {
                HttpResponse response = System.Web.HttpContext.Current.Response;
                response.Clear();
                response.Buffer = false;
                response.Charset = "GB2312";
                response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fileName, Encoding.UTF8));
                response.ContentEncoding = Encoding.GetEncoding("GB2312");

                response.ContentType = IsWord2003 ? "application/ms-word" : "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
                //response.ContentType = "application/octet-stream";

                CultureInfo formatProvider = new CultureInfo("zh-CN", true);
                StringWriter writer = new StringWriter(formatProvider);

                response.Write(html);

                response.End();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
开发者ID:zhanglc8801,项目名称:WKT2015,代码行数:33,代码来源:RenderToWord.cs

示例9: ProcessRecord

        /// <summary>
        /// Processes the record.
        /// </summary>
        protected override void ProcessRecord()
        {
            this.WriteVerbose("Formatting log");
            using (var xmlReader = new StringReader(this.Log))
            {
                var xpath = new XPathDocument(xmlReader);
                using (var writer = new StringWriter())
                {
                    var transform = new XslCompiledTransform();
                    Func<string, string> selector = file => !Path.IsPathRooted(file) ? Path.Combine(Environment.CurrentDirectory, file) : file;
                    foreach (var fileToLoad in this.FormatFile.Select(selector))
                    {
                        this.WriteVerbose("Loading format file " + fileToLoad);
                        using (var stream = File.OpenRead(fileToLoad))
                        {
                            using (var reader = XmlReader.Create(stream))
                            {
                                transform.Load(reader);
                                transform.Transform(xpath, null, writer);
                            }
                        }
                    }

                    this.WriteObject(writer.GetStringBuilder().ToString(), false);
                }
            }
        }
开发者ID:kascomp,项目名称:CruiseControl.NET,代码行数:30,代码来源:FormatLog.cs

示例10: Invoke

		public bool Invoke(string[] args)
		{
			output = new StringWriter ();
			method_arg [0] = args;
			method_arg [1] = output;
			return (bool)ep.Invoke (null, method_arg);
		}
开发者ID:jakesays,项目名称:mono,代码行数:7,代码来源:compiler-tester.cs

示例11: SetUpWriter

		private void SetUpWriter()
		{
			sw = new StringWriter ();
			xtw = new XmlTextWriter (sw);
			xtw.QuoteChar = '\'';
			xtw.Formatting = Formatting.None;
		}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:7,代码来源:XmlSerializerTests.cs

示例12: GetCommands

 public static CoordinateCommand[] GetCommands(StringWriter trace)
 {
     return new[]
 {
     new CoordinateCommand(trace)    
 };
 }
开发者ID:lavige777,项目名称:ManyConsole,代码行数:7,代码来源:Multiple_dispatch_calls_dont_interfere_with_each_other.cs

示例13: UpdateOutputLogCommand

 private UpdateOutputLogCommand(IStorageBlockBlob outputBlob, Func<string, CancellationToken, Task> uploadCommand)
 {
     _outputBlob = outputBlob;
     _innerWriter = new StringWriter(CultureInfo.InvariantCulture);
     _synchronizedWriter = TextWriter.Synchronized(_innerWriter);
     _uploadCommand = uploadCommand;
 }
开发者ID:jonkelling,项目名称:azure-webjobs-sdk,代码行数:7,代码来源:UpdateOutputLogCommand.cs

示例14: btnExcel_Click

        protected void btnExcel_Click(object sender, EventArgs e)
        {
            //Create a dummy GridView
            GridView GridView1 = new GridView();
            GridView1.AllowPaging = false;
            GridView1.DataSource = BindGridView();
            GridView1.DataBind();

            Response.Clear();
            Response.Buffer = true;
            Response.AddHeader("content-disposition",
             "attachment;filename=" + DateTime.Now.Year + "-Newly_Hired" + ".xls");
            Response.Charset = "";
            Response.ContentType = "application/vnd.ms-excel";
            StringWriter sw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(sw);

            for (int i = 0; i < GridView1.Rows.Count; i++)
            {
                //Apply text style to each Row
                GridView1.Rows[i].Attributes.Add("class", "textmode");
            }
            GridView1.RenderControl(hw);

            //style to format numbers to string
            string style = @"<style> .textmode { mso-number-format:\@; } </style>";
            Response.Write(style);
            Response.Output.Write(sw.ToString());
            Response.Flush();
            Response.End();
        }
开发者ID:ismaeljaycarpio,项目名称:vs2013,代码行数:31,代码来源:NewlyHired.aspx.cs

示例15: Specify

        public override void Specify()
        {
            when("repeatedly dispatching a command", delegate
            {
                var trace = new StringWriter();

                arrange(delegate
                {
                    ConsoleCommandDispatcher.DispatchCommand(SomeProgram.GetCommands(trace), new[] { "move", "-x", "1", "-y", "2" }, new StringWriter());
                    ConsoleCommandDispatcher.DispatchCommand(SomeProgram.GetCommands(trace), new[] { "move", "-x", "3" }, new StringWriter());
                    ConsoleCommandDispatcher.DispatchCommand(SomeProgram.GetCommands(trace), new[] { "move", "-y", "4" }, new StringWriter());
                    ConsoleCommandDispatcher.DispatchCommand(SomeProgram.GetCommands(trace), new[] { "move" }, new StringWriter());
                });

                then("all parameters are evaluated independently", delegate
                {
                    Expect.That(trace.ToString()).ContainsInOrder(
                            "You walk to 1, 2 and find a maze of twisty little passages, all alike.",
                            "You walk to 3, 0 and find a maze of twisty little passages, all alike.",
                            "You walk to 0, 4 and find a maze of twisty little passages, all alike.",
                            "You walk to 0, 0 and find a maze of twisty little passages, all alike."
                        );
                });
            });
        }
开发者ID:lavige777,项目名称:ManyConsole,代码行数:25,代码来源:Multiple_dispatch_calls_dont_interfere_with_each_other.cs


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