Пример #1
0
        public bool GetSortedOption(ref FieldSortedOption <T> fieldSortedOption)
        {
            if (fieldSortedOption.OldList == null || fieldSortedOption.NewList == null)
            {
                return(false);
            }
            if (fieldSortedOption.OldList.Count != fieldSortedOption.NewList.Count)
            {
                return(false);
            }
            if (fieldSortedOption.Options == null)
            {
                fieldSortedOption.Options = new List <SortedOption <T> >();
            }
            else
            {
                return(true);
            }

            _fieldSortedOption = fieldSortedOption;

            SortedOption <T> optionItem;

            for (int inx = 0; inx < fieldSortedOption.OldList.Count; inx++)
            {
                T oldItem = fieldSortedOption.OldList[inx];
                optionItem = new SortedOption <T>()
                {
                    NewValue    = inx == 0 ? default(T) : fieldSortedOption.NewList[inx - 1],
                    OptionValue = fieldSortedOption.NewList[inx],
                    OptionType  = inx == 0 ? SortedOptionType.FIRST : SortedOptionType.AFTER
                };
                if (Equa(oldItem, fieldSortedOption.NewList[inx]))
                {
                    optionItem.OptionType = SortedOptionType.NONE;
                    fieldSortedOption.Options.Add(optionItem);
                    continue;
                }
                fieldSortedOption.Checked = true;
                int newInx = _getIndex(fieldSortedOption.OldList, fieldSortedOption.NewList[inx]);
                fieldSortedOption.Options.Add(optionItem);
                _changeSort(fieldSortedOption.OldList, newInx, inx);
            }
            return(true);
        }
Пример #2
0
 public bool IsChecked(T value, out SortedOption <T> sortedOption)
 {
     sortedOption = null;
     if (_fieldSortedOption.Options == null || _fieldSortedOption.Options.Count == 0)
     {
         GetSortedOption(ref _fieldSortedOption);
     }
     if (_fieldSortedOption.Options?.Count != _fieldSortedOption.OldList.Count)
     {
         return(false);
     }
     if (_fieldSortedOption.Checked == false)
     {
         return(false);
     }
     sortedOption = _fieldSortedOption.Options.FirstOrDefault(i => Equa(i.OptionValue, value));
     if (sortedOption?.OptionType != SortedOptionType.NONE)
     {
         return(true);
     }
     return(false);
 }