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


C# System.IO.StringWriter.GetStringBuilder方法代码示例

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


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

示例1: ProcessRequest

        public void ProcessRequest(HttpContext context)
        {
            DataBooks book=new DataBooks();
            book.name = context.Request["bookname"];
            book.type = context.Request["booktype"];
            if(book.name!=null)
                bookcollector.Add(book);

            context.Response.ContentType = "text/html";
            VelocityEngine vltEngine = new VelocityEngine();
            vltEngine.SetProperty(RuntimeConstants.RESOURCE_LOADER, "file");
            vltEngine.SetProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, System.Web.Hosting.HostingEnvironment.MapPath("~/templates"));//模板文件所在的文件夹
            vltEngine.Init();

            VelocityContext vltContext = new VelocityContext();

            //vltContext.Put("msg", "");
            vltContext.Put("bookcollector", bookcollector);
            vltContext.Put("book", book);

            Template vltTemplate = vltEngine.GetTemplate("Front/ShopingCar.html");//模版文件所在位置

            System.IO.StringWriter vltWriter = new System.IO.StringWriter();
            vltTemplate.Merge(vltContext, vltWriter);
            string html = vltWriter.GetStringBuilder().ToString();
            context.Response.Write(html);
        }
开发者ID:ujsxn,项目名称:UJSBookStore,代码行数:27,代码来源:ShopingCar.ashx.cs

示例2: GetString

        public string GetString(SparqlResultsFormat format, IRdfWriter graphWriter = null)
        {
            switch (ResultType)
            {
                case BrightstarSparqlResultsType.VariableBindings:
                case BrightstarSparqlResultsType.Boolean:
                    var stringWriter = new System.IO.StringWriter();
                    var sparqlXmlWriter = GetSparqlWriter(format); 
                    sparqlXmlWriter.Save(_resultSet, stringWriter);
                    return stringWriter.GetStringBuilder().ToString();
                case BrightstarSparqlResultsType.Graph:
                    if (graphWriter == null)
                    {
#if WINDOWS_PHONE
                        // Cannot use DTD because the mobile version of XmlWriter doesn't support writing a DOCTYPE.
                        graphWriter = new RdfXmlWriter(WriterCompressionLevel.High, false);
#else
                        graphWriter = new RdfXmlWriter();
#endif
                    }
                    return StringWriter.Write(_graph, graphWriter);
                default:
                    throw new BrightstarInternalException(
                        String.Format("Unrecognized result type when serializing results string: {0}",
                                      ResultType));
            }
        }
开发者ID:GTuritto,项目名称:BrightstarDB,代码行数:27,代码来源:BrightstarSparqlResultSet.cs

示例3: PostProcess

 /// <summary>Called when extension shall process generated code</summary>
 /// <param name="code">The code</param>
 /// <param name="provider">CodeDOM provider (the language)</param>
 /// <version version="1.5.3">Parameter <c>Provider</c> renamed to <c>provider</c></version>
 public void PostProcess(ref string code, CodeDomProvider provider)
 {
     System.IO.StringWriter tw = new System.IO.StringWriter();
     provider.GenerateCodeFromStatement(new CodeCommentStatement(FirtsLineOfAccessor), tw, new System.CodeDom.Compiler.CodeGeneratorOptions());
     string srch = tw.GetStringBuilder().ToString();
     if (srch.EndsWith("\r\n")) srch = srch.Substring(0, srch.Length - 2);
     else if (srch.EndsWith("\r") || srch.EndsWith("\n")) srch = srch.Substring(0, srch.Length - 1);
     tw = new System.IO.StringWriter();
     CodeTypeDeclaration foo = new CodeTypeDeclaration("foo");
     foo.CustomAttributes.Add(NewAttribute);
     provider.GenerateCodeFromType(foo, tw, new System.CodeDom.Compiler.CodeGeneratorOptions());
     string attr = new System.IO.StringReader(tw.GetStringBuilder().ToString()).ReadLine();
     System.IO.StringReader sr = new System.IO.StringReader(code);
     List<String> Lines = new List<string>();
     do {
         string line = sr.ReadLine();
         if (line == null) break;
         if (line.EndsWith(srch))
             Lines[Lines.Count - 1] = attr + "\r\n" + Lines[Lines.Count - 1];
         else
             Lines.Add(line);
     } while (true);
     System.Text.StringBuilder b = new System.Text.StringBuilder();
     foreach (string line in Lines)
         b.AppendLine(line);
     code = b.ToString();
 }
