enums with real world names

March 4, 2010 18:54 by bryan

Enums are a wonderful addition to .Net, but won't it be nice to have a real world description that you can display to the user interface? Well you can, and here is how define an attribute (or use existing DisplayNameAttribute) and annotate your enum with names as additional meta-data:

public enum Unit
{
    [DisplayName("Hz")] Hertz,
    [DisplayName("%V")] Volt
}


Conditional Breakpoints

March 3, 2010 12:13 by bryan

I know that conditional breakpoints have been around for some time, I just keep forgetting how to set it, so I though it should be time write how to set a conditional breakpoint on my blog.

When you only want to break under certain conditions, you can right-click on a breakpoint red circle (or go to the Breakpoints Window and bring up the context menu on a given breakpoint) and select Condition to bring up the dialog box for conditional breakpoints. 

You’re given two options: break only when the specified expression is true or break only when the specified value has changed.  For this example, since I’m in a for loop, i’ll break when the value of result.Id == 22.

You’ll notice that the breakpoint circle now has a red plus on it to indicate it is conditional.


Magic Mushrooms Make Everything Bigger and Better

February 5, 2010 06:38 by bryan


ASP.NET MVC 2 RC

January 29, 2010 09:00 by bryan

MVC 2 is ready for use and designed to work with both VS 2008, as well as with VS 2010. 

Click here to download the ASP.NET MVC 2 release candidate for .NET 3.5 and VS 2008.  Nice thing is that it can be installed side-by-side with ASP.NET MVC on the same machine.


Simple popups or hover overs

January 13, 2010 10:53 by bryan

Many a time you use the <a href'#' title='display a message' /> to display a message when you want some hover over text to display additional information, which is fine, but what if you want to display some more fancy text, lets say in HTML you are stuck.

So I went on the search to find something that was easy to implement.

I came across a number of different popups

Each having good coverage, but I ended up using overLIB mainly as Nadun at work found it very easy to use.

Here is how I have implement the library

I have implemented a simple jQuery version of the library, I am sure you could extend it to do a lot more, I always say KIS (Keep It Simple)

Add a tag class of overlib and popup tag which holds the popup information, simple, e.g.

<a href="#" class="overlib" popup="Hello World">Basic popup</a>

If you want to display HTML content in the popup, just added it to the popup tag

<a href="#" class="overlib" popup="<b>Bold</b> can be displayed too">HTML content</a>

I have also include in my sample the overlib_pagedefaults which sets a few things up for overLIB, but this is not required if you don't want to use it.

I have attached a fully working sample to make life easier.

overLib.zip (71.66 kb)


How do you retrieving the XmlEnumAttribute values for an Enum

January 8, 2010 06:27 by bryan

When you are playing with Web Services you quite often find information held in an Attribute, but how do you get it out?

e.g.

public enum Classification {

        [System.Xml.Serialization.XmlEnumAttribute("Test drive demonstrator")]
        Testdrivedemonstrator,

        [System.Xml.Serialization.XmlEnumAttribute("Showroom vehicle")]
        Showroomvehicle,

 

By using reflection you can gain access to the attribute, here is how:

Type enumType = typeof(velocityUom);

foreach (FieldInfo fi in enumType.GetFields())

{

object[] attrs = fi.GetCustomAttributes(typeof(XmlEnumAttribute), false);

if (attrs.Length > 0)

{

Console.WriteLine(((XmlEnumAttribute)attrs[0]).Name);

}

}

 


Last Years Toys

January 4, 2010 13:12 by bryan

It's a new year and it's must be time for me to go over what toys I have played with in 2009.

  • Balsamiq Mockups must be the best application and tool that I have come across this year, after giving a talk to DotNetDevNet on the application I found that many other developers went ahead and bought the application too.
  • NotePad+, which is an extended version of the very basic default NotePad that comes with Windows.  Just replace your NotePad with this one and off you go.
  • SysInternals Process Explorer I have used every day, mainly due to the fact that Windows does not handle resources and memory that well, so you have to have a tool to sort it out for you when things go wrong.
  • GhostDoc is an internal tool for use with Visual Studio and cuts down the amount of time required for documentation, and does it right all the time.
  • The biggest and most impressive toy last year has to be the purchase of a MacBook, it's so much easier than Windows 7, XP or Vista, and things just work as they should do, well designed and well throughout, this gets 10 out of 10 for last years toys.
I'm sure I've used some other toys last year, but these are the ones that I remember the most.


There is already an open DataReader associated with this Command which must be closed first.

November 18, 2009 10:25 by bryan

Having been using LINQ to SQL for some time now, I came across my very first issue "There is already an open DataReader associated with this Command which must be closed first." it's been some time since I had this issue.

The issue only appears on one database and that is being held on a SQL 2000 box.

The solution, sorry work around, is to transfer the results in to Lists using ToList() after each LINQ call.

I have found it hard to replicate in my test environment, as it only happens on a clients installation.

David Foderick posted a similar issue he had with the Entity Framework

After speaking with Eric Nelson, he pointed out that SQL 2000 has a lack of support for MARS, however there is no planning to provide support for this, however SQL Azure does not allow MARS. So perhaps this issue will get addressed some time in the future?


JQuery and the DropDownList - ComboBox

October 28, 2009 08:59 by bryan

After playing around with Combo boxes for a while within jQuery I thought it would be good to write down, mainly so I can remember how to find and play with properties from within jQuery.  So here we go, here is the HTML that we'll be using:

 <select id="ComboBox" >
   <option value="1">Value 1</option>
   <option value="2">Value 2</option>
   <option value="3">Value 3</option>
   <option value="4">Value 4</option>
   <optgroup label="Group1">
      <option value="5">Value 5</option>
      <option value="6">Value 6</option>
      <option value="7">Value 7</option>
      <option value="8">Value 8</option>
   </optgroup>
</select>

Get the value of the selected item

This is the easiest.  Use the val method.

$("#ComboBox").val()

Get the text of the selected item

If you just try using the text() method on the combobox, this will give you the text values of all of the options in a single string.  Not what you want.  The trick is to use the :selected query modifier on the option.

$("#ComboBox option:selected").text()

Find out when the select value changed

This is also rather easy with JQuery.

$("#ComboBox").change(function() { /* do something here */ });

Programmatically set the selected item.

$("#ComboBox").val(2);

Modify the list.

Modifying a select element is not fundamentally different than modifying any other element in the dom, but there are a few basics here to keep in mind. Mainly: try to avoid using the dom directly.  Create html strings instead.

Clear the list:   $("#ComboBox").html("");

Add to the list: $("<option value=’9’>Value 9</option>").appendTo("#ComboBox");

For more information check out the jQuery API


Videos of Scott’s sessions at the Manchester “Guathon”

October 26, 2009 08:41 by bryan

 

Mike Taulty of Microsoft has now sorted out the Videos from the event Scott spoke at: -

Visual Studio .NET

Silverlight

ASP.NET MVC