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


C# StringWriter.Write方法代码示例

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


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

示例1: ToJson

        /// <summary>
        /// Converts a timestamp  specified in seconds/nanoseconds to a string.
        /// </summary>
        /// <remarks>
        /// If the value is a normalized duration in the range described in <c>field_mask.proto</c>,
        /// <paramref name="diagnosticOnly"/> is ignored. Otherwise, if the parameter is <c>true</c>,
        /// a JSON object with a warning is returned; if it is <c>false</c>, an <see cref="InvalidOperationException"/> is thrown.
        /// </remarks>
        /// <param name="paths">Paths in the field mask</param>
        /// <param name="diagnosticOnly">Determines the handling of non-normalized values</param>
        /// <exception cref="InvalidOperationException">The represented field mask is invalid, and <paramref name="diagnosticOnly"/> is <c>false</c>.</exception>
        internal static string ToJson(IList<string> paths, bool diagnosticOnly)
        {
            var firstInvalid = paths.FirstOrDefault(p => !ValidatePath(p));
            if (firstInvalid == null)
            {
                var writer = new StringWriter();
#if DOTNET35
                var query = paths.Select(JsonFormatter.ToJsonName);
                JsonFormatter.WriteString(writer, string.Join(",", query.ToArray()));
#else
                JsonFormatter.WriteString(writer, string.Join(",", paths.Select(JsonFormatter.ToJsonName)));
#endif
                return writer.ToString();
            }
            else
            {
                if (diagnosticOnly)
                {
                    var writer = new StringWriter();
                    writer.Write("{ \"@warning\": \"Invalid FieldMask\", \"paths\": ");
                    JsonFormatter.Default.WriteList(writer, (IList)paths);
                    writer.Write(" }");
                    return writer.ToString();
                }
                else
                {
                    throw new InvalidOperationException($"Invalid field mask to be converted to JSON: {firstInvalid}");
                }
            }
        }
开发者ID:Kwizatz,项目名称:protobuf,代码行数:41,代码来源:FieldMaskPartial.cs

示例2: 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 ();
		}
开发者ID:Anomalous-Software,项目名称:monomac,代码行数:35,代码来源:DocTools.cs

示例3: 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();
            }
        }
开发者ID:jlarsson,项目名称:MvcAssets,代码行数:28,代码来源:AssetsInjectorBase.cs

示例4: TestCultureInfoConstructor

        public void TestCultureInfoConstructor() {

		StringWriter writer = new StringWriter(CultureInfo.InvariantCulture);
		Assert.IsNotNull (writer.GetStringBuilder());
		
		Assert.AreEqual (String.Empty, writer.ToString());
		
		writer.Write( 'A' );
		Assert.AreEqual ("A", writer.ToString());
		
		writer.Write( " foo" );
		Assert.AreEqual ("A foo", writer.ToString());
		
		
		char[] testBuffer = "Test String".ToCharArray();
		
		writer.Write( testBuffer, 0, 4 );
		Assert.AreEqual ("A fooTest", writer.ToString());
		
		writer.Write( testBuffer, 5, 6 );
		Assert.AreEqual ("A fooTestString", writer.ToString());
		
		writer = new StringWriter(CultureInfo.InvariantCulture);
		writer.Write(null as string);
		Assert.AreEqual ("", writer.ToString());
        }
开发者ID:KonajuGames,项目名称:SharpLang,代码行数:26,代码来源:StringWriterTest.cs

