Sunday, August 31, 2008

changing the class item template in VS2008

It's been bugging me for too long, every bloody time I go new -> class in VS2008,
I get a class that is not set to public. I usually don't realize until I try to use the class at some later time.

Today I finally snapped and fixed it.

To change the template that is used to create new empty classes in VS2008,
- Go to 
C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\CSharp\Code\1033
- unzip the class.zip.
- change the class.cs file
- zip it back up and replace the original .zip file.

In yo face VS2008 default settings!!

Thursday, August 28, 2008

useful sorting of Lists

slightly in love with ruby/rails sorting
some_list.sort_by{|person| person.age}

I went ahead and made a sort function that only takes a Generic Func as input
here goes:

public static class ListExtender
{
    public static void Sort<T>(this List<T> list, Func<T, IComparable> func)
    { 
        list.Sort((a, b) => func(a).CompareTo(func(b)));
    }
}

So I can now sort for instance cards like this:

Cards.Sort(card => card.Value )

Yay!