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


C# StringWriter.ToString方法代码示例

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


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

示例1: Main

	static int Main ()
	{
		TinyHost h = CreateHost ();
		StringWriter sw = new StringWriter ();
		h.Execute ("Default.aspx", "arg1=1&arg2=2", sw);
		string result = sw.ToString ();

		if (result.IndexOf ("<p>ARG1=1</p>") == -1) {
			Console.WriteLine (result);
			return 1;
		}
		if (result.IndexOf ("<p>ARG2=2</p>") == -1) {
			Console.WriteLine (result);
			return 2;
		}

		sw.GetStringBuilder ().Length = 0;
		h.Execute ("Default.aspx", "arg1=1;arg2=2", sw);
		result = sw.ToString ();

		if (result.IndexOf ("<p>ARG1=1;arg2=2</p>") == -1) {
			Console.WriteLine (result);
			return 3;
		}
		if (result.IndexOf ("<p>ARG2=</p>") == -1) {
			Console.WriteLine (result);
			return 4;
		}

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

示例2: 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

示例3: AddNote

    public void AddNote()
    {
        try {

        var mynote=new DeviceNotes();
        mynote.DeviceId = Int32.Parse(TextBox1.Text);

        mynote.TagId=Int32.Parse(TextBox2.Text);
        mynote.Note=TextBox3.Text;

        var request =
        WebRequest.Create(HOST + "/API/v1/mdm/devices/UDID/66A1DD99B2CC191FEAB20DA10A9D747AED988770/addNote") as HttpWebRequest;
        request.Method = "POST";
        InitializeRequest(request);
        request.ContentType= MIME_TYPE;
        var xmlSerializer=new XmlSerializer(typeof(DeviceNotes));

        string inputString;
        using (var writer =new StringWriter()){

        var xmlNamespace = new XmlSerializerNamespaces();

        xmlNamespace.Add(string.Empty, string.Empty);

        xmlSerializer.Serialize(writer, mynote, xmlNamespace);

        inputString = writer.ToString();
        Label2.Text = writer.ToString();
        }

        byte[] requestBytes = Encoding.UTF8.GetBytes (inputString);
        request.ContentLength = inputString.Length;

        Stream requestStream = request.GetRequestStream();
        requestStream.Write(requestBytes, 0, requestBytes.Length);
        requestStream.Close();

        var response = (HttpWebResponse)request.GetResponse();
        //Console.WriteLine(new StreamReader (response.GetResponseStream()).ReadToEnd());

        Label1.Text = new StreamReader(response.GetResponseStream()).ReadToEnd().ToString();
        response.Close();
        }
        catch (WebException e) {
        if (e.Response != null) {
        var errorMessageStream = e.Response.GetResponseStream();
        string message = new StreamReader (errorMessageStream).ReadToEnd();
        //Console.WriteLine(message);
        Label1.Text = message.ToString();
        } else {
        //Console.WriteLine(e.Message);
        Label1.Text = e.Message;
        }
        }
        catch (Exception e)
        { //Console.WriteLine(e.Message);
        Label1.Text = e.Message;
        }
    }
开发者ID:Curtisspope,项目名称:MDM_API_AW,代码行数:59,代码来源:AddNoteToDevice.aspx.cs

示例4: EntitiesTest

    public void EntitiesTest()
    {
      Purchase purchase = new Purchase() { Id = 1 };
      purchase.PurchaseLine.Add(new PurchaseLine() { Id = 1, Purchase = purchase });
      purchase.PurchaseLine.Add(new PurchaseLine() { Id = 2, Purchase = purchase });

      StringWriter sw = new StringWriter();
      JsonSerializer serializer = new JsonSerializer();
      serializer.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;

      using (JsonWriter jw = new JsonTextWriter(sw))
      {
        jw.Formatting = Formatting.Indented;

        serializer.Serialize(jw, purchase);
      }

      string json = sw.ToString();

      Assert.AreEqual(@"{
  ""Id"": 1,
  ""PurchaseLine"": [
    {
      ""Id"": 1,
      ""PurchaseReference"": {
        ""EntityKey"": null,
        ""RelationshipName"": ""EntityDataModel.PurchasePurchaseLine"",
        ""SourceRoleName"": ""PurchaseLine"",
        ""TargetRoleName"": ""Purchase"",
        ""RelationshipSet"": null,
        ""IsLoaded"": false
      },
      ""EntityState"": 1,
      ""EntityKey"": null
    },
    {
      ""Id"": 2,
      ""PurchaseReference"": {
        ""EntityKey"": null,
        ""RelationshipName"": ""EntityDataModel.PurchasePurchaseLine"",
        ""SourceRoleName"": ""PurchaseLine"",
        ""TargetRoleName"": ""Purchase"",
        ""RelationshipSet"": null,
        ""IsLoaded"": false
      },
      ""EntityState"": 1,
      ""EntityKey"": null
    }
  ],
  ""EntityState"": 1,
  ""EntityKey"": null
}", json);

      Purchase newPurchase = JsonConvert.DeserializeObject<Purchase>(json);
      Assert.AreEqual(1, newPurchase.Id);

      Assert.AreEqual(2, newPurchase.PurchaseLine.Count);
      Assert.AreEqual(1, newPurchase.PurchaseLine.ElementAt(0).Id);
      Assert.AreEqual(2, newPurchase.PurchaseLine.ElementAt(1).Id);
    }
开发者ID:thirumg,项目名称:Avro.NET,代码行数:60,代码来源:JsonConvertTest.cs

示例5: ParseRazor

    public static string ParseRazor(string virtualPath, object model)
    {
        string pageVPath = virtualPath;

        try
        {
            Type t = BuildManager.GetCompiledType(pageVPath);
            if (t != null)
            {
                HttpContextWrapper wrapper = new HttpContextWrapper(HttpContext.Current);

                object inst = Activator.CreateInstance(t);

                System.Web.WebPages.WebPage webpage = inst as System.Web.WebPages.WebPage;
                webpage.VirtualPath = pageVPath;
                StringWriter writer = new StringWriter();
                webpage.ExecutePageHierarchy(new System.Web.WebPages.WebPageContext(wrapper, webpage, model), writer, webpage);
                string content = writer.ToString();

                return content;
            }
        }
        catch (Exception ex)
        {
            Utils.Log(string.Format("RazorHelper, ParseRazor, VirtualPath: {0}", virtualPath), ex);

            // return the error message since it will usually contain parsing
            // details when the Razor markup/syntax is invalid.  this will help
            // when debugging, so the error log does not need to be checked.
            return ex.Message;
        }

        return null;
    }
开发者ID:doct15,项目名称:blogengine,代码行数:34,代码来源:RazorHelpers.cs

示例6: GetDeliveries

 internal static string GetDeliveries()
 {
     sql = "SELECT " +
             "deliveries.id AS delivery_id, purchases.id AS purchase_id, purchases.po_number, deliveries.delivery_date, supplier_id, name AS supplier_name, " +
             "lookup_status.description AS status, lookup_status2.description AS completion_status " +
         "FROM deliveries " +
         "JOIN purchases ON purchases.id = deliveries.purchase_id " +
         "JOIN suppliers ON suppliers.id = supplier_id " +
         "JOIN lookup_status ON lookup_status.id = deliveries.status " +
         "JOIN lookup_status AS lookup_status2 ON lookup_status2.id = deliveries.completion_status " +
         "WHERE lookup_status2.description != 'Complete' ";
     dt = new DataTable();
     dt = Database.Query(sql);
     if (dt != null)
     {
         if (dt.Rows[0].ItemArray[0].ToString() == "-1")
         {
             result = dt.Rows[0].ItemArray[1].ToString();
         }
         else
         {
             StringWriter sw = new StringWriter();
             dt.WriteXml(sw);
             result = sw.ToString();
         }
     }
     else
     {
         result = Functions.FormatReturn(0, "No items found");
     }
     return result;
 }
开发者ID:kingpauloaquino,项目名称:CERP-WS,代码行数:32,代码来源:Queries.cs

示例7: renderLoginControls

    public void renderLoginControls()
    {
        try
        {
            string XmlPath = Server.MapPath("xml/UserLogin.xml");
            string XsltPath = Server.MapPath("xslt/UserLogin.xslt");

            XPathDocument xdoc = new XPathDocument(XmlPath);

            XslCompiledTransform transform = new XslCompiledTransform();
            transform.Load(XsltPath);

            StringWriter sw = new StringWriter();

            //Transform
            transform.Transform(xdoc, null, sw);
            string result = sw.ToString();

            //Remove Namespace
            result = result.Replace("xmlns:asp=\"remove\"", "");
            result = result.Replace("xmlns:cc1=\"remove\"", "");

            //Parse Control
            Control ctrl = Page.ParseControl(result);
            phLogin.Controls.Add(ctrl);
        }
        catch (Exception ex)
        {
            objNLog.Error("Error : " + ex.Message);
        }
    }
开发者ID:aptivasoft,项目名称:Adio,代码行数:31,代码来源:Login.aspx.cs

示例8: Action

    public void Action() {   
        string xml = "<?xml version=\"1.0\"?>\n<a><b c=\"d\">e</b></a>";
        string xsl = "<?xml version=\"1.0\"?>\n" +
            "<xsl:stylesheet version=\"1.0\" " +
                    "xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" " +
                    "xmlns:msxsl=\"urn:schemas-microsoft-com:xslt\" " +
                    "xmlns:js=\"urn:js\" " +
                ">" +
                "<msxsl:script language=\"jsCrIpt\" implements-prefix=\"js\">" +
                    "function SimpleTest() { return \"JScript test\"; }" +        
                "</msxsl:script>" +                
                "<xsl:template match=\"a\"><foo><xsl:apply-templates/></foo></xsl:template>" +
                "<xsl:template match=\"b\"><xsl:element name=\"bar\">" +
        	        "<xsl:attribute name=\"simpleTest\"><xsl:value-of select=\"js:SimpleTest()\"/></xsl:attribute>" +
                "</xsl:element></xsl:template>" +
                "<xsl:template match=\"/\"><xsl:apply-templates/></xsl:template>" +
            "</xsl:stylesheet>";            
    
        XPathDocument myXPathDocument = new XPathDocument(new XmlTextReader(new StringReader(xml)));

        XslTransform myXslTransform = new XslTransform();
        myXslTransform.Load(new XmlTextReader(new StringReader(xsl)));
        
        StringWriter myStringWriter = new StringWriter();
        XmlTextWriter myXmlWriter = new XmlTextWriter(myStringWriter);
        myXmlWriter.Formatting = Formatting.Indented;
        
        myXslTransform.Transform(myXPathDocument, null, myXmlWriter);
        myXmlWriter.Close();        
        
        Console.WriteLine(myStringWriter.ToString());
    }
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:32,代码来源:appdomainstress.cs

示例9: Page_Load

    protected void Page_Load(object sender, EventArgs e)
    {
        // gather log4net output with small hack to get results...
        ILoggerRepository repository = LogManager.GetRepository();
        IAppender[] appenders = repository.GetAppenders();
        MemoryAppender appender = null;
        foreach (IAppender a in appenders)
        {
            if (a is MemoryAppender)
            {
                // we found our appender to look results from
                appender = a as MemoryAppender;
                break;
            }
        }

        if (appender != null)
        {
            appender.Clear();
            fulfillmentService.ProcessCustomer(customerEditController.CurrentCustomer.Id);
            LoggingEvent[] events = appender.GetEvents();
            StringWriter stringWriter = new StringWriter();
            PatternLayout layout = new PatternLayout("%date{HH:mm:ss} %-5level %logger{1}: %message<br />");
            foreach (LoggingEvent loggingEvent in events)
            {
                layout.Format(stringWriter, loggingEvent);
            }

            results.Text = stringWriter.ToString();
        }

    }
开发者ID:ouyangyl,项目名称:MySpringNet,代码行数:32,代码来源:FulfillmentResult.aspx.cs

示例10: GetSpeaking_PracticeContents

    public List<string> GetSpeaking_PracticeContents(int ID_Unit)
    {
        IEnumerable<SPEAKING> speaking_Practices = this.GetSpeakingUnit(ID_Unit);

        List<string> list = new List<string>();

        foreach (SPEAKING item in speaking_Practices)
        {
            XmlDocument xmlDoc = new XmlDocument();
            Stream stream;
            try
            {
                stream = File.OpenRead(System.Web.Hosting.HostingEnvironment.MapPath("~/ClientBin/" + item.Suggestion));                
                xmlDoc.Load(stream);                
            }
            catch (XmlException e)
            {
                Console.WriteLine(e.Message);
            }
            // Now create StringWriter object to get data from xml document.
            StringWriter sw = new StringWriter();
            XmlTextWriter xw = new XmlTextWriter(sw);

            xmlDoc.WriteTo(xw);
            list.Add(sw.ToString());

        }

        return list;        
    }
开发者ID:mylgoehy,项目名称:qlqtpmav10,代码行数:30,代码来源:SpeakingService.cs

示例11: TestGraphConnectedComponents9Vertices

    public void TestGraphConnectedComponents9Vertices()
    {
        // Arrange
        var input =
            "9" + "\n" +
            "3 6" + "\n" +
            "3 4 5 6" + "\n" +
            "8" + "\n" +
            "0 1 5" + "\n" +
            "1 6" + "\n" +
            "1 3" + "\n" +
            "0 1 4" + "\n" +
            string.Empty + "\n" +
            "2" + "\n";

        // Act
        var inputReader = new StringReader(input);
        var outputWriter = new StringWriter();
        using (outputWriter)
        {
            Console.SetIn(inputReader);
            Console.SetOut(outputWriter);
            GraphConnectedComponents.Main();
        }

        var output = outputWriter.ToString();

        // Assert
        var expectedOutput = 
            "Connected component: 6 4 5 1 3 0" + "\n" +
            "Connected component: 8 2" + "\n" +
            "Connected component: 7" + "\n";
        output = output.Replace("\r\n", "\n");
        Assert.AreEqual(expectedOutput, output);
    }
开发者ID:nok32,项目名称:SoftUni,代码行数:35,代码来源:UnitTestsGraph.cs

示例12: btnExport_Click

    protected void btnExport_Click(object sender, EventArgs e)
    {
        Response.ClearContent();
        Response.AppendHeader("content-disposition", "attachment; filename=Evaluation Report between " + txtStartDate.Text + " and " + txtEndDate.Text + ".xls");
        Response.ContentType = "application/excel";

        StringWriter stringWrite = new StringWriter();
        HtmlTextWriter htmlTextWrite = new HtmlTextWriter(stringWrite);

        GridView1.HeaderRow.Style.Add("background-color", "#FFFFFF");
        foreach (TableCell tableCell in GridView1.HeaderRow.Cells)
        {
            tableCell.Style["background-color"] = "#5D7B9D";
        }

        foreach (GridViewRow gridViewRow in GridView1.Rows)
        {
            gridViewRow.BackColor = System.Drawing.Color.White;
            foreach (TableCell gridViewRowTableCell in gridViewRow.Cells)
            {
                gridViewRowTableCell.Style["background-color"] = "#F7F6F3";
            }
        }

        GridView1.RenderControl(htmlTextWrite);
        Response.Write(stringWrite.ToString());
        Response.End();
    }
开发者ID:jLeta,项目名称:HN_HR_1.0,代码行数:28,代码来源:Evaluation.aspx.cs

示例13: RespCallback

    private static void RespCallback(IAsyncResult ar)
    {
        HttpWebRequest req;
        HttpWebResponse resp;
        int BytesRead;
        StreamReader Reader;
        StringWriter Writer;

        req=(HttpWebRequest)(Object)ar;
        resp=(HttpWebResponse)req.EndGetResponse(ar);

        BytesRead=0;
        char[] Buffer=new char[MAX];

        Reader=new StreamReader(resp.GetResponseStream(),System.Text.Encoding.UTF8);
        Writer=new StringWriter();

        BytesRead=Reader.Read(Buffer,0,MAX);
        while(BytesRead!=0)
        {
            Writer.Write(Buffer,0,MAX);
            BytesRead=Reader.Read(Buffer,0,MAX);
        }

        Console.WriteLine("Message="+Writer.ToString());
    }
开发者ID:ShiJess,项目名称:CompanyStudy,代码行数:26,代码来源:GetURLAsync.cs

示例14: btnExportTOWord_Click

    protected void btnExportTOWord_Click(object sender, EventArgs e)
    {
        try
        {
            pnlTicket.Visible = true;
            // BindLabelData();
            Response.Clear();
            Response.Buffer = true;
            Response.AddHeader("content-disposition", "attachment;filename=Ticket.doc");
            Response.Charset = "";
            Response.ContentType = "application/vnd.ms-word";
            StringWriter sw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(sw);
            pnlTicket.RenderControl(hw);
            Response.Output.Write(sw.ToString());
            Response.Flush();
            Response.End();
        }
        catch (System.Threading.ThreadAbortException lException)
        {

            // do nothing

        }
    }
开发者ID:srisai339,项目名称:LoveJourney_Working,代码行数:25,代码来源:Bookings.aspx.cs

示例15: Test1

  public void Test1()
  {


    var context = new ControllerContext( HttpContext.Request.RequestContext, new TestController() );

    var result = ViewEngines.Engines.FindView( context, "~/ActionUrlTest/Test1.html", null );

    Assert.NotNull( result.View, "找不到视图" );


    IHtmlDocument document;

    using ( var writer = new StringWriter() )
    {
      result.View.Render( new ViewContext( context, result.View, new ViewDataDictionary(), new TempDataDictionary(), writer ), writer );

      document = new JumonyParser().Parse( writer.ToString() );
    }


    var link = document.FindFirst( "a" );

    Assert.NotNull( link );

    Assert.AreEqual( link.Attribute( "href" ).Value(), "/TestController/TestAction?arg=args" );


  }
开发者ID:ajayumi,项目名称:Jumony,代码行数:29,代码来源:ActionUrlTest.cs


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