示例5: GenerateDot

 internal string GenerateDot(Dictionary<string, object> pairs)
 {
     bool flag = false;
     StringWriter writer = new StringWriter();
     foreach (var entry in pairs)
     {
         if (flag)
         {
             writer.Write(", ");
         }
         else
         {
             flag = true;
         }
         if (entry.Value is string)
         {
             writer.Write("{0}=\"{1}\"", entry.Key.ToString(), entry.Value.ToString());
             continue;
         }
         if (entry.Value is GraphvizColor)
         {
             GraphvizColor GraphvizColor = (GraphvizColor) entry.Value;
             writer.Write("{0}=\"#{1}{2}{3}{4}\"", new object[] { entry.Key.ToString(), GraphvizColor.R.ToString("x2").ToUpper(), GraphvizColor.G.ToString("x2").ToUpper(), GraphvizColor.B.ToString("x2").ToUpper(), GraphvizColor.A.ToString("x2").ToUpper() });
             continue;
         }
         if ((entry.Value is GraphvizRankDirection) || (entry.Value is GraphvizPageDirection))
         {
             writer.Write("{0}={1};", entry.Key.ToString(), entry.Value.ToString());
             continue;
         }
         writer.Write(" {0}={1}", entry.Key.ToString(), entry.Value.ToString().ToLower());
     }
     return writer.ToString();
 }
开发者ID:sayedjalilhassan,项目名称:LearningPlatform,代码行数:34,代码来源:GraphvizGraph.cs

示例6: SendBuffer

        override protected void SendBuffer(LoggingEvent[] events)
        {

            try
            {
                StringWriter writer = new StringWriter(System.Globalization.CultureInfo.InvariantCulture);
                string t = Layout.Header;

                if (t != null)
                    writer.Write(t);

                for (int i = 0; i < events.Length; i++)
                {
                    // Render the event and append the text to the buffer
                    RenderLoggingEvent(writer, events[i]);
                }

                t = Layout.Footer;

                if (t != null)
                    writer.Write(t);

                // Use SmtpClient so we can use SSL.
                SmtpClient client = new SmtpClient(SmtpHost, Port);
                client.EnableSsl = true;
                client.Credentials = new NetworkCredential(Username, Password);
                string messageText = writer.ToString();
                MailMessage mail = new MailMessage(From, To, Subject, messageText);
                client.Send(mail);
            }
            catch (Exception e)
            {
                ErrorHandler.Error("Error occurred while sending e-mail notification from SmtpClientSmtpAppender.", e);
            }
        }
开发者ID:matiyos,项目名称:log4net.GmailAppender,代码行数:35,代码来源:GmailAppender.cs

示例7: GetOfferString

 private static string GetOfferString(Item item, Offer o, string[] listPrices, string[] salePrices)
 {
     using (StringWriter writer = new StringWriter()) {
         writer.WriteLine("Merchant: " + o.Merchant.Name);
         if (o.Merchant.MerchantId != AmazonComMerchantId)
             writer.WriteLine(
                 "Shipping information by Merchant: http://www.amazon.com/gp/help/seller/shipping.html?seller=" +
                 o.Merchant.MerchantId + "&asin=" + item.ASIN);
         if (o.Merchant.MerchantId == AmazonComMerchantId) {
             if (!o.OfferListing[0].IsEligibleForSuperSaverShipping)
                 writer.Write("Not ");
             writer.WriteLine("Eligible for Super Saver Shipping");
         }
         writer.WriteLine("List Price: " + listPrices[1]);
         if(salePrices != null)
             writer.WriteLine("Sale Price: " + salePrices[1]);
         if (o.OfferListing[0].ShippingCharge != null) {
             writer.Write("Shipping Charge: ");
             foreach (OfferListingShippingCharge charge in o.OfferListing[0].ShippingCharge) {
                 writer.Write("  ");
                 writer.WriteLine(charge.ShippingType + " - " + charge.ShippingPrice.FormattedPrice);
             }
         }
         return writer.ToString();
     }
 }
开发者ID:flynhigher,项目名称:terry-play-ground,代码行数:26,代码来源:Program.cs

