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


C# StringWriter.GetStringBuilder方法代码示例

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


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

示例1: Main

	static int Main ()
	{
		TinyHost h = CreateHost ();
		StringWriter sw = new StringWriter ();
		h.Execute ("Index1.aspx", sw);
		string result = sw.ToString ();
		if (result != "<html></html>") {
			Console.WriteLine (result);
			return 1;
		}

		sw.GetStringBuilder ().Length = 0;
		h = CreateHost ();
		h.Execute ("Index2.aspx", sw);
		result = sw.ToString ();
		if (result != "<html><fckeditorv2:whatever /></html>") {
			Console.WriteLine (result);
			return 2;
		}

		sw.GetStringBuilder ().Length = 0;
		h = CreateHost ();
		h.Execute ("Index3.aspx", sw);
		result = sw.ToString ();
		if (result.IndexOf ("Does.Not.Exist") == -1) {
			Console.WriteLine (result);
			return 3;
		}
		return 0;
	}
开发者ID:mono,项目名称:gert,代码行数:30,代码来源:test.cs

示例2: runTest

	public bool runTest()
	{
		int iCountErrors = 0;
		int iCountTestcases = 0;
        String strTemp = String.Empty ;
        Char[] cArr = new Char[10] ;
        StringBuilder sb = new StringBuilder(40);
        StringWriter sw = new StringWriter(sb);
        StringReader sr;
        iCountTestcases++;
        bool[] bArr = new bool[]{  true,true,true,true,true,false,false,false,false,false};
		try {
			for(int i = 0 ; i < bArr.Length ; i++)
				sw.WriteLine(bArr[i]);
			sr = new StringReader(sw.GetStringBuilder().ToString());
			for(int i = 0 ; i < bArr.Length ; i++) {
                sr.Read(cArr, 0, bArr[i].ToString().Length+System.Environment.NewLine.Length);
				if(new String(cArr, 0, bArr[i].ToString().Length) != bArr[i].ToString()) {
					iCountErrors++;
					printerr( "Error_298vc_"+i+"! Expected=="+bArr[i].ToString()+", got=="+new String(cArr));
				}
			}
		} catch (Exception exc) {
			iCountErrors++;
			printerr( "Error_298yg! Unexpected exception thrown, exc=="+exc.ToString());
		}
        iCountTestcases++;
        bArr = new bool[10000];
        for(int i = 0 ; i < bArr.Length ; i++)
            bArr[i] = Convert.ToBoolean(rand.Next(0,2));
		try {
            sb.Length = 0;
			for(int i = 0 ; i < bArr.Length ; i++)
				sw.WriteLine(bArr[i]);
			sr = new StringReader(sw.GetStringBuilder().ToString());
			for(int i = 0 ; i < bArr.Length ; i++) {
                sr.Read(cArr, 0, bArr[i].ToString().Length+System.Environment.NewLine.Length);
                if(new String(cArr, 0, bArr[i].ToString().Length) != bArr[i].ToString()) {
					iCountErrors++;
					printerr( "Error_57485_"+i+"! Expected=="+bArr[i].ToString()+", got=="+new String(cArr));
				}
			}
		} catch (Exception exc) {
			iCountErrors++;
			printerr( "Error_43432! Unexpected exception thrown, exc=="+exc.ToString());
		}
        if ( iCountErrors == 0 )
		{
			Console.WriteLine( "paSs. iCountTestcases=="+iCountTestcases.ToString());
			return true;
		}
		else
		{
			Console.WriteLine("FAiL! iCountErrors=="+iCountErrors.ToString() );
			return false;
		}
	}
开发者ID:ArildF,项目名称:masters,代码行数:57,代码来源:co9402writeline_bool.cs

示例3: Main

	static int Main ()
	{
		string webDir = Path.Combine (AppDomain.CurrentDomain.BaseDirectory,
			"web");
		string appCodeDir = Path.Combine (webDir, "App_Code");
		string invalidSourceFile = Path.Combine (appCodeDir, "invalid.cs");
		string invalidConfigFile = Path.Combine (webDir, "Web.config");

		Directory.CreateDirectory (appCodeDir);
		File.Delete (invalidSourceFile);
		File.Delete (invalidConfigFile);

		using (StreamWriter w = File.CreateText (invalidConfigFile)) {
			w.WriteLine ("INVALIDXML");
		}

		TinyHost h = CreateHost ();
		StringWriter sw = new StringWriter ();
		h.Execute ("Default.aspx", sw);
		string result = sw.ToString ();
		if (result == "bug81127") {
			Console.WriteLine (result);
			return 1;
		}

		sw.GetStringBuilder ().Length = 0;
		h.Execute ("~/Doc/Default.aspx", sw);
		result = sw.ToString ();
		if (result == "bug81127") {
			Console.WriteLine (result);
			return 2;
		}

		return 0;
	}
