本文整理汇总了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( @"" ) );
}
}
示例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 + " └─────────────────────────────────────────────────────────────────────────" );
}
//.........这里部分代码省略.........
示例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;
}
示例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;
}
示例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() ) );
}
}
示例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() ) );
}
}
示例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" ) );
}
}