本文整理汇总了C#中StringBuilder.AppendIfNotEmpty方法的典型用法代码示例。如果您正苦于以下问题:C# StringBuilder.AppendIfNotEmpty方法的具体用法?C# StringBuilder.AppendIfNotEmpty怎么用?C# StringBuilder.AppendIfNotEmpty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringBuilder
的用法示例。
在下文中一共展示了StringBuilder.AppendIfNotEmpty方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ToText
public static string ToText(this MonsterAttackType attack, string delimiter)
{
var sb = new StringBuilder();
if (attack.IsEmpty) {
return String.Empty;
}
else if (attack.Damage.IsEmpty) {
sb.Append(attack.Description);
}
else {
sb.AppendIfNotEmpty(attack.ToString());
}
for (int i = 0; i < attack.FailedSavingThrows.Count; ++i) {
var failed = attack.FailedSavingThrows[i];
sb.AppendFormat("{0} {1} Failed Saving Throw: {2}", delimiter, (i + 1).ToIteration(), failed); // failed.ToHtml(power));
}
foreach (var sustain in attack.Sustains) {
sb.AppendFormat("{0} Sustain", delimiter);
sb.AppendFormatIfNotEmpty(" {0}", sustain.Action);
sb.AppendFormat(": {0}", sustain.Description); //sustain.ToHtml(power));
}
foreach (var attackInner in attack.Attacks) {
sb.AppendFormat("{0} {1}: {2}", delimiter, attackInner.Name, attackInner.Effect);
}
if (!attack.Damage.IsEmpty) {
foreach (var after in attack.AfterEffects) {
sb.AppendFormat("{0} Aftereffect: {1}", delimiter, after); //after.ToHtml(power));
}
}
return sb.ToString();
}
示例2: ToWwwAuthenticateHeaderParameter
/// <summary>
/// Returns the header parameter to be put into the HTTP WWW-Authenticate header. The field ts has the timestamp
/// in UNIX time corresponding to the server clock and the field tsm is the MAC calculated for the normalized
/// timestamp data using the shared symmetric key and the algorithm agreed upon.
/// </summary>
/// <returns></returns>
internal string ToWwwAuthenticateHeaderParameter()
{
Hasher hasher = new Hasher(credential.Algorithm);
byte[] data = this.ToString().ToBytesFromUtf8();
string tsm = hasher.ComputeHmac(data, credential.Key).ToBase64String();
char trailer = ',';
StringBuilder result = new StringBuilder();
result.AppendIfNotEmpty(TS, fresh.ToString(), trailer)
.AppendIfNotEmpty(TSM, tsm, trailer);
return result.ToString().Trim().Trim(trailer);
}
示例3: ToHeaderParameter
/// <summary>
/// Returns the serialized form of this object.
/// </summary>
/// <param name="includeClientArtifacts">If true, the client supplied artifacts of id, timestamp, and nonce are included.</param>
/// <returns></returns>
private string ToHeaderParameter(bool includeClientArtifacts)
{
char trailer = ',';
StringBuilder result = new StringBuilder();
if (includeClientArtifacts)
{
result
.AppendIfNotEmpty(ID, this.Id, trailer)
.AppendIfNotEmpty(TS, (this.Timestamp > 0 ? this.Timestamp.ToString() : String.Empty), trailer)
.AppendIfNotEmpty(NONCE, this.Nonce, trailer);
}
result
.AppendIfNotEmpty(EXT, this.ApplicationSpecificData, trailer)
.AppendIfNotEmpty(MAC, this.Mac == null ? null : this.Mac.ToBase64String(), trailer)
.AppendIfNotEmpty(HASH, this.PayloadHash == null ? null : this.PayloadHash.ToBase64String(), trailer);
return result.ToString()
.Trim().Trim(trailer); // Remove the trailing trailer and space for the last pair
}
示例4: JoinCore
private static void JoinCore(StringBuilder builder, IEnumerable<string> collection, string separator)
{
using (var enumerator = collection.GetEnumerator())
if (enumerator.MoveNext())
{
builder.AppendIfNotEmpty(enumerator.Current);
while (enumerator.MoveNext())
builder
.Append(separator)
.AppendIfNotEmpty(enumerator.Current);
}
}
示例5: Join
/// <summary>Concatenates the specified separator between each element of the specified collection of strings,
/// with an optional prefix and suffix, yielding a single concatenated string.</summary>
/// <param name="collection">The collection of elements to join.</param>
/// <param name="prefix">The optional prefix to concatenate before the first element.</param>
/// <param name="separator">The separator to concatenate between each element.</param>
/// <param name="suffix">The optional suffix to concatenate after the last element.</param>
/// <returns>The single concatenated string.</returns>
public static string Join(
this IEnumerable<string> collection,
string prefix,
string separator,
string suffix)
{
if (collection == null) throw new ArgumentNullException("collection");
StringBuilder builder = new StringBuilder();
builder.AppendIfNotEmpty(prefix);
if (separator.IsNullOrEmpty())
JoinCore(builder, collection);
else JoinCore(builder, collection, separator);
return builder.AppendIfNotEmpty(suffix).ToString();
}
示例6: CreateWhereClause
// internal to allow unit testing
internal StringBuilder CreateWhereClause(EntityParameterCollection parameters)
{
Debug.Assert(parameters != null, "parameters != null");
var whereClause = new StringBuilder();
foreach (var alias in _filterAliases)
{
var allows = new StringBuilder();
var excludes = new StringBuilder();
foreach (var entry in _filters)
{
if (entry.Effect == EntityStoreSchemaFilterEffect.Allow)
{
AppendFilterEntry(allows, alias, entry, parameters);
}
else
{
Debug.Assert(entry.Effect == EntityStoreSchemaFilterEffect.Exclude, "did you add new value?");
AppendFilterEntry(excludes, alias, entry, parameters);
}
}
if (allows.Length != 0)
{
// AND appended if this is not the first condition
whereClause
.AppendIfNotEmpty(Environment.NewLine)
.AppendIfNotEmpty("AND")
.AppendIfNotEmpty(Environment.NewLine);
whereClause
.Append("(")
.Append(allows)
.Append(")");
}
if (excludes.Length != 0)
{
// AND appended if this is not the first condition
whereClause
.AppendIfNotEmpty(Environment.NewLine)
.AppendIfNotEmpty("AND")
.AppendIfNotEmpty(Environment.NewLine);
whereClause
.Append("NOT (")
.Append(excludes)
.Append(")");
}
}
return whereClause;
}
示例7: AppendComparisonFragment
private static void AppendComparisonFragment(
StringBuilder filterFragment, string alias, string propertyName, string parameterName)
{
Debug.Assert(filterFragment != null, "filterFragment != null");
Debug.Assert(alias != null, "alias != null");
Debug.Assert(propertyName != null, "propertyName != null");
filterFragment
.AppendIfNotEmpty(" AND ")
.Append(alias)
.Append(".")
.Append(propertyName)
.Append(" LIKE @")
.Append(parameterName);
}
示例8: AppendFilterEntry
// internal to allow unit testing
internal static StringBuilder AppendFilterEntry(
StringBuilder segment, string alias, EntityStoreSchemaFilterEntry entry, EntityParameterCollection parameters)
{
Debug.Assert(segment != null, "segment != null");
Debug.Assert(alias != null, "alias != null");
Debug.Assert(entry != null, "entry != null");
Debug.Assert(parameters != null, "parameters != null");
var filterText = new StringBuilder();
AppendComparison(filterText, alias, "CatalogName", entry.Catalog, parameters);
AppendComparison(filterText, alias, "SchemaName", entry.Schema, parameters);
AppendComparison(
filterText, alias, "Name",
entry.Catalog == null && entry.Schema == null && entry.Name == null ? "%" : entry.Name,
parameters);
segment
.AppendIfNotEmpty(" OR ")
.Append("(")
.Append(filterText)
.Append(")");
return segment;
}
示例9: ToString
public override string ToString()
{
var sb = new StringBuilder();
sb.AppendLine( " Type: " + Type );
sb.AppendLine( "SaveIndex: " + SaveIndex );
sb.AppendLine( " Name: " + Name );
sb.AppendLine( " Gender: " + Gender );
sb.AppendLine( "Public ID: " + PublicId );
sb.AppendLine( "Secret ID: " + SecretId );
sb.AppendLine( " Key: " + SecurityKey );
sb.AppendLine( " Time: " + TimePlayed );
sb.AppendLine( " Gamecode: " + GameCode );
sb.AppendLine( " Money: " + Money );
sb.AppendLine( " Rival: " + Rival );
sb.AppendLine( "Teamsize:\t" + TeamSize );
for( int i = 0; i < Team.Count; i++ )
sb.AppendIfNotEmpty( Team[i].Brief(), i );
sb.AppendLine( "PC Items:" );
for( int i = 0; i < PCItems.Count; i++ )
sb.AppendIfNotEmpty( PCItems[i].ToString(), i );
sb.AppendLine( "Bag Items:" );
for( int i = 0; i < Items.Count; i++ )
sb.AppendIfNotEmpty( Items[i].ToString(), i );
sb.AppendLine( "Key Items:" );
for( int i = 0; i < KeyItems.Count; i++ )
sb.AppendIfNotEmpty( KeyItems[i].ToString(), i );
sb.AppendLine( "Ball pocket:" );
for( int i = 0; i < BallPocket.Count; i++ )
sb.AppendIfNotEmpty( BallPocket[i].ToString(), i );
sb.AppendLine( "TM case:" );
for( int i = 0; i < TMCase.Count; i++ )
sb.AppendIfNotEmpty( TMCase[i].ToString(), i );
sb.AppendLine( "Berries:" );
for( int i = 0; i < Berries.Count; i++ )
sb.AppendIfNotEmpty( Berries[i].ToString(), i );
sb.AppendLine( "PC buffer:" );
string pre = string.Empty;
for( int i = 0; i < PcBuffer.Count; i++ )
{
if( i % 30 == 0 )
pre = "PC Box #" + Math.Floor( i / 30.0 );
if( sb.AppendIfNotEmpty( PcBuffer[i].Brief(), i, pre ) )
pre = string.Empty;
}
return sb.ToString();
}