public Argument(ArgumentAttribute attribute, FieldInfo field, ErrorReporter reporter) { longName = Parser.LongName(attribute, field); explicitShortName = Parser.ExplicitShortName(attribute); shortName = Parser.ShortName(attribute, field); hasHelpText = Parser.HasHelpText(attribute); helpText = Parser.HelpText(attribute, field); defaultValue = Parser.DefaultValue(attribute, field); elementType = ElementType(field); flags = Flags(attribute, field); this.field = field; seenValue = false; this.reporter = reporter; isDefault = (attribute != null && attribute is DefaultArgumentAttribute); if (IsCollection) { collectionValues = new ArrayList(); } Debug.Assert(longName != null && longName != ""); Debug.Assert(!isDefault || !ExplicitShortName); Debug.Assert(!IsCollection || AllowMultiple, "Collection arguments must have allow multiple"); Debug.Assert(!Unique || IsCollection, "Unique only applicable to collection arguments"); Debug.Assert(IsValidElementType(Type) || IsCollectionType(Type)); Debug.Assert((IsCollection && IsValidElementType(elementType)) || (!IsCollection && elementType == null)); Debug.Assert(!IsRequired || !HasDefaultValue, "Required arguments cannot have default value"); Debug.Assert(!HasDefaultValue || defaultValue.GetType() == field.FieldType, "Type of default value must match field type"); }
static string LongName(ArgumentAttribute attribute, FieldInfo field) { return (attribute == null || attribute.DefaultLongName) ? field.Name : attribute.LongName; }
static string ShortName(ArgumentAttribute attribute, FieldInfo field) { string result; if (attribute is DefaultArgumentAttribute) { result = null; } else { if (!ExplicitShortName(attribute)) { result = LongName(attribute, field).Substring(0, 1); } else { result = attribute.ShortName; } } return result; }
static string HelpText(ArgumentAttribute attribute, FieldInfo field) { string result; if (attribute == null) { result = null; } else { result = attribute.HelpText; } return result; }
static bool HasHelpText(ArgumentAttribute attribute) { return attribute != null && attribute.HasHelpText; }
static ArgumentType Flags(ArgumentAttribute attribute, FieldInfo field) { ArgumentType result; if (attribute != null) { result = attribute.Type; } else { if (IsCollectionType(field.FieldType)) { result = ArgumentType.MultipleUnique; } else { result = ArgumentType.AtMostOnce; } } return result; }
static bool ExplicitShortName(ArgumentAttribute attribute) { return attribute != null && !attribute.DefaultShortName; }
static object DefaultValue(ArgumentAttribute attribute, FieldInfo field) { return (attribute == null || !attribute.HasDefaultValue) ? null : attribute.DefaultValue; }