private static object DefaultValue(ArgumentAttribute attribute, FieldInfo field) { if ((attribute != null) && attribute.HasDefaultValue) { return(attribute.DefaultValue); } return(null); }
private static string ShortName(ArgumentAttribute attribute, FieldInfo field) { if (attribute is DefaultArgumentAttribute) { return(null); } if (!ExplicitShortName(attribute)) { return(LongName(attribute, field).Substring(0, 1)); } return(attribute.ShortName); }
private static ArgumentType Flags(ArgumentAttribute attribute, FieldInfo field) { if (attribute != null) { return(attribute.Type); } if (IsCollectionType(field.FieldType)) { return(ArgumentType.MultipleUnique); } return(ArgumentType.AtMostOnce); }
/// <summary> /// Creates a new command line argument parser. /// </summary> /// <param name="argumentSpecification"> The type of object to parse. </param> /// <param name="reporter"> The destination for parse errors. </param> public Parser(Type argumentSpecification, ErrorReporter reporter) { this.reporter = reporter; this.arguments = new ArrayList(); this.argumentMap = new Hashtable(); foreach (FieldInfo info in argumentSpecification.GetFields()) { if ((!info.IsStatic && !info.IsInitOnly) && !info.IsLiteral) { ArgumentAttribute attribute = GetAttribute(info); if (attribute is DefaultArgumentAttribute) { this.defaultArgument = new Argument(attribute, info, reporter); } else { this.arguments.Add(new Argument(attribute, info, reporter)); } } } foreach (Argument argument in this.arguments) { this.argumentMap[argument.LongName] = argument; if (argument.ExplicitShortName) { if ((argument.ShortName != null) && (argument.ShortName.Length > 0)) { this.argumentMap[argument.ShortName] = argument; } else { argument.ClearShortName(); } } } foreach (Argument argument2 in this.arguments) { if (!argument2.ExplicitShortName) { if (((argument2.ShortName != null) && (argument2.ShortName.Length > 0)) && !this.argumentMap.ContainsKey(argument2.ShortName)) { this.argumentMap[argument2.ShortName] = argument2; } else { argument2.ClearShortName(); } } } }
public Argument(ArgumentAttribute attribute, FieldInfo field, ErrorReporter reporter) { this.longName = Parser.LongName(attribute, field); this.explicitShortName = Parser.ExplicitShortName(attribute); this.shortName = Parser.ShortName(attribute, field); this.hasHelpText = Parser.HasHelpText(attribute); this.helpText = Parser.HelpText(attribute, field); this.defaultValue = Parser.DefaultValue(attribute, field); this.elementType = Parser.ElementType(field); this.flags = Parser.Flags(attribute, field); this.field = field; this.seenValue = false; this.reporter = reporter; this.isDefault = (attribute != null) && (attribute is DefaultArgumentAttribute); this.isToggle = attribute.IsToggle; if (this.IsCollection) { this.collectionValues = new ArrayList(); } }
private static bool HasHelpText(ArgumentAttribute attribute) { return((attribute != null) && attribute.HasHelpText); }
private static bool ExplicitShortName(ArgumentAttribute attribute) { return((attribute != null) && !attribute.DefaultShortName); }