Steve is right (no pun intended): Extension methods are what you're asking for. In C# you'd do something like this:
namespace ExtensionsNamespace; // Name this whatever you want.
public static class ListExtensions // must be public static!
{
// must be public static and the first parameter needs a "this"
public static IList<T> ToOrderedList<T>(this IList<T> originalList, IComparer<T> comparer)
{
// Code to take the original list and return an ordered version
}
}
And then in your code:
using ExtensionsNamespace;
...
IComparer<Book> comparer = GetBookComparer();
IList<BooK> books = GetBookList().ToOrderedList(comparer);
There are some additional things you can do using lambda expressions to avoid the need to write your own comparer class in certain cases, and so forth. However, before you go reinventing the wheel I'd suggest you look at LINQ to Objects, which already has a lot of these functionalities built in. For example:
using System.Linq;
...
IEnumerable<Book> booksInOrder1 = GetBookList().OrderBy(b => b.Title);
Does that answer your question?