本文整理汇总了C#中System.Reflection.PropertyInfo.GetArgumentName方法的典型用法代码示例。如果您正苦于以下问题:C# PropertyInfo.GetArgumentName方法的具体用法?C# PropertyInfo.GetArgumentName怎么用?C# PropertyInfo.GetArgumentName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.PropertyInfo
的用法示例。
在下文中一共展示了PropertyInfo.GetArgumentName方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetShortcut
public static string GetShortcut(PropertyInfo info)
{
var actionProperty = ArgAction.GetActionProperty(info.DeclaringType);
if (actionProperty != null && actionProperty.Name == info.Name) return null;
var attr = info.Attr<ArgShortcut>();
if (attr == null) return info.GetArgumentName()[0] + "";
else return attr.Shortcut;
}
示例2: ValidateAlways
/// <summary>
/// Validates that the user actually specified a value and optionally prompts them when it is missing.
/// </summary>
/// <param name="prop">The property being populated. This validator doesn't do anything with it.</param>
/// <param name="arg">The value specified on the command line or null if it wasn't specified</param>
public override void ValidateAlways(PropertyInfo prop, ref string arg)
{
if (arg == null && PromptIfMissing)
{
var value = "";
while (string.IsNullOrWhiteSpace(value))
{
Console.Write("Enter value for " + prop.GetArgumentName() + ": ");
value = Console.ReadLine();
}
arg = value;
}
if (arg == null)
{
throw new MissingArgException("The argument '" + prop.GetArgumentName() + "' is required", new ArgumentNullException(prop.GetArgumentName()));
}
}
示例3: GetShortcutInternal
private static string GetShortcutInternal(PropertyInfo info, List<string> knownShortcuts)
{
var actionProperty = ArgAction.GetActionProperty(info.DeclaringType);
if (actionProperty != null && actionProperty.Name == info.Name) return null;
var attr = info.Attr<ArgShortcut>();
if (attr == null)
{
string shortcutVal = "";
foreach (char c in info.GetArgumentName())
{
shortcutVal += c;
if (knownShortcuts.Contains(shortcutVal) == false) return shortcutVal;
}
return shortcutVal;
}
else
{
if (attr.policy.HasValue && attr.policy.Value == ArgShortcutPolicy.NoShortcut && attr.Shortcut != null)
{
throw new InvalidArgDefinitionException("You cannot specify a shortcut value and an ArgShortcutPolicy of NoShortcut");
}
if (attr.Shortcut == null) return null;
if (attr.Shortcut.StartsWith("-")) attr.Shortcut = attr.Shortcut.Substring(1);
else if (attr.Shortcut.StartsWith("/")) attr.Shortcut = attr.Shortcut.Substring(1);
return attr.Shortcut;
}
}
示例4: FindShortcutsInternal
private static List<string> FindShortcutsInternal(PropertyInfo info, List<string> knownShortcuts)
{
var actionProperty = ArgAction.GetActionProperty(info.DeclaringType);
if (actionProperty != null && actionProperty.Name == info.Name) return new List<string>();
var attrs = info.Attrs<ArgShortcut>();
if (attrs.Count == 0)
{
string shortcutVal = "";
foreach (char c in info.GetArgumentName())
{
shortcutVal += c;
if (knownShortcuts.Contains(shortcutVal) == false) return new List<string>{ shortcutVal };
}
return new List<string> { shortcutVal };
}
else
{
List<string> ret = new List<string>();
bool noShortcut = false;
foreach (var attr in attrs)
{
if (attr.policy.HasValue && attr.policy.Value == ArgShortcutPolicy.NoShortcut)
{
noShortcut = true;
}
if (noShortcut && attr.Shortcut != null)
{
throw new InvalidArgDefinitionException("You cannot specify a shortcut value and an ArgShortcutPolicy of NoShortcut");
}
if (attr.Shortcut != null)
{
if (attr.Shortcut.StartsWith("-")) attr.Shortcut = attr.Shortcut.Substring(1);
else if (attr.Shortcut.StartsWith("/")) attr.Shortcut = attr.Shortcut.Substring(1);
}
if (attr.Shortcut != null)
{
ret.Add(attr.Shortcut);
}
}
return ret;
}
}
示例5: FindShortcutsInternal
private static List<string> FindShortcutsInternal(PropertyInfo info, List<string> knownShortcuts)
{
var actionProperty = ArgAction.GetActionProperty(info.DeclaringType);
if (actionProperty != null && actionProperty.Name == info.Name) return new List<string>();
var attrs = info.Attrs<ArgShortcut>();
bool ignoreCase = true;
if (info.DeclaringType.HasAttr<ArgIgnoreCase>() && info.DeclaringType.Attr<ArgIgnoreCase>().IgnoreCase == false) ignoreCase = false;
if (attrs.Count == 0)
{
string shortcutVal = "";
foreach (char c in info.GetArgumentName().Substring(0, info.GetArgumentName().Length-1))
{
shortcutVal += c;
if (knownShortcuts.Contains(shortcutVal) == false) return new List<string>{ ignoreCase ? shortcutVal.ToLower() : shortcutVal };
}
return new List<string>();
}
else
{
List<string> ret = new List<string>();
foreach (var attr in attrs.OrderBy(a => a.Shortcut == null ? 0 : a.Shortcut.Length))
{
bool noShortcut = false;
if (attr.Policy == ArgShortcutPolicy.NoShortcut)
{
noShortcut = true;
}
if (noShortcut && attr.Shortcut != null)
{
throw new InvalidArgDefinitionException("You cannot specify a shortcut value and an ArgShortcutPolicy of NoShortcut");
}
if (attr.Shortcut != null)
{
if (attr.Shortcut.StartsWith("-")) attr.Shortcut = attr.Shortcut.Substring(1);
else if (attr.Shortcut.StartsWith("/")) attr.Shortcut = attr.Shortcut.Substring(1);
}
if (attr.Shortcut != null)
{
ret.Add(ignoreCase ? attr.Shortcut.ToLower() : attr.Shortcut);
}
}
return ret;
}
}
示例6: GetShortcutInternal
private static string GetShortcutInternal(PropertyInfo info, List<string> knownShortcuts)
{
var actionProperty = ArgAction.GetActionProperty(info.DeclaringType);
if (actionProperty != null && actionProperty.Name == info.Name) return null;
var attr = info.Attr<ArgShortcut>();
if (attr == null)
{
string shortcutVal = "";
foreach (char c in info.GetArgumentName())
{
shortcutVal += c;
if (knownShortcuts.Contains(shortcutVal) == false) return shortcutVal;
}
return shortcutVal;
}
else
{
if (attr.Shortcut == null) return null;
if (attr.Shortcut.StartsWith("-")) attr.Shortcut = attr.Shortcut.Substring(1);
else if (attr.Shortcut.StartsWith("/")) attr.Shortcut = attr.Shortcut.Substring(1);
return attr.Shortcut;
}
}