private static void SetParserStateIfNeeded(object options, OptionInfo option, bool? required, bool? mutualExclusiveness) { var list = ReflectionUtil.RetrievePropertyList<ParserStateAttribute>(options); if (list.Count == 0) { return; } var property = list[0].Left; // This method can be called when parser state is still not intialized if (property.GetValue(options, null) == null) { property.SetValue(options, new CommandLine.ParserState(), null); } var parserState = (IParserState)property.GetValue(options, null); if (parserState == null) { return; } var error = new ParsingError { BadOption = { ShortName = option.ShortName, LongName = option.LongName } }; if (required != null) { error.ViolatesRequired = required.Value; } if (mutualExclusiveness != null) { error.ViolatesMutualExclusiveness = mutualExclusiveness.Value; } parserState.Errors.Add(error); }
private static void BuildAndSetPostParsingStateIfNeeded(object options, OptionInfo option, bool? required, bool? mutualExclusiveness) { if (options is CommandLineOptionsBase) { ParsingError error = new ParsingError(); //if (option != null) //{ error.BadOption.ShortName = option.ShortName; //error.BadOptionShortName = option.ShortName; error.BadOption.LongName = option.LongName; //error.BadOptionLongName = option.LongName; //} if (required != null) error.ViolatesRequired = required.Value; if (mutualExclusiveness != null) error.ViolatesMutualExclusiveness = mutualExclusiveness.Value; ((CommandLineOptionsBase)options).InternalLastPostParsingState.Errors.Add(error); } }