blob: b8a606798f8e746b28dca7dbf32a6fb7535716be (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using DSALib.Auxiliary;
using DSALib.Models.Database;
namespace DSACore.Auxiliary
{
public static class DataObjectEnumerableExtension
{
public static IDataObject Match(this IEnumerable<IDataObject> dataObjects, string name)
{
return (dataObjects as IOrderedEnumerable<IDataObject> ?? throw new InvalidOperationException()).OrderBy(x => SpellCorrect.Compare(name,x.Name)).Last();
}
public static bool TryMatch(this IEnumerable<IDataObject> dataObjects,out IDataObject data, string name)
{
data = (dataObjects as IOrderedEnumerable<IDataObject> ?? throw new InvalidOperationException()).OrderBy(x => SpellCorrect.Compare(name,x.Name)).Last();
return SpellCorrect.IsMatch(name, data.Name);
}
}
}
|