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


C# StringBuilder.AppendMultiLine方法代码示例

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


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

示例1: appending_multi_lines_with_a_prefix_with_null_or_empty_or_one_line

        public void appending_multi_lines_with_a_prefix_with_null_or_empty_or_one_line()
        {
            {
                StringBuilder b = new StringBuilder();
                string text = @"One line.";
                string t = b.AppendMultiLine( "|", text, true ).ToString();
                Assert.That( t, Is.EqualTo( @"|One line." ) );
            }
            {
                StringBuilder b = new StringBuilder();
                string text = @"";
                string t = b.AppendMultiLine( "|", text, true ).ToString();
                Assert.That( t, Is.EqualTo( @"|" ) );
            }
            {
                StringBuilder b = new StringBuilder();
                string text = null;
                string t = b.AppendMultiLine( "|", text, true ).ToString();
                Assert.That( t, Is.EqualTo( @"|" ) );
            }
            {
                StringBuilder b = new StringBuilder();
                string text = @"One line.";
                string t = b.AppendMultiLine( "|", text, false ).ToString();
                Assert.That( t, Is.EqualTo( @"One line." ) );
            }
            {
                StringBuilder b = new StringBuilder();
                string text = @"";
                string t = b.AppendMultiLine( "|", text, false ).ToString();
                Assert.That( t, Is.EqualTo( @"" ) );
            }
            {
                StringBuilder b = new StringBuilder();
                string text = null;
                string t = b.AppendMultiLine( "|", text, false ).ToString();
                Assert.That( t, Is.EqualTo( @"" ) );
            }

        }
开发者ID:Invenietis,项目名称:ck-core,代码行数:40,代码来源:StringAndStringBuilderExtensionTests.cs

