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


C# Argument.Format方法代码示例

本文整理汇总了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);
        }
开发者ID:reubeno,项目名称:NClap,代码行数:60,代码来源:ArgumentUsageInfo.cs


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