本文整理汇总了C#中Builder.AppendFormat方法的典型用法代码示例。如果您正苦于以下问题:C# Builder.AppendFormat方法的具体用法?C# Builder.AppendFormat怎么用?C# Builder.AppendFormat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Builder
的用法示例。
在下文中一共展示了Builder.AppendFormat方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FormatWithEmbeddedExpressions
private Builder FormatWithEmbeddedExpressions(Builder result, string format, object obj)
{
int i = 0;
while (i < format.Length)
{
char c = format[i++];
if (c == '{')
{
if (i >= 2 && format[i - 2] == '\\')
{
result.Append('{');
}
else
{
int expressionEnd = format.IndexOf('}', i);
bool noQuotes, callableOnly;
string memberName;
if (expressionEnd == -1 || (memberName = ParseSimpleMemberName(format, i, expressionEnd, out noQuotes, out callableOnly)) == null)
{
// the expression isn't properly formatted
result.Append(format, i - 1, format.Length - i + 1);
break;
}
Ref.MemberInfo member = ResolveMember(obj, memberName, callableOnly);
if (member == null)
{
result.AppendFormat(callableOnly ? "!<Method '{0}' not found>" : "!<Member '{0}' not found>", memberName);
}
else
{
Exception exception;
object value = GetMemberValue(member, obj, out exception);
if (exception != null)
{
FormatException(result, exception);
}
else
{
string name;
FormatObjectRecursive(result, value, !noQuotes, MemberDisplayFormat.NoMembers, out name);
}
}
i = expressionEnd + 1;
}
}
else
{
result.Append(c);
}
}
return result;
}
示例2: FormatWithEmbeddedExpressions
private Builder FormatWithEmbeddedExpressions(Builder result, string format, object obj)
{
int i = 0;
while (i < format.Length)
{
char c = format[i++];
if (c == '{')
{
if (i >= 2 && format[i - 2] == '\\')
{
result.Append('{');
}
else
{
int expressionEnd = format.IndexOf('}', i);
bool noQuotes, callableOnly;
string memberName;
if (expressionEnd == -1 || (memberName = ParseSimpleMemberName(format, i, expressionEnd, out noQuotes, out callableOnly)) == null)
{
// the expression isn't properly formatted
result.Append(format, i - 1, format.Length - i + 1);
break;
}
MemberInfo member = ResolveMember(obj, memberName, callableOnly);
if (member == null)
{
result.AppendFormat(callableOnly ? "!<Method '{0}' not found>" : "!<Member '{0}' not found>", memberName);
}
else
{
Exception exception;
object value = GetMemberValue(member, obj, out exception);
if (exception != null)
{
FormatException(result, exception);
}
else
{
MemberDisplayFormat oldMemberDisplayFormat = _memberDisplayFormat;
CommonPrimitiveFormatterOptions oldPrimitiveOptions = _primitiveOptions;
_memberDisplayFormat = MemberDisplayFormat.Hidden;
_primitiveOptions = new CommonPrimitiveFormatterOptions(
_primitiveOptions.NumberRadix,
_primitiveOptions.IncludeCharacterCodePoints,
quoteStringsAndCharacters: !noQuotes,
escapeNonPrintableCharacters: _primitiveOptions.EscapeNonPrintableCharacters,
cultureInfo: _primitiveOptions.CultureInfo);
string _;
FormatObjectRecursive(result, value, isRoot: false, debuggerDisplayName: out _);
_primitiveOptions = oldPrimitiveOptions;
_memberDisplayFormat = oldMemberDisplayFormat;
}
}
i = expressionEnd + 1;
}
}
else
{
result.Append(c);
}
}
return result;
}