开发者ID:wskplho,项目名称:Tools,代码行数:31,代码来源:DebuggerStepThrough.cs

示例4: run

	public void run()
	{
		Exception exp = null;
		System.IO.StringReader sr = null;
		System.IO.StringWriter sw = null;

		try
		{
			BeginCase("ReadXml - DataSetOut");

			DataSet oDataset = new DataSet("DataSetOut");
			sw = new System.IO.StringWriter();
			oDataset.WriteXml(sw,System.Data.XmlWriteMode.WriteSchema);
			
			sr = new System.IO.StringReader(sw.GetStringBuilder().ToString());
			oDataset = new DataSet("DataSetOut");

			oDataset.ReadXml(sr);
			Compare(oDataset.Tables.Count ,0);
		}
		catch(Exception ex)	{exp = ex;}
		finally	
		{
			EndCase(exp);
			exp = null;
			sw.Close();
		}

	
	}
开发者ID:nlhepler,项目名称:mono,代码行数:30,代码来源:DataSet_WriteXml_TX.cs

示例5: RenderHtml

        /// <summary>
        /// 用data数据填充templateName模板,渲染生成html返回
        /// </summary>
        /// <param name="templateName"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public static string RenderHtml(string templateName, object data)
        {
            //第一步:Creating a VelocityEngine也就是创建一个VelocityEngine的实例
            VelocityEngine vltEngine = new VelocityEngine();   //也可以使用带参构造函数直接实例
            vltEngine.SetProperty(RuntimeConstants.RESOURCE_LOADER, "file");
            vltEngine.SetProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, System.Web.Hosting.HostingEnvironment.MapPath("~/templates"));//模板文件所在的文件夹
            vltEngine.Init();
            //vltEngine.AddProperty(RuntimeConstants.INPUT_ENCODING, "gb2312");
            //vltEngine.AddProperty(RuntimeConstants.OUTPUT_ENCODING, "gb2312");

            //第二步:Creating the Template加载模板文件
            //这时通过的是Template类,并使用VelocityEngine的GetTemplate方法加载模板
            Template vltTemplate = vltEngine.GetTemplate(templateName);

            //第三步:Merging the template整合模板
            VelocityContext vltContext = new VelocityContext();
            vltContext.Put("Data", data);//设置参数,在模板中可以通过$data来引用

            //第四步:创建一个IO流来输出模板内容推荐使用StringWriter(因为template中以string形式存放)
            System.IO.StringWriter vltWriter = new System.IO.StringWriter();
            vltTemplate.Merge(vltContext, vltWriter);

            string html = vltWriter.GetStringBuilder().ToString();
            return html;
        }
开发者ID:zhangtaoxgu,项目名称:aspnetProject,代码行数:31,代码来源:CommonHelper.cs

示例6: run

	public void run()
	{
		Exception exp = null;
	
		DataSet ds1 = new DataSet();
		ds1.Tables.Add(GHTUtils.DataProvider.CreateParentDataTable());
		ds1.Tables.Add(GHTUtils.DataProvider.CreateChildDataTable());

		//add data to check GH bug of DataSet.ReadXml of empty strings
		ds1.Tables[1].Rows.Add(new object[] {7,1,string.Empty,string.Empty,new DateTime(2000,1,1,0,0,0,0),35});
		ds1.Tables[1].Rows.Add(new object[] {7,2," ","		",new DateTime(2000,1,1,0,0,0,0),35});
		ds1.Tables[1].Rows.Add(new object[] {7,3,"","",new DateTime(2000,1,1,0,0,0,0),35});


		System.IO.StringWriter sw = new System.IO.StringWriter();
		//write xml file, data only
		ds1.WriteXml(sw);

		//copy both data and schema
		DataSet ds2 = ds1.Copy();
		//clear the data
		ds2.Clear();

		System.IO.StringReader sr = new System.IO.StringReader(sw.GetStringBuilder().ToString());
		ds2.ReadXml(sr);

		//check xml data
		try
		{
			BeginCase("ReadXml - Tables count");
			Compare(ds1.Tables.Count ,ds2.Tables.Count );
		}
		catch(Exception ex)	{exp = ex;}
		finally	{EndCase(exp); exp = null;}

		try
		{
			BeginCase("ReadXml - Table 1 row count");
			Compare(ds1.Tables[0].Rows.Count ,ds2.Tables[0].Rows.Count);
		}
		catch(Exception ex)	{exp = ex;}
		finally	{EndCase(exp); exp = null;}

		try
		{
			BeginCase("ReadXml - Table 2 row count");
			Compare(ds1.Tables[1].Rows.Count ,ds2.Tables[1].Rows.Count);
		}
		catch(Exception ex)	{exp = ex;}
		finally	{EndCase(exp); exp = null;}
		
		sr.Close();
		sw.Close();


	}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:56,代码来源:DataSet_ReadXml_T.cs

