You are currently browsing the Plan B Software blog archives.


  • Categories

  • Meta

    Great Design Pattern Web Site

    July 13th, 2010

    I just stumbled on this great web site on my travels on the Internet today its got some great information on
    design patterns, anti-patterns, refactorings and UML.

    Go ahead and take a look you can find it here.

    MvcConf – Virtual ASP.Net MVC Conference

    July 9th, 2010

    Check out the free online MVC Conference here . There’s more information over at Los Techies to.

    Razor View Engine For MVC2

    July 8th, 2010

    Check out Scott Guthrie’s new blog post on  Razor the new view engine that will ship with MVC 2 shortly.

    At first glance it looks really nice and simple to learn. Essentially rather than wrapping your code elements in your view with <% %> tags you can simply use an @ symbol. The view engine has syntactic awareness built into it so there is  no need to close off your tags. If you want to declare multiple lines of code you use the following you wrap your code in the following symbols @{  code goes here } This will go a long way to reduce the tag soup that you get in your views with the current out the box MVC view engine.

    In Scott Gu’s blog he also states that it will be possible to fully Unit Test your views without the need of a web controller or web server. This sounds really interesting to me and I wonder how far Microsoft will take it as I would love to see this extend into being able to test your JQuery in your views as well, as these days I find this is where the majority of the logic sits. I know it is possible test JQuery with frameworks such as QUnit but I haven’t been altogether comfortable with the amount of duplicated HTML that you have create in order to write your tests…I digress maybe that’s a subject for another post.

    Anyway I look forward to it’s release.

    Manage Your Code Snippets With DropBox

    June 25th, 2010

    I regularly work on a number of different development machines and always find it annoying when I haven’t got my latest and greatest code snippet installed. That’s where DropBox is great. The free package gives you a 2gb allowance which once you install there client software creates a DropBox folder on your machine any files placed in that folder are automatically synchronized with any other machines that you use and that have DropBox installed on.

    This means that if you point your CodeSnippets folder at a folder in your DropBox they will all be magically kept up to date across multiple machines.


    I’m going to do the same with my Resharper Template as well!!

    Nunit Code Snippet

    June 24th, 2010

    Here is a useful code snippet that I use all the time to create an empty unit test.

    To use it go to your My Code Snippets folder, go to the snippet manager in Visual Studio (Ctrl K + Ctrl B) to get the file path if you don’t know it. Create a new text file with and appropriate name and rename the extension to .snippet and cut and paste the following xml into the file and save it.


    <?xml version="1.0" encoding="utf-8"?>
    <CodeSnippets xmlns="">
        <CodeSnippet Format="1.0.0">
                    NUnit Test
                        <ToolTip>Replace with test method name</ToolTip>
                <Code Language="CSharp">
                public void $Test_Name$()
    And Bob’s your uncle it should appear in your code snippet shortcuts..Ctrl K Ctrl S to access.

    CodeBurner Firebug extension

    June 23rd, 2010

    I just found this nice add in for Firebug called CodeBurner. Essentially it adds in a lot of HTML & CSS reference documentation. The nice thing about it is that when your browsing your HTML or CSS within Firebug you can right click an element and either get a description and get an example of its usage see the screenshot below.




    Or you can get information within which browsers that particular element is supported.




    Quite useful…

    Visual Studio Rename Shortcut

    June 16th, 2010

    This is more for me than anything else as I can never remember the keyboard short cut to use the build in “Rename” functionality that is built into Visual Studio 2008, and probably 2010 though I haven’t tested it.

    Anyway its Shift + Alt + F10

    Programatically Creating a UIButton with MonoTouch

    June 15th, 2010

    This is probably a really basic post but as I am a still learning the MonoTouch Framework and I couldn’t find anywhere on the Internet explaining how to do it. Anyway today I was trying to programmatically create a UIButton in MonoTouch and set the button type.


    There is a ButtonType property on the instantiated UIButton object but its read only and I couldn’t see any constructor that took a buttontype.


    In the end the answer was quite simple there is a static factory method on the UIButton class that you use to instantiate a new button. The code looks something like this.


       1: var button = UIButton.FromType(UIButtonType.RoundedRect);

       2: button.frame = new RectangleF(100f, 100f, 100f, 100f);

       3: button.SetTitle("click me", UIControlState.Normal);


    Technorati Tags:

    LightSpeed 3.0 Released

    December 15th, 2009

    The guys at Mindscape have released the latest version of their Lightspeed ORM.

    Read more about it here.

    I look forward to downloading it and having a play.

    ASP.Net MVC Option Group DropDown Control

    December 15th, 2009

    Option Groups for drop down lists have been an HTML feature for many years now but have never been supported in any Asp.Net control. It was a bit of a shame recently whilst working on a new Asp.Net MVC web site to find that its still not possible to do out of the box.


    However the good thing about MVC is that its a really easy  to write your own custom controls in the shape of HTML helpers so I thought I’d go about writing my own.

    What did I want the control to do?

    Firstly I wanted it to be strongly typed so no magic strings. I also wanted to be able to pass the control an enumerable collection of objects and use lambda expressions to tell the control which properties to render the text, value and how to group the dropdown items by.

    <%= Html.OptionGroupDropDownList(
              car =>  car.CountryOfOrigin,
              car => car.Brand,
              car => car.Brand,
              car => car.Brand == "BMW")%>

    Line 2 above represents the collection of cars we wish to render as option items.
    Line 3 is the property value of a car we wish to group them by.
    Line 4 is the property value of a car we wish to use as the option value.
    Line 5 is the property value a car we wish to use for the option text.
    Line 6 is a condition we can supply to tell the control which drop down item should be selected.

    which renders HTML that looks something a little like this:


    Ok so the code looks like this..

    public static string OptionGroupDropDownList<T, TProperty, TProperty1, TProperty2>
    ( this HtmlHelper htmlHelper,
      string name,
      string optionLabel,
      IEnumerable<T> collection,
      Func<T, TProperty> optionGroupProperty,
      Func<T, TProperty1> optionValueProperty,
      Func<T, TProperty2> optionTextProperty,
      Func<T, bool> isSelectedCondition)
          var groupedCollection = collection.GroupBy(optionGroupProperty);
          // We are trying to generate the Html that looks something like this...
          //  <optgroup label="Swedish Cars">
          //      <option value="volvo">Volvo</option>
          //      <option value="saab">Saab</option>
          //  </optgroup>
          using (var stringWriter = new StringWriter())
          using (var writer = new HtmlTextWriter(stringWriter))
              writer.AddAttribute(HtmlTextWriterAttribute.Name, name);
              writer.AddAttribute(HtmlTextWriterAttribute.Id, name);
              if(string.IsNullOrEmpty(optionLabel) == false)
               // Group by our optGroup the above example that would be
               // "Swedish Cars"
               foreach (var optionGroup in groupedCollection)
                    var optionGroupLabel = optionGroup.Key;
                    // label="Swedish Cars"
                    writer.AddAttribute(Label, optionGroupLabel.ToString());
                    writer.RenderBeginTag(Optgroup); //<optgroup>  
                     foreach (var option in optionGroup)
                       var optionValue = optionValueProperty.Invoke(option).ToString();
                       var optionText = optionTextProperty.Invoke(option).ToString();
                       var isOptionSelected = isSelectedCondition.Invoke(option);
                       if (isOptionSelected)
                         writer.AddAttribute(HtmlTextWriterAttribute.Selected, "true");
                       // value = "volvo"
                       writer.AddAttribute(HtmlTextWriterAttribute.Value, optionValue); 
                       // <option>
                       // Volvo
                       // </option>
                      // </optiongroup>
                    return stringWriter.ToString();