}//private bool LexFileArguments( String fileName, out String[] arguments ) private static String LongName ( CommandLineArgumentAttribute commandLineArgumentAttribute, FieldInfo fieldInfo ) { return (commandLineArgumentAttribute == null || commandLineArgumentAttribute.DefaultLongName) ? fieldInfo.Name : commandLineArgumentAttribute.LongName; }//private static String LongName
/// <summary> /// Creates a new command line argument parser. /// </summary> /// <param name="argumentSpecification"> The type of object to parse. </param> /// <param name="errorReporter"> The destination for parse errors. </param> public CommandLineArgumentParser ( Type argumentSpecification, ErrorReporter errorReporter ) { this.errorReporter = errorReporter; this.arguments = new ArrayList(); this.argumentMap = new Hashtable(); foreach (FieldInfo fieldInfo in argumentSpecification.GetFields()) { if (!fieldInfo.IsStatic && !fieldInfo.IsInitOnly && !fieldInfo.IsLiteral) { CommandLineArgumentAttribute attribute = GetAttribute(fieldInfo); if (attribute is DefaultCommandLineArgumentAttribute) { Debug.Assert(this.defaultArgument == null); this.defaultArgument = new Argument(attribute, fieldInfo, errorReporter ); }//if (attribute is DefaultCommandLineArgumentAttribute) else { this.arguments.Add(new Argument(attribute, fieldInfo, errorReporter )); }//else (attribute is DefaultCommandLineArgumentAttribute) }//if (!fieldInfo.IsStatic && !fieldInfo.IsInitOnly && !fieldInfo.IsLiteral) }//foreach (FieldInfo fieldInfo in argumentSpecification.GetFields()) // add explicit names to map foreach (Argument argument in this.arguments) { Debug.Assert(!argumentMap.ContainsKey(argument.LongName)); this.argumentMap[argument.LongName] = argument; if (argument.ExplicitShortName && argument.ShortName != null && argument.ShortName.Length > 0) { Debug.Assert(!argumentMap.ContainsKey(argument.ShortName)); this.argumentMap[argument.ShortName] = argument; }//if (argument.ExplicitShortName && argument.ShortName != null && argument.ShortName.Length > 0) }//foreach (Argument argument in this.arguments) // 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; }//if (!argumentMap.ContainsKey(argument.ShortName)) }//if (!argument.ExplicitShortName && argument.ShortName != null && argument.ShortName.Length > 0) }//foreach (Argument argument in this.arguments) }//public CommandLineArgumentParser(Type argumentSpecification, ErrorReporter reporter)