Created
March 11, 2016 14:01
-
-
Save Pzixel/ae9a2946f84db1a21c4d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class WinApi | |
{ | |
[DllImport("shlwapi.dll", CharSet = CharSet.Unicode)] | |
public static extern int StrCmpLogicalW(string s1, string s2); | |
} | |
class AlphanumericComparer : IComparer<string> | |
{ | |
public int Compare(string x, string y) | |
{ | |
return WinApi.StrCmpLogicalW(x, y); | |
} | |
public static AlphanumericComparer<T> For<T>(T obj, Func<T, string> func) | |
{ | |
return new AlphanumericComparer<T>(func); | |
} | |
} | |
class AlphanumericComparer<T> : IComparer<T> | |
{ | |
private readonly Func<T, string> _func; | |
public AlphanumericComparer(Func<T, string> func) | |
{ | |
_func = func; | |
} | |
public int Compare(T x, T y) | |
{ | |
return WinApi.StrCmpLogicalW(_func(x), _func(y)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment