本文整理汇总了C#中Argument.Format方法的典型用法代码示例。如果您正苦于以下问题:C# Argument.Format方法的具体用法?C# Argument.Format怎么用?C# Argument.Format使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Argument
的用法示例。
在下文中一共展示了Argument.Format方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryGetDefaultValueString
/// <summary>
/// Tries to construct a string describing the argument's default value.
/// </summary>
/// <param name="setAttribute">Metadata regarding the argument set
/// containing this argument.</param>
/// <param name="arg">The argument to retrieve a default value string
/// from.</param>
/// <returns>If one should be advertised, returns the string version of
/// the default value for this argument; otherwise, returns null.
/// </returns>
private static string TryGetDefaultValueString(ArgumentSetAttribute setAttribute, Argument arg)
{
// Firstly, if the argument is required, then there's no need to
// indicate any default value.
if (arg.IsRequired)
{
return null;
}
// Next, go check for the actual *effective* default value for the
// argument; we may still receive back a value here even if one
// wasn't explicitly declared, as we will have consulted with the
// argument's type to determine its default value.
var defaultValue = arg.EffectiveDefaultValue;
// If the default value is null, then that's not useful to show the
// user.
if (defaultValue == null)
{
return null;
}
// Special case: if the argument type is bool, then the argument
// will be like a switch, and that's typically assumed to be false
// if not present. So if the default value is indeed 'false', then
// don't bother displaying it; but if it's 'true', then it's
// important to indicate that.
if ((defaultValue is bool) && !((bool)defaultValue))
{
return null;
}
// Special case: if the argument type is string, then it's safe
// to assume that its default value is an empty string.
var stringDefaultValue = defaultValue as string;
if ((stringDefaultValue != null) && string.IsNullOrEmpty(stringDefaultValue))
{
return null;
}
// At this point, it's probably important to display the default
// value.
var formattedArg = arg.Format(setAttribute, defaultValue, suppressArgNames: true).ToList();
if (formattedArg.Count == 0)
{
return null;
}
return string.Join(" ", formattedArg);
}