27 lines
1.2 KiB
C#
27 lines
1.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace mbts.ui.settings {
|
|
static class GridSettingsHelper {
|
|
public static TColKey? parse_col_id<TColKey>(string id) where TColKey : struct =>
|
|
Enum.TryParse(id, true, out TColKey key) ? key : (TColKey?)null;
|
|
|
|
public static string fmt_col_id<TColKey>(TColKey key) where TColKey : struct =>
|
|
key.ToString();
|
|
|
|
public static void normalize_sorting_criterion<TColKey>(IEnumerable<SortingCriteria> sorting_criterion, IReadOnlyDictionary<string, TColKey> sort_member_to_id) where TColKey : struct =>
|
|
normalize_sorting_criterion(sorting_criterion, new Func<string, TColKey?>[] {
|
|
parse_col_id<TColKey>,
|
|
col_name => sort_member_to_id.TryGetValue(col_name, out var k) ? k : (TColKey?)null
|
|
});
|
|
|
|
public static void normalize_sorting_criterion<TColKey>(IEnumerable<SortingCriteria> sorting_criterion, IEnumerable<Func<string, TColKey?>> conversion_dels) where TColKey : struct {
|
|
foreach (var sc in sorting_criterion) {
|
|
sc.col_name = conversion_dels
|
|
.Select(del => del(sc.col_name))
|
|
.FirstOrDefault(k => k.HasValue)?.ToString() ?? sc.col_name;
|
|
}
|
|
}
|
|
}
|
|
} |