/////////////////////////////////////////////////////////////////////// public static bool SetPresent( OptionDictionary options, string name, bool present, int index, Variant value ) { if (options != null) { if (name != null) { IOption option; if (options.TryGetValue(name, out option)) { if (option != null) { option.SetPresent(options, present, index, value); return(true); } } } } return(false); }
/////////////////////////////////////////////////////////////////////// #region Option Lookup Methods private static bool TryResolveSimple( OptionDictionary options, string name, bool verbose, ref IOption option, ref Result error ) { if (options == null) { error = "invalid options"; return(false); } if (name == null) { error = "invalid option name"; return(false); } if (!options.TryGetValue(name, out option)) { error = BadOption(verbose ? options : null, name); return(false); } if (option == null) { error = String.Format("invalid option \"{0}\"", name); return(false); } return(true); }
/////////////////////////////////////////////////////////////////////// #region Private private static bool IsPresent( OptionDictionary options, string name, bool noCase, bool strict, ref Variant value, ref int index ) { if (options != null) { if (name != null) { if (noCase) { // // HACK: Perform a linear search of the options. We // should not need to do this since the options // are in a dictionary; however, we want to // preserve the "case-sensitive" semantics unless // otherwise requested by the caller. // bool found = false; foreach (KeyValuePair <string, IOption> pair in options) { if (String.Compare(pair.Key, 0, name, 0, name.Length, StringOps.SystemNoCaseStringComparisonType) == 0) { found = true; IOption option = pair.Value; if ((option != null) && option.IsPresent(options, ref value)) { index = option.Index; return(true); } } } if (strict && !found) { // // NOTE: This should not really happen, issue a // debug trace. // TraceOps.DebugTrace(String.Format( "IsPresent: {0}", BadOption(options, name)), typeof(OptionDictionary).Name, TracePriority.Command); } } else { IOption option; if (options.TryGetValue(name, out option)) { if ((option != null) && option.IsPresent(options, ref value)) { index = option.Index; return(true); } } else if (strict) { // // NOTE: This should not really happen, issue a // debug trace. // TraceOps.DebugTrace(String.Format( "IsPresent: {0}", BadOption(options, name)), typeof(OptionDictionary).Name, TracePriority.Command); } } } } return(false); }