private SortOrder GetSortOrder(MapiTable table, SortBy[] sortColumns, GroupByAndOrder[] groupBy, int expandCount, ref List <PropTag> alteredProperties) { if ((sortColumns == null || sortColumns.Length == 0) && (groupBy == null || groupBy.Length == 0)) { return(null); } SortOrder sortOrder = new SortOrder(); if (groupBy != null) { for (int i = 0; i < groupBy.Length; i++) { NativeStorePropertyDefinition nativeGroupBy = InternalSchema.ToStorePropertyDefinition(groupBy[i].GroupByColumn).GetNativeGroupBy(); PropTag sortPropertyTag = this.GetSortPropertyTag(nativeGroupBy, ref alteredProperties); GroupSort nativeGroupSort = InternalSchema.ToStorePropertyDefinition(groupBy[i].GroupSortColumn.ColumnDefinition).GetNativeGroupSort(groupBy[i].GroupSortColumn.SortOrder, groupBy[i].GroupSortColumn.Aggregate); PropTag sortPropertyTag2 = this.GetSortPropertyTag((NativeStorePropertyDefinition)nativeGroupSort.ColumnDefinition, ref alteredProperties); SortFlags sortFlag; switch (nativeGroupSort.Aggregate) { case Aggregate.Min: sortFlag = SortFlags.CategoryMin; break; case Aggregate.Max: sortFlag = SortFlags.CategoryMax; break; default: throw new ArgumentOutOfRangeException("groupBy", nativeGroupSort.Aggregate, ServerStrings.ExInvalidAggregate); } sortOrder.AddCategory(sortPropertyTag, QueryExecutor.SortOrderToSortFlags(nativeGroupSort.SortOrder)); if (sortPropertyTag != sortPropertyTag2) { sortOrder.Add(sortPropertyTag2, sortFlag); } } sortOrder.ExpandCount = expandCount; } if (sortOrder.GetSortCount() > 4) { throw new ArgumentException(ServerStrings.ExTooComplexGroupSortParameter, "groupBy"); } if (sortColumns != null && sortColumns.Length > 0) { SortBy[] nativeSortBy = QueryExecutor.GetNativeSortBy(sortColumns); if (nativeSortBy.Length + sortOrder.GetSortCount() > 6) { throw new ArgumentOutOfRangeException("sortColumns", ServerStrings.ExTooManySortColumns); } for (int j = 0; j < nativeSortBy.Length; j++) { PropertyDefinition columnDefinition = nativeSortBy[j].ColumnDefinition; PropTag sortPropertyTag3 = this.GetSortPropertyTag((NativeStorePropertyDefinition)columnDefinition, ref alteredProperties); sortOrder.Add(sortPropertyTag3, QueryExecutor.SortOrderToSortFlags(nativeSortBy[j].SortOrder)); } } return(sortOrder); }