HitLab NZ!

Well done guys!

References: http://www.hitlab.org.nz

CodeLab Update

Hi All,

Just to give you an update on what we are doing.   We provide support services and technical expertise to a number of open source products including Moodle and Joomla.   Our clients are education institutes including Aoraki Polytechnic and Pro+Med Medic Training.   We also contract to SPF Multimedia to help develop software products for schools (pre-school, primary, high school and tertiary institutes).

We also do custom software development for Pro+Med where they have a dynamic driven C# ASP.NET website running on our own XTS Web Engine.   This will soon be changed to use the ASP.NET MVC framework.

We are also part of the Timaru Kyokushin Karate club where we manage their http://www.timarukyokushin.co.nz website.

On the side, I’m work full-time for Verb Ltd as a Lead Developer/Project Manager.

Creating a generic list of anonymous types

Scenerio

I have a simple HTML form on a ASP.NET Web page. This form is to post a number of values including several elements that are compulsory to perform several actions on the server. As we know, when we post values to ASP.NET these are available for Request.Form. All we know is the key and value in the NameValueCollection object. I want to be able to check if several values are present and if they are not, return the respective element meta-description rather than the original name.

For Example If we post a name field called formName, we want to return “You must enter data into the fields: Form Name”.

Solution

I used a generic list of a anonymous type. My anonymous type has a Name and a Value property.

var nameValueInstance = new { Name=”formName”,Value=”Form Name”}

I created a list factory that pases in a array of generic type interfaces and returns a generic list of the generic type interface.

private static List<T> MakeList<T>(params T[] items)

{

List<T> newList = new List<T>(items);

return newList;

}

I was then able to do the following to create a generic list of anonymous types:

var fields = MakeList(new { Name = “price”, Value = “Price” }, new { Name = “productname”, Value = “Product Name” });

From here I was able to interate through the list and validate the Form elements and return the nessessary output.

References:

http://kirillosenkov.blogspot.com/2008/01/how-to-create-generic-list-of-anonymous.html