FundraisingMenu.SearchServices.FundraisingMenuSearchServices.EvaluateOrderBy C# (CSharp) Method

EvaluateOrderBy() public method

Get a function to pass into a LINQ OrderBy clause. The column sorting parameter is an index that gives the index of the column to sort by in display order. The list of columns is also in display order. So, we have to get the name of the column to sort by looking it up in the list of columns at the specified sort column index. Then, we can look up the attribute by name in the dataMap and return a lambda expression.
public EvaluateOrderBy ( int colId, List columns ) : object>.Func
colId int The display-ordered index of the sorted column
columns List The display-ordered list of columns
return object>.Func
        public Func<FundraisingMenuResult, object> EvaluateOrderBy(int colId, List<ColumnData> columns)
        {
            Func<FundraisingMenuResult, object> result = null;
            if (0 <= colId && colId < columns.Count)
            {
                // Find the name of the column to sort by in the list of columns (which is in display order).
                string columnName = columns[colId].data;
                if (!string.IsNullOrEmpty(columnName) && _dataMap.ContainsKey(columnName))
                {
                    result = r => string.Join(",", _dataMap[columnName].ExtractValues(r));
                }
            }
            return result;
        }