/// <summary> /// Obtains an Array of <see cref="Option"/>s from a <see cref="IDictionary"/>. /// </summary> /// <param name="dictionary"></param> /// <returns></returns> public static OptionCollection FromDictionary(IDictionary dictionary) { if (dictionary == null) { throw new ArgumentNullException("dictionary"); } List <Option> opts = new List <Option>(); foreach (DictionaryEntry entry in dictionary) { opts.Add(Option.FromDictionaryEntry(entry)); } OptionCollection result = new OptionCollection(opts); return(result); }
/// <summary> /// Determines whether the specified object is equal to the current object. /// </summary> /// <param name="other"></param> /// <returns></returns> public bool Equals(OptionCollection other) { if (other is null) { return(false); } if (Count != other.Count) { return(false); } for (int i = 0; i < items.Count; i++) { if (!items[i].Equals(other.items[i])) { return(false); } } return(true); }
/// <summary>Obtains an Array of <see cref="Option" />s from a specified string Array.</summary> /// <param name="lines">The strings to obtain Options from.</param> /// <param name="ignoreInvalid">if set to <c>true</c> [ignore invalid options].</param> /// <returns></returns> /// <exception cref="ArgumentNullException">texts.</exception> public static OptionCollection FromStrings(string[] lines, bool ignoreInvalid = false) { if (lines == null) { throw new ArgumentNullException("texts"); } List <Option> opts = new List <Option>(); foreach (string line in lines) { if (ignoreInvalid && !Option.IsOption(line)) { continue; } opts.Add(Option.Parse(line)); } OptionCollection result = new OptionCollection(opts); return(result); }