Example #1
0
        private static OrderByPropertyComparer CreateComparer(
            List <OrderByPropertyEntry> orderMatrix,
            List <MshParameter> mshParameterList,
            bool ascending,
            CultureInfo cultureInfo,
            bool caseSensitive)
        {
            if (orderMatrix == null || orderMatrix.Count == 0)
            {
                return(null);
            }
            Nullable <bool>[] ascendingOverrides = null;
            if (mshParameterList != null && mshParameterList.Count != 0)
            {
                ascendingOverrides = new Nullable <bool> [mshParameterList.Count];
                for (int k = 0; k < ascendingOverrides.Length; k++)
                {
                    object ascendingVal = mshParameterList[k].GetEntry(
                        SortObjectParameterDefinitionKeys.AscendingEntryKey);
                    object descendingVal = mshParameterList[k].GetEntry(
                        SortObjectParameterDefinitionKeys.DescendingEntryKey);
                    bool isAscendingDefined  = isOrderEntryKeyDefined(ascendingVal);
                    bool isDescendingDefined = isOrderEntryKeyDefined(descendingVal);
                    if (!isAscendingDefined && !isDescendingDefined)
                    {
                        // if neither ascending nor descending is defined
                        ascendingOverrides[k] = null;
                    }
                    else if (isAscendingDefined && isDescendingDefined &&
                             (bool)ascendingVal == (bool)descendingVal)
                    {
                        // if both ascending and descending defined but their values conflict
                        // they are ignored.
                        ascendingOverrides[k] = null;
                    }
                    else if (isAscendingDefined)
                    {
                        ascendingOverrides[k] = (bool)ascendingVal;
                    }
                    else
                    {
                        ascendingOverrides[k] = !(bool)descendingVal;
                    }
                }
            }
            OrderByPropertyComparer comparer =
                OrderByPropertyComparer.CreateComparer(orderMatrix, ascending,
                                                       ascendingOverrides, cultureInfo, caseSensitive);

            return(comparer);
        }
Example #2
0
 private static OrderByPropertyComparer CreateComparer(List <OrderByPropertyEntry> orderMatrix, List <MshParameter> mshParameterList, bool ascending, CultureInfo cultureInfo, bool caseSensitive)
 {
     if ((orderMatrix == null) || (orderMatrix.Count == 0))
     {
         return(null);
     }
     bool?[] ascendingOverrides = null;
     if ((mshParameterList != null) && (mshParameterList.Count != 0))
     {
         ascendingOverrides = new bool?[mshParameterList.Count];
         for (int i = 0; i < ascendingOverrides.Length; i++)
         {
             object entry         = mshParameterList[i].GetEntry("ascending");
             object orderEntryKey = mshParameterList[i].GetEntry("descending");
             bool   flag          = isOrderEntryKeyDefined(entry);
             bool   flag2         = isOrderEntryKeyDefined(orderEntryKey);
             if (!flag && !flag2)
             {
                 ascendingOverrides[i] = null;
             }
             else if ((flag && flag2) && (((bool)entry) == ((bool)orderEntryKey)))
             {
                 ascendingOverrides[i] = null;
             }
             else if (flag)
             {
                 ascendingOverrides[i] = new bool?((bool)entry);
             }
             else
             {
                 ascendingOverrides[i] = new bool?(!((bool)orderEntryKey));
             }
         }
     }
     return(OrderByPropertyComparer.CreateComparer(orderMatrix, ascending, ascendingOverrides, cultureInfo, caseSensitive));
 }