Silverlight doesn’t have any DataTemplateSelectors, which is too bad. If you want to choose a different template based on certain properties of the object you’re binding to, you have to use a work-around. Jeremy Likness has a rather extensive solution, but I found Timmy Kokke’s way to be more light-weight. Basically, just make a new class that inherits from ContentControl, override its OnContentChanged method and set its ContentTemplate property to the template you need: public class PersonNameDataTemplateSelector : ContentControl {     protected override void OnContentChanged(object oldContent, object newContent)    

I just go my AppHarbor build to work, and can definitely recommend it if you have a project of your own. It’s a builder server and hosting in one. I switched to Mercurial for this, but it will work with Git also. I just wanted to be able to tell the girls in the club that I use Mercurial. When I push my changes to BitBucket, AppHarbor will pull them in (it also works with GitHub, Codeplex,…), build my solution,

When asserting the content of collections, lists, dictionaries,… in unit tests, don’t do this: Assert.That(this.result.Contains(this.expectedResult1)); Assert.That(this.result.Contains(this.expectedResult2));   Or this: Assert.AreEqual(this.expectedResult1, this.result[0]); Assert.AreEqual(this.expectedResult2, this.result[1]); What if you implemented your method wrong, and the result contains more than two elements? Unless you’re totally not interested in the size of the result, always check if the collection is as big as you expect it to be: Assert.AreEqual(2, this.expectedResult.Count); Assert.AreEqual(this.expectedResult1, this.result[0]); Assert.AreEqual(this.expectedResult2, this.result[1]);

Do you find yourself often writing the same pieces of code? I guess we all do: the INotifyPropertyChanged interface and the PropertyChanged method in WPF projects are one example. Unit tests more often than not have the same structure (at least on a per-project basis). Visual Studio’s snippets functionality can speed up your work in this regard. I knew about snippets since some time, but never actually used them. I recently noticed I had to type the same code for

After having an interesting discussion with Stefaan (colleague, friend, ex-colleague and now colleague again) about my previous post on NHibernate’s SQLCriterion, I decided to have another look at my usage of SQLCriterion. He argued that with SQLCriterion, you’re more or less working around the ORM, which I can agree with. After putting it on StackOverflow, I got three answers and tried all three. This is what I went with in the end: ISessionFactory sessionFactory = GetSessionFactory();  ISession session = sessionFactory.GetCurrentSession(); 

I recently needed to use NHibernate’s SQLCriterion, but lost some time on finding out how to use it. Once you’ve found it, it’s quite simple actually: ISessionFactory sessionFactory = GetSessionFactory(); ISession session = sessionFactory.GetCurrentSession(); ICriteria criteria = session.CreateCriteria(); var sqlString = new SqlString(“{alias}.GroupId = ” + groupId); criteria.Add(new SQLCriterion(sqlString, new object[0], new IType[0])); return criteria.List(); The {alias} is there so NHibernate knows where to put the table name. I’m not so sure about the second and third argument of the SQLCriterion

Update: This is an old article that helped us at the time, using a centralized version control system (Subversion). We created our own branching strategy, and in essence, came up with trunk based development before we really knew it already existed. For the record: I would heavily advise against developing your own branching strategy. The issue with making up your own branching strategy is that, like most not-invented-here solutions, you’re probably not going to be smarter than the community. Choosing

This was a blog post I had lying around, waiting to be posted. This post on code smells on the All Your Base Are Belong To Us blog reminded me of it. So here goes. Everyone has coding pet peeves. Pieces of code they can’t resist the urge to change when they see it. Of course, there will be exceptions, or cases where it’s impossible to change the code, or just not worth it. But not that often. Apart from

On two projects I have worked on, I’ve seen a lot of this: public void DoSomething() { try { // actually do something here } catch (Exception ex) { throw new Exception(“Unable to do something”, ex); } } I’ve seen this in various differing styles: not including the original exception in the newly thrown one (ouch!)* having a custom Exception type, indicating where in the code/assemblies the exception happened.Reasons seem to be a desire to easily see where the exception

Well, I’ve switched databases again. After briefly trying NHibernate, then switching to RavenDB, then looking at Karvonite, I think I’ve found what I was looking for in Sterling. I was looking for an easy way to persist objects. NHibernate is nice, but compared to object-oriented databases, it’s a lot of work (database schema’s, mapping files, etc.). RavenDB introducted me to the NoSql alternatives, but has a high licensing fee and is a little to heavy for my needs. Karvonite was