示例7: getPureView

        //GET PURE VIEW
        public object getPureView(string viewName)
        {
            var sw = new System.IO.StringWriter();
            var viewResult = ViewEngines.Engines.FindPartialView(ControllerContext, viewName);
            var viewContext = new ViewContext(ControllerContext, viewResult.View, ViewData, TempData, sw);
            viewResult.View.Render(viewContext, sw);
            viewResult.ViewEngine.ReleaseView(ControllerContext, viewResult.View);

            return sw.GetStringBuilder().ToString();
        }
开发者ID:saeidghoreshi,项目名称:partition1,代码行数:11,代码来源:HomeController.cs

示例8: RenderRazorViewToString

 public string RenderRazorViewToString(string viewName, object model, ControllerContext ControllerContext)
 {
     ViewData.Model = model;
     using (var sw = new System.IO.StringWriter())
     {
         var viewResult = ViewEngines.Engines.FindPartialView(ControllerContext, viewName);
         var viewContext = new ViewContext(ControllerContext, viewResult.View, ViewData, TempData, sw);
         viewResult.View.Render(viewContext, sw);
         viewResult.ViewEngine.ReleaseView(ControllerContext, viewResult.View);
         return sw.GetStringBuilder().ToString();
     }
 }
开发者ID:erkanAslanel,项目名称:titizOto,代码行数:12,代码来源:DbWithControllerWithMaster.cs

示例9: RenderPartialViewtoString

 public static string RenderPartialViewtoString(Controller controller, string view,object model)
 {
     controller.ViewData.Model = model;
     using (System.IO.StringWriter writer=new System.IO.StringWriter())
     {
         ViewEngineResult viewResult = ViewEngines.Engines.FindPartialView(controller.ControllerContext, view);
         ViewContext viewContext = new ViewContext(controller.ControllerContext, viewResult.View, controller.ViewData, controller.TempData, writer);
         viewResult.View.Render(viewContext, writer);
         viewResult.ViewEngine.ReleaseView(controller.ControllerContext, viewResult.View);
         return writer.GetStringBuilder().ToString();
     }
 }
开发者ID:joinabhimanyu,项目名称:MusicStoreApp,代码行数:12,代码来源:RenderHelper.cs

示例10: ViewToString

        public static string ViewToString(Controller controller, string viewName, object model)
        {
            controller.ViewData.Model = model;

            using (var sw = new System.IO.StringWriter())
            {
                var viewResult = ViewEngines.Engines.FindPartialView(controller.ControllerContext, viewName);
                var viewContext = new ViewContext(controller.ControllerContext, viewResult.View, controller.ViewData, controller.TempData, sw);
                viewResult.View.Render(viewContext, sw);
                viewResult.ViewEngine.ReleaseView(controller.ControllerContext, viewResult.View);

                return sw.GetStringBuilder().ToString();
            }
        }
开发者ID:rickeygalloway,项目名称:Test,代码行数:14,代码来源:ControllerHelper.cs

示例11: 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);
		}
开发者ID:emtees,项目名称:old-code,代码行数:15,代码来源:TestSearch.cs

