http://www.cyberack.com/2007/07/adding-syntax-highlighter-to-blogger.html

Search This Blog

Loading...

Monday, August 27, 2012

ToObservableCollection

kick it on DotNetKicks.com

I've found myself writing this bit over several times and though to myself. "Self you should put this somewhere."
And so I answer back....OK. As an added bonus you can use it too.
using System.Collections.Generic;
using System.Collections.ObjectModel;
 
namespace Example.Extensions
{
    public static class Extensions
    {
        public static ObservableCollection ToObservableCollection(this IEnumerable enumerable)
        {
            var col = new ObservableCollection();
            foreach (var cur in enumerable)
            {
                col.Add(cur);
            }
            return col;
        }
    }
}