public OptionList(Options optionBundle)
{
if (optionBundle == null)
throw new ArgumentNullException("optionBundle");
Type optionsType = optionBundle.GetType();
this.optionBundle = optionBundle;
parsingMode = optionBundle.ParsingMode;
breakSingleDashManyLettersIntoManyOptions = optionBundle.BreakSingleDashManyLettersIntoManyOptions;
endOptionProcessingWithDoubleDash = optionBundle.EndOptionProcessingWithDoubleDash;
ReportError = optionBundle.ReportError;
ExtractEntryAssemblyInfo(optionsType);
foreach(MemberInfo mi in optionsType.GetMembers())
{
object[] attribs = mi.GetCustomAttributes(typeof(KillOptionAttribute), true);
if (attribs == null || attribs.Length == 0)
{
attribs = mi.GetCustomAttributes(typeof(OptionAttribute), true);
if (attribs != null && attribs.Length > 0)
{
OptionDetails option = new OptionDetails(mi, (OptionAttribute) attribs[0], optionBundle);
list.Add(option);
HasSecondLevelHelp = HasSecondLevelHelp || option.SecondLevelHelp;
}
else if (mi.DeclaringType == mi.ReflectedType)
{
// not inherited
attribs = mi.GetCustomAttributes(typeof(ArgumentProcessorAttribute), true);
if (attribs != null && attribs.Length > 0)
AddArgumentProcessor(mi);
}
}
}
if (argumentProcessor == null) // try to find an inherited one
foreach(MemberInfo mi in optionsType.GetMembers())
if (mi.DeclaringType != mi.ReflectedType)
{
// inherited
object[] attribs = mi.GetCustomAttributes(typeof(ArgumentProcessorAttribute), true);
if (attribs != null && attribs.Length > 0)
AddArgumentProcessor(mi);
}
}