示例8: EmitBatch

        protected override void EmitBatch(IEnumerable<LogEvent> events)
        {
            var payload = new StringWriter();
            payload.Write("{\"events\":[");

            var formatter = new JsonFormatter();
            var delimStart = "";
            foreach (var logEvent in events)
            {
                payload.Write(delimStart);
                formatter.Format(logEvent, payload);
                delimStart = ",";
            }

            payload.Write("]}");

            var content = new StringContent(payload.ToString(), Encoding.UTF8, "application/json");
            if (!string.IsNullOrWhiteSpace(_apiKey))
                content.Headers.Add(ApiKeyHeaderName, _apiKey);
    
            var result = _httpClient.PostAsync(BulkUploadResource, content).Result;
            if (!result.IsSuccessStatusCode)
                SelfLog.WriteLine("Received failed result {0}: {1}", result.StatusCode, result.Content.ReadAsStringAsync().Result);

            var returned = result.Content.ReadAsStringAsync().Result;
            _minimumAcceptedLevel = SeqApi.ReadEventInputResult(returned);
        }
开发者ID:colin-young,项目名称:serilog-sinks-seq,代码行数:27,代码来源:SeqSink-net40.cs

示例9: ExecuteResult

        public override void ExecuteResult(ControllerContext context)
        {
            var sw = new StringWriter();

            foreach (var header in ColumnHeaders)
                sw.Write(string.Format("\"{0}\",", header));

            var properties = GetType(Records).GetProperties();

            foreach (var item in Records)
            {
                if (item != null)
                {
                    sw.WriteLine();
                    foreach (var property in properties)
                    {
                        var obj = property.GetValue(item, null);
                        if (obj != null)
                        {
                            var strValue = obj.ToString();
                            sw.Write(string.Format("\"{0}\",", ReplaceSpecialCharacters(strValue)));
                        }
                        else
                            sw.Write("\"\"");
                    }
                }
            }

            WriteFile(FileName, "application/CSV", sw.ToString());
        }
开发者ID:feanz,项目名称:Example,代码行数:30,代码来源:CsvResult.cs

示例10: using

        String IStyleFormatter.Sheet(IEnumerable<IStyleFormattable> rules)
        {
            var sb = Pool.NewStringBuilder();
            var first = true;

            using (var writer = new StringWriter(sb))
            {
                foreach (var rule in rules)
                {
                    if (first)
                    {
                        first = false;
                    }
                    else
                    {
                        writer.Write(_newLineString);
                        writer.Write(_newLineString);
                    }

                    rule.ToCss(writer, this);
                }
            }

            return sb.ToPool();
        }
开发者ID:Wojdav,项目名称:AngleSharp,代码行数:25,代码来源:PrettyStyleFormatter.cs

示例11: Render

        public void Render(IList<Timeseries> splitPerYear, StringWriter writer)
        {
            WriteSeriesHeaders(splitPerYear, writer);

            for (var i = 0; i < 12; i++)
            {
                var monthNumber = i + 1;
                WriteRowHeader(monthNumber, writer);

                foreach (var series in splitPerYear)
                {
                    var firstMonthInSeries = series[0].Time.Month;
                    var startMonthDelta = firstMonthInSeries - 1;
                    var index = i - startMonthDelta;

                    if (index >= 0 && index < series.Count)
                    {
                        var v = series[index].V;
                        var numberFormat = m_CultureInfo.NumberFormat;
                        var formattedValue = v.ToString(numberFormat);
                        writer.Write(formattedValue);
                    }
                    writer.Write(ColumnSeparator);
                }
                writer.WriteLine();
            }
        }
开发者ID:fbertilsson,项目名称:Yearly,代码行数:27,代码来源:MonthlyValueRenderer.cs

示例12: GetArguments

 public override string GetArguments(string inputFileName, string outputFileName)
 {
     VideoParameters parms =
         VideoParameterOracle.GetParameters(inputFileName);
     if (parms == null)
         return string.Format(
             "\"{0}\" -o \"{1}\" --videoquality 8 --audioquality 6 --frontend",
             inputFileName, outputFileName);
     else {
         StringBuilder paramsBuilder = new StringBuilder();
         StringWriter paramsWriter = new StringWriter(paramsBuilder);
         if (parms.Height.HasValue && parms.Width.HasValue)
             paramsWriter.Write("-x {0} -y {1} ",
                 parms.Width, parms.Height);
         if (parms.VideoBitrate.HasValue && parms.AudioBitrate.HasValue)
             paramsWriter.Write("-V {0} -A {1} --two-pass ",
                 parms.VideoBitrate, parms.AudioBitrate);
         else
             paramsWriter.Write("--videoquality 8 --audioquality 6 ");
         paramsWriter.Close();
         return string.Format(
             "\"{0}\" -o \"{1}\" {2} --frontend",
                 inputFileName, outputFileName, paramsBuilder.ToString());
     }
 }
