A few useful extensions for ObservableCollection
I created a few extension methods that deal with ObservableCollection that I've been using in the WP7 projects that I hope you will find useful as well. The first method is for sorting a collection. The second is to convert IEnumerable<T> to ObservableCollection<T>:
public static class ObservableExtension
{
public static void Sort<T>(this ObservableCollection<T> collection,
IComparable<T> comparable)
{
if (comparable == null)
{
throw new ArgumentNullException("comparable is null");
}
Array.Sort<T>(collection, comparable);
}
public static ObservableCollection<T> ToObservableCollection<T>(this IEnumerable<T> source)
{
ObservableCollection<T> collection = new ObservableCollection<T>();
foreach (T item in source)
{
collection.Add(item);
}
return collection;
}
}
Enjoy...
Comments
- Anonymous
August 21, 2010
These won't compile for tool build 6536... Why?