public Argument(CommandLineArgumentAttribute attribute, FieldInfo field, ErrorReporter reporter)
            {
                this.longName          = CommandLineArgumentParser.LongName(attribute, field);
                this.explicitShortName = CommandLineArgumentParser.ExplicitShortName(attribute);
                this.shortName         = CommandLineArgumentParser.ShortName(attribute, field);
                this.elementType       = ElementType(field);
                this.flags             = Flags(attribute, field);
                this.field             = field;
                this.seenValue         = false;
                this.reporter          = reporter;
                this.isDefault         = attribute != null && attribute is DefaultCommandLineArgumentAttribute;
                this.description       = attribute.Description;

                if (IsCollection)
                {
                    this.collectionValues = new ArrayList();
                }

                Debug.Assert(this.longName != null && this.longName.Length > 0);
                if (IsCollection && !AllowMultiple)
                {
                    ThrowError("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));
            }
        /// <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 CommandLineArgumentParser(Type argumentSpecification, ErrorReporter reporter)
        {
            this.reporter    = reporter;
            this.arguments   = new ArrayList();
            this.argumentMap = new Hashtable();

            foreach (FieldInfo field in argumentSpecification.GetFields())
            {
                if (!field.IsStatic && !field.IsInitOnly && !field.IsLiteral)
                {
                    CommandLineArgumentAttribute attribute = GetAttribute(field);
                    if (attribute is DefaultCommandLineArgumentAttribute)
                    {
                        if (this.defaultArgument != null)
                        {
                            ThrowError("More that one DefaultCommandLineArgument has been used");
                        }
                        this.defaultArgument = new Argument(attribute, field, reporter);
                    }
                    else
                    {
                        this.arguments.Add(new Argument(attribute, field, reporter));
                    }
                }
            }

            // add explicit names to map
            foreach (Argument argument in this.arguments)
            {
                if (argumentMap.ContainsKey(argument.LongName))
                {
                    ThrowError("Argument {0} is duplicated", argument.LongName);
                }
                this.argumentMap[argument.LongName] = argument;
                if (argument.ExplicitShortName && argument.ShortName != null && argument.ShortName.Length > 0)
                {
                    if (this.argumentMap.ContainsKey(argument.ShortName))
                    {
                        ThrowError("Argument {0} is duplicated", argument.ShortName);
                    }
                    this.argumentMap[argument.ShortName] = argument;
                }
            }

            // add implicit names which don't collide to map
            foreach (Argument argument in this.arguments)
            {
                if (!argument.ExplicitShortName && argument.ShortName != null && argument.ShortName.Length > 0)
                {
                    if (!argumentMap.ContainsKey(argument.ShortName))
                    {
                        this.argumentMap[argument.ShortName] = argument;
                    }
                }
            }
        }
 private static CommandLineArgumentType Flags(CommandLineArgumentAttribute attribute, FieldInfo field)
 {
     if (attribute != null)
     {
         return(attribute.Type);
     }
     else if (IsCollectionType(field.FieldType))
     {
         return(CommandLineArgumentType.MultipleUnique);
     }
     else
     {
         return(CommandLineArgumentType.AtMostOnce);
     }
 }
			public Argument(CommandLineArgumentAttribute attribute, FieldInfo field, ErrorReporter reporter)
			{
				this.longName = CommandLineArgumentParser.LongName(attribute, field);
				this.explicitShortName = CommandLineArgumentParser.ExplicitShortName(attribute);
				this.shortName = CommandLineArgumentParser.ShortName(attribute, field);
				this.elementType = ElementType(field);
				this.flags = Flags(attribute, field);
				this.field = field;
				this.seenValue = false;
				this.reporter = reporter;
				this.isDefault = attribute != null && attribute is DefaultCommandLineArgumentAttribute;
				this.description=attribute.Description;
                
				if (IsCollection)
				{
					this.collectionValues = new ArrayList();
				}
                
				Debug.Assert(this.longName != null && this.longName.Length > 0);
				if (IsCollection && !AllowMultiple)
					ThrowError("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));
			}
		private static CommandLineArgumentType Flags(CommandLineArgumentAttribute attribute, FieldInfo field)
		{
			if (attribute != null)
				return attribute.Type;
			else if (IsCollectionType(field.FieldType))
				return CommandLineArgumentType.MultipleUnique;
			else
				return CommandLineArgumentType.AtMostOnce;
		}
		private static bool ExplicitShortName(CommandLineArgumentAttribute attribute)
		{
			return (attribute != null && !attribute.DefaultShortName);
		}
		private static string ShortName(CommandLineArgumentAttribute attribute, FieldInfo field)
		{
			return !ExplicitShortName(attribute) ? LongName(attribute, field).Substring(0,1) : attribute.ShortName;
		}
		private static string LongName(CommandLineArgumentAttribute attribute, FieldInfo field)
		{
			return (attribute == null || attribute.DefaultLongName) ? field.Name : attribute.LongName;
		}
 private static bool ExplicitShortName(CommandLineArgumentAttribute attribute)
 {
     return(attribute != null && !attribute.DefaultShortName);
 }
 private static string ShortName(CommandLineArgumentAttribute attribute, FieldInfo field)
 {
     return(!ExplicitShortName(attribute) ? LongName(attribute, field).Substring(0, 1) : attribute.ShortName);
 }
 private static string LongName(CommandLineArgumentAttribute attribute, FieldInfo field)
 {
     return((attribute == null || attribute.DefaultLongName) ? field.Name : attribute.LongName);
 }