示例2: DumpException

        /// <summary>
        /// Recursively dumps an <see cref="Exception"/> as readable text.
        /// </summary>
        /// <param name="w">The TextWriter to write to.</param>
        /// <param name="prefix">Prefix that will start all lines.</param>
        /// <param name="displayMessage">Whether the exception message must be displayed or skip.</param>
        /// <param name="ex">The exception to display.</param>
        static public void DumpException( StringBuilder w, string prefix, bool displayMessage, Exception ex )
        {
            CKException ckEx = ex as CKException;
            if( ckEx != null && ckEx.ExceptionData != null )
            {
                ckEx.ExceptionData.ToStringBuilder( w, prefix );
                return;
            }

            string header = String.Format( " ┌──────────────────────────■ Exception : {0} ■──────────────────────────", ex.GetType().Name );

            string p;
            w.AppendLine( prefix + header );
            string localPrefix = prefix + " | ";
            if( displayMessage && ex.Message != null )
            {
                w.Append( localPrefix + "Message: " );
                w.AppendMultiLine( localPrefix + "         ", ex.Message, false );
                w.AppendLine();
            }
            if( ex.StackTrace != null )
            {
                w.Append( localPrefix + "Stack: " );
                w.AppendMultiLine( localPrefix + "       ", ex.StackTrace, false );
                w.AppendLine();
            }
            var fileNFEx = ex as System.IO.FileNotFoundException;
            if( fileNFEx != null )
            {
                if( !String.IsNullOrEmpty( fileNFEx.FileName ) ) w.AppendLine( localPrefix + "FileName: " + fileNFEx.FileName );
                #if NET451 || NET46
                if( fileNFEx.FusionLog != null )
                {
                    w.Append( localPrefix + "FusionLog: " );
                    w.AppendMultiLine( localPrefix + "         ", fileNFEx.FusionLog, false );
                    w.AppendLine();
                }
                #endif
            }
            else
            {
                var loadFileEx = ex as System.IO.FileLoadException;
                if( loadFileEx != null )
                {
                    if( !String.IsNullOrEmpty( loadFileEx.FileName ) ) w.AppendLine( localPrefix + "FileName: " + loadFileEx.FileName );
                    #if NET451 || NET46
                    if( loadFileEx.FusionLog != null )
                    {
                        w.Append( localPrefix + "FusionLog: " );
                        w.AppendMultiLine( localPrefix + "         ", loadFileEx.FusionLog, false );
                        w.AppendLine();
                    }
                    #endif
                }
                else
                {
                    var typeLoadEx = ex as ReflectionTypeLoadException;
                    if( typeLoadEx != null )
                    {
                        w.AppendLine( localPrefix + " ┌──────────────────────────■ [Loader Exceptions] ■──────────────────────────" );
                        p = localPrefix + " | ";
                        foreach( var item in typeLoadEx.LoaderExceptions )
                        {
                            DumpException( w, p, true, item );
                        }
                        w.AppendLine( localPrefix + " └─────────────────────────────────────────────────────────────────────────" );
                    }
                    #if NET451 || NET46
                    else
                    {
                        var configEx = ex as System.Configuration.ConfigurationException;
                        if( configEx != null )
                        {
                            if( !String.IsNullOrEmpty( configEx.Filename ) ) w.AppendLine( localPrefix + "FileName: " + configEx.Filename );
                        }
                    }
                    #endif
                }
            }
            // The InnerException of an aggregated exception is the same as the first of it InnerExceptionS.
            // (The InnerExceptionS are the contained/aggregated exceptions of the AggregatedException object.)
            // This is why, if we are on an AggregatedException we do not follow its InnerException.
            var aggrex = ex as AggregateException;
            if( aggrex != null && aggrex.InnerExceptions.Count > 0 )
            {
                w.AppendLine( localPrefix + " ┌──────────────────────────■ [Aggregated Exceptions] ■──────────────────────────" );
                p = localPrefix + " | ";
                foreach( var item in aggrex.InnerExceptions )
                {
                    DumpException( w, p, true, item );
                }
                w.AppendLine( localPrefix + " └─────────────────────────────────────────────────────────────────────────" );
            }
//.........这里部分代码省略.........
开发者ID:Invenietis,项目名称:ck-core,代码行数:101,代码来源:ActivityMonitorTextWriterClient.cs

示例3: AppendField

 static StringBuilder AppendField( StringBuilder b, string prefix, string label, string text )
 {
     b.Append( prefix ).Append( label ).Append( ": " ).Append( ' ', 10 - label.Length );
     prefix += new string( ' ', 12 );
     b.AppendMultiLine( prefix, text, false ).AppendLine();
     return b;
 }
开发者ID:Invenietis,项目名称:ck-core,代码行数:7,代码来源:CKExceptionData.cs

示例4: PrefixWithOurExtension

 long PrefixWithOurExtension( Stopwatch w, string f, string[] results )
 {
     GC.Collect();
     w.Restart();
     StringBuilder b = new StringBuilder();
     for( int i = 0; i < results.Length; ++i )
     {
         // We must use the prefixLastEmptyLine to match the way the naive implementation works.
         results[i] = b.AppendMultiLine( prefix, f, false, prefixLastEmptyLine: true ).ToString();
         b.Clear();
     }
     w.Stop();
     return w.ElapsedTicks;
 }
开发者ID:Invenietis,项目名称:ck-core,代码行数:14,代码来源:StringAndStringBuilderExtensionTests.cs

示例5: appending_multi_lines_with_prefixLastEmptyLine

        public void appending_multi_lines_with_prefixLastEmptyLine()
        {
            string text = @"First line.
Second line.


";
            {
                StringBuilder b = new StringBuilder();
                string t = b.AppendMultiLine( "|", text, true, prefixLastEmptyLine: false ).ToString();
                Assert.That( t, Is.EqualTo( @"|First line.
|Second line.
|
|".NormalizeEOL() ) );
            }

            {
                StringBuilder b = new StringBuilder();
                string t = b.AppendMultiLine( "|", text, true, prefixLastEmptyLine: true ).ToString();
                Assert.That( t, Is.EqualTo( @"|First line.
|Second line.
|
|
|".NormalizeEOL() ) );
            }
        }
开发者ID:Invenietis,项目名称:ck-core,代码行数:26,代码来源:StringAndStringBuilderExtensionTests.cs

示例6: appending_multi_lines_with_a_prefix

        public void appending_multi_lines_with_a_prefix()
        {
            {
                StringBuilder b = new StringBuilder();
                string text = @"First line.
Second line.
    Indented.

    Also indented.
Last line.";
                // Here, normalizing the source embedded string is to support 
                // git clone with LF in files instead of CRLF. 
                // Our (slow) AppendMultiLine normalizes the end of lines to Environment.NewLine.
                string t = b.AppendMultiLine( "|", text, true ).ToString();
                Assert.That( t, Is.EqualTo( @"|First line.
|Second line.
|    Indented.
|
|    Also indented.
|Last line.".NormalizeEOL() ) );
            }

            {
                StringBuilder b = new StringBuilder();
                string text = @"First line.
Second line.
    Indented.

    Also indented.
Last line.";
                string t = b.AppendMultiLine( "|", text, false ).ToString();
                Assert.That( t, Is.EqualTo( @"First line.
|Second line.
|    Indented.
|
|    Also indented.
|Last line.".NormalizeEOL() ) );
            }

        }
开发者ID:Invenietis,项目名称:ck-core,代码行数:40,代码来源:StringAndStringBuilderExtensionTests.cs

示例7: appending_multi_lines_to_empty_lines

 public void appending_multi_lines_to_empty_lines()
 {
     {
         StringBuilder b = new StringBuilder();
         string text = Environment.NewLine;
         string t = b.AppendMultiLine( "|", text, true ).ToString();
         Assert.That( t, Is.EqualTo( "|" ) );
     }
     {
         StringBuilder b = new StringBuilder();
         string text = Environment.NewLine + Environment.NewLine;
         string t = b.AppendMultiLine( "|", text, true ).ToString();
         Assert.That( t, Is.EqualTo( "|" + Environment.NewLine + "|" ) );
     }
     {
         StringBuilder b = new StringBuilder();
         string text = Environment.NewLine + Environment.NewLine + Environment.NewLine;
         string t = b.AppendMultiLine( "|", text, true ).ToString();
         Assert.That( t, Is.EqualTo( "|" + Environment.NewLine + "|" + Environment.NewLine + "|" ) );
     }
     {
         StringBuilder b = new StringBuilder();
         string text = Environment.NewLine + Environment.NewLine + Environment.NewLine + "a";
         string t = b.AppendMultiLine( "|", text, true ).ToString();
         Assert.That( t, Is.EqualTo( "|" + Environment.NewLine + "|" + Environment.NewLine + "|" + Environment.NewLine + "|a" ) );
     }
 }
开发者ID:Invenietis,项目名称:ck-core,代码行数:27,代码来源:StringAndStringBuilderExtensionTests.cs


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