本文整理汇总了C#中System.IO.StringWriter.Close方法的典型用法代码示例。如果您正苦于以下问题:C# System.IO.StringWriter.Close方法的具体用法?C# System.IO.StringWriter.Close怎么用?C# System.IO.StringWriter.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.StringWriter
的用法示例。
在下文中一共展示了System.IO.StringWriter.Close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestSearch_
public virtual void TestSearch_()
{
System.IO.StringWriter sw = new System.IO.StringWriter();
DoTestSearch(sw, false);
sw.Close();
System.String multiFileOutput = sw.GetStringBuilder().ToString();
//System.out.println(multiFileOutput);
sw = new System.IO.StringWriter();
DoTestSearch(sw, true);
sw.Close();
System.String singleFileOutput = sw.GetStringBuilder().ToString();
Assert.AreEqual(multiFileOutput, singleFileOutput);
}
示例2: GengerCode
public string GengerCode(CodeNamespace nspace)
{
StringBuilder sb = new StringBuilder();
System.IO.StringWriter sw = new System.IO.StringWriter(sb);
CodeGeneratorOptions geneOptions = new CodeGeneratorOptions();//代码生成选项
geneOptions.BlankLinesBetweenMembers = false;
geneOptions.BracingStyle = "C";
geneOptions.ElseOnClosing = true;
geneOptions.IndentString = " ";
CodeDomProvider.GetCompilerInfo("c++").CreateProvider().GenerateCodeFromNamespace(nspace, sw, geneOptions);//代码生成
sw.Close();
return sb.ToString();
}
示例3: getParseResult
/// <summary>
/// ajax method for demo of parsing NVelocity Temp with VelocityEngine
/// </summary>
/// <param name="template"></param>
/// <param name="dirctionary"></param>
public void getParseResult(string template,string dirctionary)
{
if ((template == null) || (dirctionary == null))
{
CancelView();
return;
}
var map=Newtonsoft.Json.JavaScriptConvert.DeserializeObject<Hashtable>(dirctionary);
var writer = new System.IO.StringWriter();
var nve = new NVelocity.App.VelocityEngine();
nve.Init();
var context = new NVelocity.VelocityContext(map);
nve.Evaluate(context, writer, "", template);
RenderText(writer.GetStringBuilder().ToString());
writer.Close();
CancelView();
}
示例4: WriteValuesToXml
public string WriteValuesToXml()
{
string result = string.Empty;
XmlSerializer xs = new XmlSerializer(typeof(Collection<UserQuestionOption>));
System.IO.StringWriter sw = new System.IO.StringWriter();
try
{
xs.Serialize(sw, this.Values);
result = sw.ToString();
}
finally
{
sw.Close();
}
return result;
}
示例5: ToString
public override string ToString()
{
var sw = new System.IO.StringWriter();
using (XmlTextWriter writer = new XmlTextWriter(sw))
{
writer.Formatting = Formatting.Indented;
writer.Indentation = 4;
writer.WriteStartElement("Step");
writer.WriteElementString("Enable", Enable.ToString());
writer.WriteElementString("Comment", Comment);
writer.WriteElementString("OnFailureLable", OnFailureLabel);
writer.WriteRaw(Action.ToString());
writer.WriteEndElement();
}
string retval = sw.ToString();
sw.Close();
sw.Dispose();
return retval;
}
示例6: ToString
public override string ToString()
{
var sw = new System.IO.StringWriter();
using (var writer = new XmlTextWriter(sw))
{
writer.Formatting = Formatting.Indented;
writer.Indentation = 4;
writer.WriteStartElement("Action");
writer.WriteElementString("ID", ((int)TypeId).ToString());
writer.WriteElementString("Name", Name);
writer.WriteStartElement("Details");
foreach (string data in Details)
writer.WriteElementString("Detail", data);
writer.WriteEndElement();
writer.WriteEndElement();
}
string retval = sw.ToString();
sw.Close();
sw.Dispose();
return retval;
}
示例7: ToString
public override string ToString()
{
var sw = new System.IO.StringWriter();
using (XmlTextWriter writer = new XmlTextWriter(sw))
{
writer.Formatting = Formatting.Indented;
writer.Indentation = 4;
writer.WriteStartDocument();
writer.WriteStartElement("Test");
//writer.WriteElementString("Enable", Enable.ToString());
writer.WriteElementString("Description", Description);
writer.WriteStartElement("Scripts");
foreach (TestEntity entity in Entities)
writer.WriteRaw(entity.ToString());
writer.WriteEndElement();
writer.WriteEndElement();
writer.WriteEndDocument();
}
string retval = sw.ToString().Replace("utf-16", "utf-8"); ;
sw.Close();
sw.Dispose();
return retval;
}
示例8: ConvertToGpx
public static string ConvertToGpx(Track track)
{
gpx.gpxType gpx = new gpx.gpxType();
gpx.creator = track.VehicleName;
gpx.metadata = new global::gpx.metadataType();
gpx.metadata.time = track.StartTime.HasValue ? DateTime.MinValue : track.StartTime.Value;
gpx.metadata.timeSpecified = track.StartTime.HasValue;
using (var rep = ServiceProvider.GetService<IRepositoryFactory>().GenerateRepository<TrackPoint>())
{
rep.Attach(track);
gpx.trk = new gpx.trkType[1];
gpx.trk[0] = new global::gpx.trkType();
gpx.trk[0].number = "1";
gpx.trk[0].trkseg = new gpx.trksegType[1];
gpx.trk[0].trkseg[0] = new global::gpx.trksegType();
gpx.trk[0].trkseg[0].trkpt = new gpx.wptType[track.TrackPoints.Count];
for(int i=0; i<track.TrackPoints.Count; ++i)
{
gpx.trk[0].trkseg[0].trkpt[i] = new global::gpx.wptType();
gpx.trk[0].trkseg[0].trkpt[i].ele = (decimal)track.TrackPoints[i].Altitude;
gpx.trk[0].trkseg[0].trkpt[i].eleSpecified = true;
gpx.trk[0].trkseg[0].trkpt[i].lat = (decimal)track.TrackPoints[i].Latitude;
gpx.trk[0].trkseg[0].trkpt[i].lon = (decimal)track.TrackPoints[i].Longitude;
gpx.trk[0].trkseg[0].trkpt[i].time = track.TrackPoints[i].GpsTime;
gpx.trk[0].trkseg[0].trkpt[i].timeSpecified = true;
gpx.trk[0].trkseg[0].trkpt[i].magvar = (decimal)track.TrackPoints[i].Heading;
gpx.trk[0].trkseg[0].trkpt[i].magvarSpecified = true;
}
}
var xmlSerialize = new System.Xml.Serialization.XmlSerializer(typeof(gpx.gpxType));
var stream = new System.IO.StringWriter();
xmlSerialize.Serialize(stream, gpx);
stream.Close();
return stream.ToString();
}
示例9: getDebugInfo
public string getDebugInfo()
{
System.IO.StringWriter outfile = new System.IO.StringWriter();
string name = "";
outfile.WriteLine("PES header");
outfile.WriteLine("PES version:\t" + pesVersion);
for (int i = 0; i < pesHeader.Count; i++)
{
name = (i + 1).ToString();
outfile.WriteLine(name + "\t" + pesHeader[i].ToString());
}
if (embOneHeader.Count > 0)
{
outfile.WriteLine("CEmbOne header");
for (int i = 0; i < embOneHeader.Count; i++)
{
switch (i + 1)
{
case 22:
name = "translate x";
break;
case 23:
name = "translate y";
break;
case 24:
name = "width";
break;
case 25:
name = "height";
break;
default:
name = (i + 1).ToString();
break;
}
outfile.WriteLine(name + "\t" + embOneHeader[i].ToString());
}
}
if (embPunchHeader.Count > 0)
{
outfile.WriteLine("CEmbPunch header");
for (int i = 0; i < embPunchHeader.Count; i++)
{
switch (i + 1)
{
default:
name = (i + 1).ToString();
break;
}
outfile.WriteLine(name + "\t" + embPunchHeader[i].ToString());
}
}
outfile.WriteLine("stitches start: " + startStitches.ToString());
outfile.WriteLine("block info");
outfile.WriteLine("number\tcolor\tstitches");
for (int i = 0; i < this.blocks.Count; i++)
{
outfile.WriteLine((i + 1).ToString() + "\t" + blocks[i].colorIndex.ToString() + "\t" + blocks[i].stitchesTotal.ToString());
}
outfile.WriteLine("color table");
outfile.WriteLine("number\ta\tb");
for (int i = 0; i < colorTable.Count; i++)
{
outfile.WriteLine((i + 1).ToString() + "\t" + colorTable[i].a.ToString() + ", " + colorTable[i].b.ToString());
}
if (blocks.Count > 0)
{
outfile.WriteLine("Extended stitch debug info");
for (int blocky = 0; blocky < blocks.Count; blocky++)
{
outfile.WriteLine("block " + (blocky + 1).ToString() + " start");
for (int stitchy = 0; stitchy < blocks[blocky].stitches.Length; stitchy++)
{
outfile.WriteLine(blocks[blocky].stitches[stitchy].X.ToString() + ", " + blocks[blocky].stitches[stitchy].Y.ToString());
}
}
}
outfile.Close();
return outfile.ToString();
}
示例10: GetSearchView
public string GetSearchView(SearchGroup searchGroup)
{
var page = new System.Web.UI.Page();
var oSearchView = (SearchView) LoadControl(PathProvider.GetControlVirtualPath("SearchView.ascx"));
oSearchView.SearchGroup = searchGroup;
oSearchView.IsListView = ProjectID == -1;
oSearchView.SearchText = SearchText;
page.Controls.Add(oSearchView);
var writer = new System.IO.StringWriter();
HttpContext.Current.Server.Execute(page, writer, false);
var output = writer.ToString();
writer.Close();
return output;
}
示例11: SaveXml
public static string SaveXml( XmlDocument doc, bool prettyPrint )
{
System.IO.StringWriter strwriter = new System.IO.StringWriter();
XmlTextWriter writer = new XmlTextWriter( strwriter );
if( prettyPrint )
{
writer.Formatting = Formatting.Indented;
writer.IndentChar = '\t';
writer.Indentation = 1;
}
else
writer.Formatting = Formatting.None;
doc.Save( writer );
writer.Close();
strwriter.Close();
return strwriter.ToString();
}
示例12: replaceSpecialXmlChars
/// <summary>
/// Replaces special characters in strings.
/// </summary>
/// <remarks>
/// * Behaves like XmlTextWriter.WriteString(), but also replaces
/// the apostrophe and double-quote characters -- which WriteString()
/// does not, unless it is in an attribute context...
///
/// * PERFORMANCE NOTE: About 2.5 s slower than old method over the course
/// of 1 million runs. TBD see if there is a good way for us to reuse
/// the StringWriter and XmlTextWriter so that we don't have to keep
/// recreating them. Maybe a factory method?
/// </remarks>
/// <param name="s"></param>
/// <returns></returns>
public static string replaceSpecialXmlChars(string s)
{
// this takes care of all of the characters except ' and " because
// we are not processing within the context of an attribute
//
System.IO.StringWriter stringWriter = new System.IO.StringWriter();
using (XmlWriter writer = new XmlTextWriter(stringWriter))
{
writer.WriteString(s);
stringWriter.Close();
writer.Close();
}
string result = stringWriter.ToString();
result = result.Replace("\"", """);
result = result.Replace("'", "'");
return result;
}
示例13: PrintProductIDBarcode
public void PrintProductIDBarcode(int ProductIDSysNo)
{
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment; filename=po.txt");
HttpContext.Current.Response.Charset = "GB2312";
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
HttpContext.Current.Response.ContentType = "application/vnd.ms-txt";
System.IO.StringWriter tw = new System.IO.StringWriter();
string sql = "select p_i.productsysno,i_s.position1 from product_id p_i inner join po_master po on p_i.posysno=po.sysno inner join inventory_stock i_s on po.stocksysno=i_s.stocksysno and p_i.productsysno=i_s.productsysno where p_i.sysno = " + ProductIDSysNo;
DataSet ds = SqlHelper.ExecuteDataSet(sql);
if (!Util.HasMoreRow(ds))
return;
string sLine = "\"ID\",\"ProductID\",\"Quantity\",\"StockNo\"";
tw.WriteLine(sLine);
sLine = "\"" + 1 + "\",\"" + Util.TrimNull(ds.Tables[0].Rows[0]["productsysno"]) + "_" + ProductIDSysNo + "\",\"1\",\"" + Util.TrimNull(ds.Tables[0].Rows[0]["position1"]) + "\"";
tw.WriteLine(sLine);
tw.Flush();
tw.Close();
HttpContext.Current.Response.Write(tw.ToString()); //Write the HTML back to the browser.
HttpContext.Current.Response.End();
}
示例14: SavePageStateToPersistenceMedium
/// <summary>
///
/// </summary>
/// <param name="state"></param>
protected override void SavePageStateToPersistenceMedium(object state)
{
try
{
LosFormatter los = new LosFormatter();
System.IO.StringWriter sw = new System.IO.StringWriter();
this.Session[("\'" + (Session.SessionID + "\'"))] = String.Empty;
los.Serialize(sw, state);
this.Session[("\'" + (Session.SessionID + "\'"))] = sw.ToString();
sw.Close();
}
catch (Exception ex)
{
throw ex;
}
}
示例15: RegisterExportClientScript
private void RegisterExportClientScript()
{
//this javascript will get executed CLIENT-SIDE when the Export button is clicked
Page.ClientScript.RegisterHiddenField(EXPORT_HIDDENFIELD_NAME, string.Empty);
string scriptBlockName = "_kh_ExportGridToExcel";
System.IO.StringWriter scriptBlock = new System.IO.StringWriter();
scriptBlock.WriteLine("function SaveGrid()");
scriptBlock.WriteLine("{");
scriptBlock.WriteLine(" var hf = document.getElementById('{0}');", EXPORT_HIDDENFIELD_NAME);
scriptBlock.WriteLine(" var grd = document.getElementById('{0}');", grdList.ClientID);
scriptBlock.WriteLine(" if (grd && hf)");
scriptBlock.WriteLine(" { ");
scriptBlock.WriteLine(" var htmlarray = grd.outerHTML.split(\"\\n\");");
scriptBlock.WriteLine(" var htmlOutput = '';");
scriptBlock.WriteLine(" for (i = 0;i < htmlarray.length;i++)");
scriptBlock.WriteLine(" {");
scriptBlock.WriteLine(" var hasCheckBoxHeader = htmlarray[i].indexOf('<TH style=\"WIDTH: 50px\" scope=col>Select</TH>') != -1");
scriptBlock.WriteLine(" var hasBtnHeader = htmlarray[i].indexOf('<TH style=\"WIDTH: 60px\" scope=col> </TH>') != -1");
scriptBlock.WriteLine(" var hasCheckBox = htmlarray[i].indexOf('type=checkbox') != -1");
scriptBlock.WriteLine(" var hasBtn = htmlarray[i].indexOf('href=\"javascript:__doPostBack') != -1");
scriptBlock.WriteLine(" if (!hasCheckBoxHeader && !hasBtnHeader && !hasCheckBox && !hasBtn)");
scriptBlock.WriteLine(" {");
scriptBlock.WriteLine(" htmlOutput = htmlOutput + htmlarray[i] + \"\\n\"");
scriptBlock.WriteLine(" }");
scriptBlock.WriteLine(" }");
scriptBlock.WriteLine(" hf.value = htmlOutput.replace('style=\"HEIGHT: 0px\"','').replace('border=1','border=0');"); //fixes minor formatting issues in Excel
scriptBlock.WriteLine(" return true;");
scriptBlock.WriteLine(" } ");
scriptBlock.WriteLine(" else");
scriptBlock.WriteLine(" return false;");
scriptBlock.WriteLine("}");
if (!ClientScript.IsClientScriptBlockRegistered(scriptBlockName))
ClientScript.RegisterClientScriptBlock(this.GetType(), scriptBlockName, scriptBlock.ToString(), true);
scriptBlock.Close();
}