示例12: readerHtml

        public static string readerHtml(string path, string name, object data)
        {
            VelocityEngine vltEngine = new VelocityEngine();
            vltEngine.SetProperty(RuntimeConstants.RESOURCE_LOADER, "file");
            vltEngine.SetProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, System.Web.Hosting.HostingEnvironment.MapPath(path));//模板文件所在的文件夹
            vltEngine.Init();

            VelocityContext vltContext = new VelocityContext();
            vltContext.Put("Data", data);//设置参数,在模板中可以通过$data来引用

            Template vltTemplate = vltEngine.GetTemplate(name);
            System.IO.StringWriter vltWriter = new System.IO.StringWriter();
            vltTemplate.Merge(vltContext, vltWriter);
            return vltWriter.GetStringBuilder().ToString();
        }
开发者ID:liuker0x007,项目名称:InfoSecPracticeSystem,代码行数:15,代码来源:writeHtml.cs

示例13: ProcessRequest

        public void ProcessRequest(HttpContext context)
        {
            string searchid= context.Request.Form["searchid"];
            string searchtext = context.Request.Form["searchtext"];
            dataaccess(searchid, searchtext);
            if (searchid == "2")
            {
                //book
                context.Response.ContentType = "text/html";
                VelocityEngine vltEngine = new VelocityEngine();
                vltEngine.SetProperty(RuntimeConstants.RESOURCE_LOADER, "file");
                vltEngine.SetProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, System.Web.Hosting.HostingEnvironment.MapPath("~/templates"));//模板文件所在的文件夹
                vltEngine.Init();
                VelocityContext vltContext = new VelocityContext();

                vltContext.Put("object", searchtext);
                string show="<img src='books/"+book.ser+"' width='210' height='150' />";
                vltContext.Put("result", show);

                Template vltTemplate = vltEngine.GetTemplate("Front/Search.html");//模版文件所在位置

                System.IO.StringWriter vltWriter = new System.IO.StringWriter();
                vltTemplate.Merge(vltContext, vltWriter);
                string html = vltWriter.GetStringBuilder().ToString();
                context.Response.Write(html);
            }
            else if (searchid == "3")
            {
                //news
                context.Response.ContentType = "text/html";
                VelocityEngine vltEngine = new VelocityEngine();
                vltEngine.SetProperty(RuntimeConstants.RESOURCE_LOADER, "file");
                vltEngine.SetProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, System.Web.Hosting.HostingEnvironment.MapPath("~/templates"));//模板文件所在的文件夹
                vltEngine.Init();

                VelocityContext vltContext = new VelocityContext();

                vltContext.Put("object", searchtext);
                vltContext.Put("result", news.news);

                Template vltTemplate = vltEngine.GetTemplate("Front/Search.html");//模版文件所在位置
                System.IO.StringWriter vltWriter = new System.IO.StringWriter();
                vltTemplate.Merge(vltContext, vltWriter);
                string html = vltWriter.GetStringBuilder().ToString();
                context.Response.Write(html);
            }
        }
开发者ID:ujsxn,项目名称:UJSBookStore,代码行数:47,代码来源:Search.ashx.cs

示例14: 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();
        }
开发者ID:biguoting,项目名称:MVCWebApplication,代码行数:23,代码来源:HomeController.cs

示例15: RenderPartialViewToString

        /// <summary>
        /// Method to generate the view as a HTML string.
        /// </summary>
        public string RenderPartialViewToString(string viewName, object model)
        {
            if (string.IsNullOrEmpty(viewName))
            {
                viewName = CurrentController.ControllerContext.RouteData.GetRequiredString("action");
            }

            CurrentController.ViewData.Model = model;

            using (System.IO.StringWriter sw = new System.IO.StringWriter())
            {
                ViewEngineResult viewResult = ViewEngines.Engines.FindPartialView(CurrentController.ControllerContext, viewName);
                ViewContext viewContext = new ViewContext(CurrentController.ControllerContext, viewResult.View, CurrentController.ViewData, CurrentController.TempData, sw);
                viewResult.View.Render(viewContext, sw);

                return sw.GetStringBuilder().ToString();
            }
        }
开发者ID:EpiCenterADC,项目名称:EPICenter,代码行数:21,代码来源:RenderHelper.cs


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