本文整理汇总了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 ();
}
示例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();
}
示例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);
}
示例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();
}
}
示例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();
}
}
}
示例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();
}
示例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();
}
示例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;
}
}
示例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);
}
}
}
示例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);
}
示例11: SetUpWriter
private void SetUpWriter()
{
sw = new StringWriter ();
xtw = new XmlTextWriter (sw);
xtw.QuoteChar = '\'';
xtw.Formatting = Formatting.None;
}
示例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;
}
示例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();
}
示例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