/// <summary> /// Gets a new <see cref="HotstringSelectedOptions"/> instance containing the selected values of <paramref name="ListItems"/> /// </summary> /// <param name="ListItems">The list containing one or more Selected Items to add to the list</param> /// <returns> /// A new Instance of <see cref="HotstringSelectedOptions"/> with the values that were marked as Selected in the /// <paramref name="ListItems"/> /// </returns> /// <remarks> /// Only <see cref="mapItem"/> items that have <see cref="mapItem.Selected"/> set to true /// will be included in the <see cref="HotstringSelectedOptions"/> instance. /// </remarks> public static HotstringSelectedOptions FromList(IList <mapItem> ListItems) { var ho = new HotstringSelectedOptions(); if (ListItems.Count == 0) { return(ho); } foreach (var item in ListItems) { if (item.Selected == true) { if (ho.HasKey[item.key] == false) { if (Enum.IsDefined(typeof(HotStringOptionsEnum), item.key)) { HotStringOptionsEnum en; if (Enum.TryParse(item.key, out en) == true) { ho.Options.Add(en); ho.Keys.Add(item.key); } } } } } // foreach (var item in ListItems) return(ho); }
/// <summary> /// Creates a new instance of <see cref="HotstringSelectedOptions"/> populated with the /// values in <paramref name="Options"/> /// </summary> /// <param name="Options">The Array of Enum Values use to populate the instance</param> /// <returns> /// Instance of <see cref="HotstringSelectedOptions"/>. If <paramref name="Options"/> is null /// then return instance will have no values. /// </returns> public new static HotstringSelectedOptions FromArray(HotStringOptionsEnum[] Options) { var so = SelectedOptionRule <HotStringOptionsEnum> .FromArray(Options); HotstringSelectedOptions hs = new HotstringSelectedOptions(); hs.Keys = so.Keys; hs.Options = so.Options; return(hs); }
/// <summary> /// Attempts to Parse a string representing one or more Options. /// </summary> /// <param name="s">The Options to Parse</param> /// <param name="ec">The <see cref="HotstringSelectedOptions"/> that represents the parsed results</param> /// <returns> /// Returns True if the parse was successful; Otherwise false /// </returns> public static bool TryParse(string s, out HotstringSelectedOptions ec) { bool retval = false; HotstringSelectedOptions outec = null; try { HotstringSelectedOptions ecs = HotstringSelectedOptions.Parse(s); outec = ecs; retval = true; } catch (Exception) { } ec = outec; return(retval); }
/// <summary> /// Gets a Instance of <see cref="HotstringSelectedOptions"/> From a String value /// </summary> /// <param name="s">The String to parse for values</param> /// <returns> /// Instance of <see cref="HotstringSelectedOptions"/> if Parse succeeded; Otherwise, null. /// </returns> /// <exception cref="ArgumentNullException"></exception> public new static HotstringSelectedOptions Parse(string s) { if (string.IsNullOrEmpty(s)) { throw new ArgumentNullException(); } try { // all chars except for `n and `t are single chars var opt = new HotstringSelectedOptions(); var so = SelectedOptionRule <HotStringOptionsEnum> .Parse(s); opt.Keys = so.Keys; opt.Options = so.Options; opt.ExcludeRules = so.ExcludeRules; return(opt); } catch (Exception) { throw; } }