Exemplo n.º 1
0
        /// <summary>
        /// Creates a List of <see cref="SortedMapItem"/> objects representing all the Value
        /// in T enum. The List is Sorted Based upon <see cref="SortedMapItem.SortOrder"/>
        /// </summary>
        /// <param name="SelectedValues">
        /// Instance of <see cref="SelectedOptions{T}"/>. Each value in SelectedValues will set the
        /// corresponding <see cref="SortedMapItem.Selected"/> to true;
        /// </param>
        /// <param name="ExcludeRules">
        /// If any rule matches the exclude then the matched item will not be
        /// outputted in the list.
        /// </param>
        /// <returns>
        /// List of <see cref="SortedMapItem"/>
        /// </returns>
        /// <remarks>
        /// <see cref="SortedMapItem.Parent"/> is set to the List.
        /// </remarks>
        public virtual List <SortedMapItem> ToList(SelectedOptions <T> SelectedValues, EnumRule <T> ExcludeRules)
        {
            List <SortedMapItem> SortList = new List <SortedMapItem>();

            if (this.Item == null)
            {
                return(SortList);
            }

            foreach (var map in this.Item)
            {
                SortedMapItem newMap = new SortedMapItem();
                if (ExcludeRules[map.Key])
                {
                    // exclude rule continue
                    continue;
                }
                newMap.Key       = map.Key;
                newMap.Value     = map.Value;
                newMap.SortOrder = map.SortOrder;
                if (SelectedValues.HasKey[map.Key])
                {
                    newMap.Selected = true;
                }
                newMap.Parent = SortList;
                SortList.Add(newMap);
            }
            // Sort the list based upon sort values for display.
            // This comes into play when the binding list is bound to a list control
            // such as a drop down list.
            SortList.Sort((value1, value2) => value1.SortOrder.CompareTo(value2.SortOrder));
            return(SortList);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a Binding List of <see cref="SortedMapItem"/> objects representing all the Value
        /// in T enum. The List is Sorted Based upon <see cref="SortedMapItem.SortOrder"/>
        /// </summary>
        /// <param name="ExcludeRules">
        /// If any rule matches the exclude then the matched item will not be
        /// outputted in the bind list.
        /// </param>
        /// <returns>
        /// Binding list of <see cref="SortedMapItem"/>
        /// </returns>
        /// <remarks>
        /// <see cref="SortedMapItem.Parent"/> is set to the Binding List.
        /// </remarks>
        public virtual BindingList <SortedMapItem> ToBindingList(EnumRule <T> ExcludeRules)
        {
            BindingList <SortedMapItem> bl = new BindingList <SortedMapItem>();

            if (this.Item == null)
            {
                return(bl);
            }
            List <SortedMapItem> SortList = new List <SortedMapItem>();

            foreach (var map in this.Item)
            {
                SortedMapItem newMap = new SortedMapItem();
                if (ExcludeRules[map.Key])
                {
                    // exclude rule continue
                    continue;
                }
                newMap.Key       = map.Key;
                newMap.Value     = map.Value;
                newMap.SortOrder = map.SortOrder;
                SortList.Add(newMap);
            }
            // Sort the list based upon sort values for display.
            // This comes into play when the binding list is bound to a list control
            // such as a drop down list.
            SortList.Sort((value1, value2) => value1.SortOrder.CompareTo(value2.SortOrder));

            // Now that the list is sorted add the values to the binding list.
            foreach (var map in SortList)
            {
                map.Parent = bl;
                bl.Add(map);
            }
            SortList.Clear();
            return(bl);
        }