Exemple #1
0
 private static string HelpText(ArgumentAttribute attribute)
 {
     if (attribute == null)
     {
         return(null);
     }
     else
     {
         return(attribute.HelpText);
     }
 }
Exemple #2
0
        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);
        }
Exemple #3
0
 private static ArgumentType Flags(ArgumentAttribute attribute, FieldInfo field)
 {
     if (attribute != null)
     {
         return(attribute.Type);
     }
     else if (IsCollectionType(field.FieldType))
     {
         return(ArgumentType.MultipleUnique);
     }
     else
     {
         return(ArgumentType.AtMostOnce);
     }
 }
Exemple #4
0
        /// <summary>
        /// Initializes a new instance of the Parser class.
        /// 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)
        {
            if (argumentSpecification == null)
            {
                throw new ArgumentNullException("argumentSpecification");
            }

            this.reporter    = reporter;
            this.arguments   = new ArrayList();
            this.argumentMap = new Hashtable();

            foreach (FieldInfo field in argumentSpecification.GetFields())
            {
                if (!field.IsStatic && !field.IsInitOnly && !field.IsLiteral)
                {
                    ArgumentAttribute attribute = GetAttribute(field);
                    if (attribute is DefaultArgumentAttribute)
                    {
                        Debug.Assert(this.defaultArgument == null, "The default Argument.");
                        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)
            {
                Debug.Assert(!this.argumentMap.ContainsKey(argument.LongName), "Long name");
                this.argumentMap[argument.LongName] = argument;
                if (argument.ExplicitShortName)
                {
                    if (argument.ShortName != null && argument.ShortName.Length > 0)
                    {
                        Debug.Assert(!this.argumentMap.ContainsKey(argument.ShortName), "Short Name");
                        this.argumentMap[argument.ShortName] = argument;
                    }
                    else
                    {
                        argument.ClearShortName();
                    }
                }
            }

            // add implicit names which don't collide to map
            foreach (Argument argument in this.arguments)
            {
                if (!argument.ExplicitShortName)
                {
                    if (argument.ShortName != null && argument.ShortName.Length > 0 && !this.argumentMap.ContainsKey(argument.ShortName))
                    {
                        this.argumentMap[argument.ShortName] = argument;
                    }
                    else
                    {
                        argument.ClearShortName();
                    }
                }
            }
        }
Exemple #5
0
 private static object DefaultValue(ArgumentAttribute attribute)
 {
     return((attribute == null || !attribute.HasDefaultValue) ? null : attribute.DefaultValue);
 }
Exemple #6
0
 private static bool ExplicitShortName(ArgumentAttribute attribute)
 {
     return(attribute != null && !attribute.DefaultShortName);
 }
Exemple #7
0
 private static bool HasHelpText(ArgumentAttribute attribute)
 {
     return(attribute != null && attribute.HasHelpText);
 }
Exemple #8
0
 private static string LongName(ArgumentAttribute attribute, FieldInfo field)
 {
     return((attribute == null || attribute.DefaultLongName) ? field.Name : attribute.LongName);
 }