Blog Archive

Tuesday, October 17

Enumerate Using

If you ever need to enumerate a collection of IDisposable items, and you find the following code snippet ugly:

foreach (SomeDisposableClass item in collectionOfDisposableItems)
{
   using (item)
   {
      // do stuff
   }
}

You may find the following method useful:

public static IEnumerable<T> EnumerateUsing<T>(IEnumerable<T> disposableItems)
   where T : IDisposable
{
   foreach (T item in disposableItems)
      using (item)
         yield return item;
}

Calling code looks like:

foreach (SomeDisposableClass item in EnumerateUsing(collectionOfDisposableItems))
{
   // do stuff
}

And yes, Dispose() does get called appropriately after you're finished "doing stuff".

Friday, October 6

Merging in Subversion

Once you've done it, merging from a branch to the trunk (or vice versa) in Subversion is a trivial task. But that first time you attempt it, it can seem a little daunting. Here's a quick how-to:

  1. Let's say you've got a development branch that's all committed and ready to be merged into the trunk. First, switch your working copy to where the result of the merge will ultimately be committed; in this case, the trunk.
  2. merge from the current location to the location that resembles your desired final result; for us, this is merging from the trunk to the development branch.
  3. Resolve any conflicts and commit your current working copy.