Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to create a linq OrderBy alias

Status
Not open for further replies.

mrgulic

Technical User
Sep 18, 2001
248
US
I use the following to sort text containing strings and integers naturally

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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top