Monday, 19 April 2010

n350254507751_6618 I work with Allstate NI and due to expansion we're looking for .Net developers. Check out the careers site for more details or come and meet with us an one of our open days (dates below). If you're a talented .Net developer you should come check us out especially if you like:

    .    Working a 4 Day Weeks while being paid for 5!! 
    .    Duvet days
    .    Money off gym fees
    .    Beer & pizza
    .    Plus loads and loads more benefits.


If you don't believe me check this video out.

Upcoming open days at Allstate NI's Belfast and Northland Rd offices:


Belfast Office
Thursday 29th April 2010 3-7pm
Thursday 27th May 2010 3-7pm

Northland Rd Offices
Friday 30th April 2010 3-7pm
Friday 28th May 2010 3-7 pm

posted on Monday, 19 April 2010 19:50:00 (GMT Standard Time, UTC+00:00)  #    Add Comment | Comments [0]
 Sunday, 18 April 2010

northwest I'll be delivering a session to NW-MTUG on what's new in C# 4.0 on Monday 17th May. You can get all the details on NW-MTUG's site and register here.

I'll cover the main new features with code examples for each:

            • Dynamic
            • Named & Option Parameters
            • Generic Variance

There'll also be a few prizes to give out on the night ;-)

posted on Sunday, 18 April 2010 11:10:00 (GMT Standard Time, UTC+00:00)  #    Add Comment | Comments [0]
 Tuesday, 02 March 2010
This is just a very short example of writing files to a CD or DVD using C# on Windows XP. For this I will use the XP Burn Component provided by Microsoft. This is a class library that you can use from C# or any other .Net language to write files to disc, simply down load the MSI file from the XP Burn web site and follow these steps.
  1. Start Visual Studio and create a new Windows Forms Application
  2. Right click on the 'References' folder and select 'Add Reference.'
  3. Browse to the location of the XPBurnComponent.dll file, for me I had chose all the default settings during the installation options and the dll was located under 'My Documents' folder in MSDN\XPBurn. AddReference
  4. Once you have added the dll to your project you can begin using the classes it contains by adding a using directive for the XPBurn namespace

    using XPBurn;

  5. Writing files to the disc is now very easy al you have to do is create an instance of XPBurnCD, call the AddFile method to add files to the disc and the RecordDisc method to actually write the files to the disc. This sample method shows adding files in a directory and writing these to disc.

    XPBurnCD cd = new XPBurnCD(); cd.BurnComplete += new NotifyCompletionStatus(BurnComplete); MessageBox.Show(cd.BurnerDrive); DirectoryInfo dir = new DirectoryInfo(_burnFolder); foreach (FileInfo file in dir.GetFiles()) { cd.AddFile(file.FullName, file.Name); } cd.RecordDisc(false, false);


The XPBurnCD class has a number of events that you can use to monitor the progress of the burn process. In the above example I have used the NotifyCompletionStatus so that I can display a message to the user when all the files have been written to the disc. For more information on the classes, methods and properties that XPBurn has take a look at the help file 'XPBurnDocs.chm' which is installed in the same directory as 'XPBurnComponent.dll'.

You can download my Visual Studio 2010 sample application

posted on Tuesday, 02 March 2010 21:23:08 (GMT Standard Time, UTC+00:00)  #    Add Comment | Comments [0]
 Wednesday, 04 November 2009

Getting a string value for an enum value is a common problem and there's a few solutions knocking around the Internet, however a few of these that I've seen end up having a utility class that handles mapping the enum value to the relevant string value, this is fine but I think this is an operation that should be callable on the enum value without having to go off and use another class. The solution I have here provides this functionality using extension methods that are available in .Net 3.5.

The first thing I did was to create a new attribute that will be applied to the enum values when they are declared so a string value can be specified for each enum value such as is shown in the code snippet below:


public enum 
    Red = 0,
    Blue = 1,
    Green = 2

The code for the attribute class is:

public class StringValueAttribute : Attribute 
    public string StringValue { get; private set; }

    public StringValueAttribute(string value) 
         this.StringValue = value; 

When writing the extension method we can take advantage of the fact that all enums have Enum as their base class. This allows the following extension to be defined.

public static stringGetStringValue(this Enum enumValue) 
   . . . 

This method is now available to be called as follows: 

Colors myColor = Colors.Red; 


As the 'GetStringValue' extension method is available on all enums it leaves the possibility that GetStringValue could be called on enums that have not used the 'StringValue' attribute. To protect against this there are two options, option one would be to return an empty string and option two is to use reflection and return the name of the enum value. This was the option I choose, firstly I look for the 'StringValue' attribute if that is present the method returns that as this is the mechanism that allows the developer to take finer control of the string value. So the previous enum could be defined as follows:


public enum Colors 
        Red = 0, 

        Blue = 1, 

        Green = 2 

Likewise the enum could be defined as shown below and we would get the values 'Red', 'Green' and 'Blue' when using the 'GetStringValue' method.

public enum Colors 
        Red = 0, 
        Blue = 1, 
        Green = 2 

Here is my implementation of the extension method: 

public static string GetStringValue(this Enum enumValue) 
    Typetype = enumValue.GetType(); 
    FieldInfo fieldInfo = type.GetField(enumValue.ToString()); 

    StringValueAttribute[] attribs = fieldInfo.GetCustomAttributes( 
        typeof(StringValueAttribute), false) as StringValueAttribute[]; 

    if(attribs.Length > 0) 
        return attribs[0].StringValue; 
        return fieldInfo.Name;  

I've a prebuilt DLL so all you need to do is download this and reference it in your projects making sure to include the namespace 'Gangleri.Enums' when you wish to use the extension method or the StringValue attribute.

Source Code:

posted on Wednesday, 04 November 2009 21:13:16 (GMT Standard Time, UTC+00:00)  #    Add Comment | Comments [1]
 Thursday, 29 October 2009

I've been doing some work with the Unity IoC container recently and had to configure some generic types so I thought I'd post some of the examples here so that I'd have some to refer back to more than anything else a blog post tends to be less likely to get lost that an old post-it note.

Xml config to configure mapping for a specific generic type, note the use of [[]] to define the generic type. Inside the square brackets you specify type name and the assembly containing the type. In both example `1 signifies the generic parameter:

<type type="Data.Repository.IRepository`1[[Poco.Address, Poco]], Data.Repository"
      mapTo="Data.Repository.LinqRepository`1[[Poco.Address, Poco]], Data.Repository">
  <lifetime type="singleton"></lifetime>

Xml config to configure open generic type mapping:

<typeAlias alias="IRepository`1"            
" /> <type type="IRepository`1" mapTo="Questern.ActiveOrderManagementSystem.Data.Repository.LinqRepository`1,
"> <lifetime type="singleton" /> </type>


Thanks to Marceli for helping out with this!!

posted on Thursday, 29 October 2009 19:52:26 (GMT Standard Time, UTC+00:00)  #    Add Comment | Comments [1]