开发者ID:mono,项目名称:gert,代码行数:35,代码来源:test3.cs

示例4: runTest

	public bool runTest()
	{
		Console.WriteLine(s_strTFPath + "\\" + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
		int iCountErrors = 0;
		int iCountTestcases = 0;
		String strValue = String.Empty;
		try {
			StringBuilder sb = new StringBuilder(40);
			StringWriter sw = new StringWriter(sb);
			sw.Write(4);
			sb = sw.GetStringBuilder();
			iCountTestcases++;
			if(!sb.ToString().Equals("4")) {
				iCountErrors++;
				printerr( "Error_298vc! Unexpected value written, sb=="+sb.ToString());
			}
		} catch (Exception exc) {
			iCountErrors++;
			printerr( "Error_298yg! Unexpected exception thrown, exc=="+exc.ToString());
		}
		if ( iCountErrors == 0 )
		{
			Console.WriteLine( "paSs. "+s_strTFName+" ,iCountTestcases=="+iCountTestcases.ToString());
			return true;
		}
		else
		{
			Console.WriteLine("FAiL! "+s_strTFName+" ,iCountErrors=="+iCountErrors.ToString()+" , BugNums?: "+s_strActiveBugNums );
			return false;
		}
	}
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:31,代码来源:co5556ctor_sb.cs

示例5: RenderPartialViewToString

    /// <summary>
    /// Renders the specified partial view to a string.
    /// </summary>
    /// <param name="viewName">The name of the partial view.</param>
    /// <param name="model">The model.</param>
    /// <returns>The partial view as a string.</returns>
    protected string RenderPartialViewToString(string viewName, object model)
    {
        if (string.IsNullOrEmpty(viewName))
        {
            viewName = ControllerContext.RouteData.GetRequiredString("action");
        }

        ViewData.Model = model;

        using (var sw = new StringWriter())
        {
            // Find the partial view by its name and the current controller context.
            ViewEngineResult viewResult = ViewEngines.Engines.FindPartialView(ControllerContext, viewName);

            if (viewResult.View == null)
            {
              throw new ArgumentException(string.Format("Could not find the view with the specified name '{0}'.", viewName), "viewName");
            }

            // Create a view context.
            var viewContext = new ViewContext(ControllerContext, viewResult.View, ViewData, TempData, sw);

            // Render the view using the StringWriter object.
            viewResult.View.Render(viewContext, sw);

            return sw.GetStringBuilder().ToString();
        }
    }
开发者ID:henkmollema,项目名称:MvcPartialViewToString,代码行数:34,代码来源:BaseController.cs

示例6: Start

    // Use this for initialization
    void Start()
    {
        var sw = new StringWriter();
        Evaluator.MessageOutput = sw;
        _stringBuilder = sw.GetStringBuilder();
        Evaluator.Init(new string[0]);
        Evaluator.ReferenceAssembly(Assembly.GetExecutingAssembly());

        foreach (Assembly a in AppDomain.CurrentDomain.GetAssemblies())
        {
            try
            {
                Evaluator.ReferenceAssembly(a);
                Debug.Log("Loaded assembly: " + a.FullName);
            }
            catch (Exception ex)
            {
                Debug.LogWarning("Couldn't load assembly: " + a.FullName + " (" + ex.ToString() + ")");
            }
        }

        Evaluator.Run("using UnityEngine;");
        Evaluator.Run("using Mono.CSharp;");
        Evaluator.Run("using System;");
        Evaluator.Run("using System.Text;");
        Evaluator.Run("using System.Collections;");
        Evaluator.Run("using System.Linq;");
        Evaluator.Run("using DarkCluster.Core;");
        Evaluator.Run("using Assets.Scripts.Events;");
    }
开发者ID:Kazetsukai,项目名称:DarkCluster,代码行数:31,代码来源:REPL.cs

示例7: runTest

	public bool runTest()
	{
		Console.WriteLine(s_strTFPath + "\\" + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
		int iCountErrors = 0;
		int iCountTestcases = 0;
		String strValue = String.Empty;
		Char[] chArr = new Char[]{
			Char.MinValue
			,Char.MaxValue
			,'\t'
			,' '
			,'$'
			,'@'
			,'#'
			,'\0'
			,'\v'
			,'\''
			,'\u3190'
			,'\uC3A0'
			,'A'
			,'5'
			,'\uFE70' 
			,'-'
			,';'
			,'\u00E6'
			,'\n'
			,'\v'
		};
		try {
			StringBuilder sb = new StringBuilder(40);
			StringWriter sw = new StringWriter(sb);
			StringReader sr;
			for(int i = 0 ; i < chArr.Length ; i++)
				sb.Append(chArr[i]);
			sw.Write(sb.ToString());
			sr = new StringReader(sw.GetStringBuilder().ToString());
			Int32 tmp = 0;
			for(int i = 0 ; i < chArr.Length ; i++) {
				iCountTestcases++;
				if((tmp = sr.Read()) != (Int32)chArr[i]) {
					iCountErrors++;
					printerr( "Error_298vc_"+i+"! Expected=="+(Int32)chArr[i]+", got=="+tmp);
				}
			}
		} catch (Exception exc) {
			iCountErrors++;
			printerr( "Error_298yg! Unexpected exception thrown, exc=="+exc.ToString());
		}
		if ( iCountErrors == 0 )
		{
			Console.WriteLine( "paSs. "+s_strTFName+" ,iCountTestcases=="+iCountTestcases.ToString());
			return true;
		}
		else
		{
			Console.WriteLine("FAiL! "+s_strTFName+" ,iCountErrors=="+iCountErrors.ToString()+" , BugNums?: "+s_strActiveBugNums );
			return false;
		}
	}
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:59,代码来源:co5559write_str.cs

示例8: GetJsonFromObject

 public static string GetJsonFromObject(dynamic obj)
 {
     var jsonSerializer = new JsonSerializer();
     using (var stringWriter = new StringWriter())
     {
         jsonSerializer.Serialize(stringWriter, obj);
         var stringBuilder = stringWriter.GetStringBuilder();
         return stringBuilder.ToString();
     }
 }
开发者ID:arneeiri,项目名称:OpenRestWorkshop,代码行数:10,代码来源:Utils.cs

示例9: SerializeXml

    /// <summary>
    ///     An object extension method that serialize a string to XML.
    /// </summary>
    /// <param name="this">The @this to act on.</param>
    /// <returns>The string representation of the Xml Serialization.</returns>
    public static string SerializeXml(this object @this)
    {
        var xmlSerializer = new XmlSerializer(@this.GetType());

        using (var stringWriter = new StringWriter())
        {
            xmlSerializer.Serialize(stringWriter, @this);
            using (var streamReader = new StringReader(stringWriter.GetStringBuilder().ToString()))
            {
                return streamReader.ReadToEnd();
            }
        }
    }
开发者ID:ChuangYang,项目名称:Z.ExtensionMethods,代码行数:18,代码来源:Object.SerializeXml.cs

示例10: RunTests

    private static void RunTests(Assembly assembly)
    {
        if (assembly == null)
            throw new ArgumentNullException("assembly");

        using (var sw = new StringWriter())
        {
            var runner = new NUnitStreamUI(sw);
            runner.Execute(assembly);
            var resultSummary = runner.Summary;
            var resultText = sw.GetStringBuilder().ToString();
            Presenter(resultText, resultSummary);
        }
    }
开发者ID:NameNIL,项目名称:iOS4Unity,代码行数:14,代码来源:NUnitLiteUnityRunner.cs

示例11: RenderRazorViewToString

 public string RenderRazorViewToString(string viewName, object model)
 {
     ViewData.Model = model;
     using (var sw = new 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:NALSS,项目名称:socioboard,代码行数:14,代码来源:MessagesController.cs

示例12: RenderPartialViewToString

    /// <summary>
    /// Method Used to Render a Partial View with Model intact as a string for use in a JSON request
    /// </summary>
    /// <param name="viewName">Path of view that you are attempting to call.</param>
    /// <param name="model">The model data that the view should expect to recieve.</param>
    /// <returns>Html string of partial view.</returns>
    public static string RenderPartialViewToString(this Controller controller, string viewName, object model)
    {
        if (string.IsNullOrEmpty(viewName))
            viewName = controller.ControllerContext.RouteData.GetRequiredString("action");

        controller.ViewData.Model = model;

        using (var writer = new StringWriter())
        {
            ViewEngineResult viewResult = ViewEngines.Engines.FindPartialView(controller.ControllerContext, viewName);
            ViewContext viewContext = new ViewContext(controller.ControllerContext, viewResult.View, controller.ViewData, controller.TempData, writer);
            viewResult.View.Render(viewContext, writer);

            return writer.GetStringBuilder().ToString();
        }
    }
开发者ID:winmissupport,项目名称:FeatureUpate,代码行数:22,代码来源:Controllers.cs

示例13: Main

    public static void  Main(System.String[] args) {
	// first, we init the runtime engine.  Defaults are fine.
	try {
	    Velocity.Init();
	} catch (System.Exception e) {
	    System.Console.Out.WriteLine("Problem initializing Velocity : " + e);
	    return;
	}

	// lets make a Context and put data into it
	VelocityContext context = new VelocityContext();
	context.Put("name", "Velocity");
	context.Put("project", "Jakarta");

	// lets render a template
	StringWriter writer = new StringWriter();
	try {
	    Velocity.MergeTemplate("example2.vm", context, writer);
	} catch (System.Exception e) {
	    System.Console.Out.WriteLine("Problem merging template : " + e);
	}

	System.Console.Out.WriteLine(" template : " + writer.GetStringBuilder().ToString());

	// lets dynamically 'create' our template
	// and use the evaluate() method to render it
	System.String s = "We are using $project $name to render this.";
	writer = new StringWriter();
	try {
	    Velocity.Evaluate(context, writer, "mystring", s);
	} catch (ParseErrorException pee) {
	    // thrown if something is wrong with the
	    // syntax of our template string
	    System.Console.Out.WriteLine("ParseErrorException : " + pee);
	} catch (MethodInvocationException mee) {
	    // thrown if a method of a reference
	    // called by the template
	    // throws an exception. That won't happen here
	    // as we aren't calling any methods in this
	    // example, but we have to catch them anyway
	    System.Console.Out.WriteLine("MethodInvocationException : " + mee);
	} catch (System.Exception e) {
	    System.Console.Out.WriteLine("Exception : " + e);
	}

	System.Console.Out.WriteLine(" string : " + writer.GetStringBuilder().ToString());
    }
开发者ID:DF-thangld,项目名称:web_game,代码行数:47,代码来源:Example2.cs

示例14: RenderViewToString

    public static string RenderViewToString(this Controller controller, string viewName = null, object model = null, string masterName = null)
    {
        if (string.IsNullOrEmpty(viewName))
            {
                viewName = controller.ControllerContext.RouteData.GetRequiredString("action");
            }

            controller.ViewData.Model = model;

            using (StringWriter sw = new StringWriter())
            {
                ViewEngineResult viewResult = ViewEngines.Engines.FindView(controller.ControllerContext, viewName, masterName);
                ViewContext viewContext = new ViewContext(controller.ControllerContext, viewResult.View, controller.ViewData, controller.TempData, sw);
                viewResult.View.Render(viewContext, sw);
                return sw.GetStringBuilder().ToString();
            }
    }
开发者ID:Thirlan,项目名称:insideword,代码行数:17,代码来源:ControllerExtension.cs

示例15: RunTests

    public static void RunTests(Assembly assembly)
    {
        if (assembly == null)
            throw new ArgumentNullException("assembly");

    //    if (_tested.Contains(assembly))
      //      return;
        _tested.Add(assembly);

        using (var sw = new StringWriter())
        {
            var runner = new TextUI(sw);
            runner.Execute(new[] {"/nologo", assembly.FullName});
            var resultText = sw.GetStringBuilder().ToString();
            var assemblyName = assembly.GetName().Name;
            Presenter(assemblyName, resultText);
        }
    }
开发者ID:DavidKimYongRak,项目名称:Lightweight-IoC-Container-for-Unity3D,代码行数:18,代码来源:NUnitLiteUnityRunner.cs


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