I use the following to sort text containing strings and integers naturally
Current
I have been trying to create an alias (I hope I am using the correct terminology) so I can centralize and end up doing the following instead
Change to
Alias code
I am pretty much at the point of giving up and just copying and pasting "new OrdinalStringComparer(true)" everywhere i need it as I have no idea where to go from here. I have tried changing TSource to string, but that didnt work. Reading an MSDN page on this didn't help. You all are my last resort.
thanks for you time.
Current
Code:
.OrderBy(x => x.some_class_property_string, new OrdinalStringComparer(true)))
I have been trying to create an alias (I hope I am using the correct terminology) so I can centralize and end up doing the following instead
Change to
Code:
.OrderByNaturalSorting(x => x.some_class_property_string))
Alias code
Code:
public static IOrderedEnumerable<TSource> OrderByNaturalSorting<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
{
return source.OrderBy(keySelector, new OrdinalStringComparer(true));
}
I am pretty much at the point of giving up and just copying and pasting "new OrdinalStringComparer(true)" everywhere i need it as I have no idea where to go from here. I have tried changing TSource to string, but that didnt work. Reading an MSDN page on this didn't help. You all are my last resort.
thanks for you time.