开发者ID:timryder,项目名称:mirovideoconverter,代码行数:25,代码来源:TheoraVideoFormat.cs

示例13: Show

		public static void Show(Exception e, StackTrace innerStackTrace = null, string customMessage = null)
		{
			var writer = new StringWriter();

			if (customMessage != null)
				WriteCustomMessage(customMessage, writer);
			else
				SetCustomMessageBasedOnTheActualError(writer, e);

			writer.Write("Message: ");
			writer.WriteLine(e.Message);
			if (string.IsNullOrWhiteSpace(UrlUtil.Url) == false)
			{
				writer.Write("Uri: ");
				writer.WriteLine(UrlUtil.Url);
			}
			writer.Write("Server Uri: ");
			writer.WriteLine(GetServerUri(e));

			writer.WriteLine();
			writer.WriteLine("-- Error Information --");
			writer.WriteLine(e.ToString());
			writer.WriteLine();

			if (innerStackTrace != null)
			{
				writer.WriteLine("Inner StackTrace: ");
				writer.WriteLine(innerStackTrace.ToString());
			}
		
			Show(writer.ToString());
		}
开发者ID:925coder,项目名称:ravendb,代码行数:32,代码来源:ErrorPresenter.cs

示例14: Insert

        public override void Insert(IDbAccesser dba, Entity item)
        {
            var idColumn = this.IdentityColumn;
            if (idColumn != null)
            {
                if (_selectSEQSql == null)
                {
                    var seqName = new StringWriter();
                    seqName.Write("SEQ_");
                    this.AppendPrepare(seqName, this.Name);
                    seqName.Write('_');
                    this.AppendPrepare(seqName, idColumn.Name);
                    var seqNameValue = Rafy.DbMigration.Oracle.OracleMigrationProvider.LimitOracleIdentifier(seqName.ToString());

                    //此序列是由 DbMigration 中自动生成的。
                    _selectSEQSql = string.Format(@"SELECT {0}.NEXTVAL FROM DUAL", seqNameValue);
                }
                //由于默认可能不是 int 类型,所以需要类型转换。
                var value = dba.RawAccesser.QueryValue(_selectSEQSql);
                value = TypeHelper.CoerceValue(item.KeyProvider.KeyType, value);
                idColumn.LoadValue(item, value);

                //如果实体的 Id 是在插入的过程中生成的,
                //那么需要在插入组合子对象前,先把新生成的父对象 Id 都同步到子列表中。
                item.SyncIdToChildren();
            }

            base.Insert(dba, item);
        }
开发者ID:hardCTE,项目名称:Rafy,代码行数:29,代码来源:OracleTable.cs

示例15: TestWrite

        public void TestWrite() {
                StringWriter writer = new StringWriter();

                Assert.AreEqual (String.Empty, writer.ToString());
                
                writer.Write( 'A' );
                Assert.AreEqual ("A", writer.ToString());

                writer.Write( " foo" );
                Assert.AreEqual ("A foo", writer.ToString());

                
                char[] testBuffer = "Test String".ToCharArray();

                writer.Write( testBuffer, 0, 4 );
                Assert.AreEqual ("A fooTest", writer.ToString());

                writer.Write( testBuffer, 5, 6 );
                Assert.AreEqual ("A fooTestString", writer.ToString());

		writer = new StringWriter ();
                writer.Write(null as string);
                Assert.AreEqual ("", writer.ToString());

        }
开发者ID:KonajuGames,项目名称:SharpLang,代码行数:25,代码来源:StringWriterTest.cs


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