My name is Edward Tanguay. I'm an American software and web developer living and working in Berlin, Germany.
13 hours ago: Good podcast discussion on the relationship between hume and rousseau: http://is.gd/7Y0bn.
14 hours ago: Good stackoverflow podcast, lots on apple, generally positive toward the ipad: http://is.gd/7XUjE.
14 hours ago: Why we fall #berlin #ice #crazy, http://is.gd/7XQmk.
2 days ago: Jquery will make it palatable RT @pholdings: i have seen the future and...oh, shit, i'm gonna have to program in javascript?
2 days ago: Germany vs. Google Street View: "a millionfold violation of privacy": http://is.gd/7R5W1.
3 days ago: Thanks TimothyP, File.ReadAllText() works well, nice to know: http://is.gd/7N8yo.
3 days ago: WPF CODE EXAMPLE: Custom ChooserGroup control which allows user to change selection kind from dropdown to radiobuttons: http://is.gd/7N96b.
3 days ago: C# CODE EXAMPLE: Base code to create a simple regex unit tester: http://is.gd/7N8Hf.
3 days ago: WPF CODE EXAMPLE: How to use a WPF FileDialog to read in a text file: http://is.gd/7N8yo.
3 days ago: XAML CODE EXAMPLE: How to stop a XAML button from expanding to the size of its parent width (stop the madness): http://is.gd/7N8pr.
3 days ago: I'm a pretty public guy but I'm not sure I'd go as far as blippy: http://blippy.com.
WPF CODE EXAMPLE created 3 days ago permalink
Custom ChooserGroup control which allows user to change selection kind from dropdown to radiobuttons
This is an example of how to make a control that abstracts the dropdown and radiobutton controls away so that you can make a "ChooserGroup" and then render it as a: (1) dropdown, (2) radio buttons vertical, or (3) radio buttons horizontal. This control has a custom OnChoiceItemChanged event which even abstracts the handling of a changed item no matter what type of control has been rendered.
XAML:
<Window x:Class="TestRad2343.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    WindowStartupLocation="CenterScreen"
    Title="Window1" Height="350" Width="300">
    <Window.Resources>
        <Style TargetType="{x:Type GroupBox}" x:Key="GroupBoxMain">
            <Setter Property="Padding" Value="10" />
            <Setter Property="Margin" Value="0 0 0 10" />
            <Setter Property="BorderBrush" Value="#ccc" />
            <Setter Property="BorderThickness" Value="2" />
        </Style>
        <Style TargetType="{x:Type TextBlock}" x:Key="GroupBoxHeaderMain">
            <Setter Property="FontFamily" Value="Lucida Sans" />
            <Setter Property="FontSize" Value="12" />
            <Setter Property="Foreground" Value="#aaa" />
        </Style>

    </Window.Resources>

    <StackPanel Margin="10" HorizontalAlignment="Left">

        <GroupBox Style="{DynamicResource GroupBoxMain}" Margin="0 0 0 10">
            <GroupBox.Header>
                <TextBlock Text="Switch the Chooser"
                                    Style="{DynamicResource GroupBoxHeaderMain}"/>
            </GroupBox.Header>
            <StackPanel>
                <StackPanel HorizontalAlignment="Left" VerticalAlignment="Top" >
                    <Button x:Name="ButtonForDropDown" Content="Drop Down" Padding="3" Margin="0 0 0 3" Click="Button_Click_DropDown"/>
                    <Button x:Name="ButtonForRadioButtonsHorizontal" Content="Radio Buttons Horizontal" Padding="3" Margin="0 0 0 3" Click="Button_Click_RadioButtonsHorizontal" />
                    <Button x:Name="ButtonForRadioButtonsVertical" Content="Radio Buttons Vertical" Padding="3" Margin="0 0 0 3"    Click="Button_Click_RadioButtonsVertical"/>
                </StackPanel>
            </StackPanel>
        </GroupBox>

        <StackPanel HorizontalAlignment="Left" Margin="0 0 0 10">
            <ContentControl x:Name="ControlArea"/>
        </StackPanel>

        <StackPanel HorizontalAlignment="Left" Margin="0 0 0 10">
            <Button x:Name="SubmitButton" Content="Submit" Click="Button_Click_Submit"/>
        </StackPanel>

        <TextBlock x:Name="Message" Foreground="Blue" Margin="0 0 0 10"/>
    </StackPanel>
</Window>

Code Behind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Globalization;
using System.ComponentModel;

namespace TestRad2343
{
    public partial class Window1 : Window, INotifyPropertyChanged
    {
        #region ViewModelProperty: SelectedIdCode
        private string _selectedIdCode;
        public string SelectedIdCode
        {
            get
            {
                return _selectedIdCode;
            }

            set
            {
                _selectedIdCode = value;
                OnPropertyChanged("SelectedIdCode");
            }
        }
        #endregion //test

        private ChooserDirection chooserDirection = new ChooserDirection();
        private ChooserKind chooserKind = new ChooserKind();

        private string choices = "one, two, three, four, five, six";

        public Window1()
        {
            InitializeComponent();

            chooserKind = ChooserKind.RadioButtons;
            chooserDirection = ChooserDirection.Vertical;
            ManageButtonEnabling("radioButtonsVertical");
            SelectedIdCode = "two";

            RefreshPage();
        }

        void RefreshPage()
        {
            WrapPanel wp = new WrapPanel();
            ChooserGroup chooserGroup = new ChooserGroup("chooser1", choices, SelectedIdCode);
            chooserGroup.ChooserKind = chooserKind;
            chooserGroup.ChooserDirection = chooserDirection;
            ControlArea.Content = chooserGroup.Render();
            chooserGroup.OnChoiceItemChanged += new ChooserGroup.ChoiceItemChangedHandler(chooserGroup_OnChoiceItemChanged);

            SubmitButton.Tag = chooserGroup;
        }

        void chooserGroup_OnChoiceItemChanged(object sender, ChoiceItemArgs args)
        {
            ChooserGroup chooserGroup = sender as ChooserGroup;
            SelectedIdCode = chooserGroup.GetSelectedIdCode();
        }

        private void Button_Click_Submit(object sender, RoutedEventArgs e)
        {
            ChooserGroup chooserGroup = ((Button)sender).Tag as ChooserGroup;
            Message.Text = String.Format("You selected '{0}'.", chooserGroup.GetSelectedIdCode());
        }

        private void Button_Click_DropDown(object sender, RoutedEventArgs e)
        {
            chooserKind = ChooserKind.DropDown;
            ManageButtonEnabling("dropDown");
            RefreshPage();
        }

        private void Button_Click_RadioButtonsHorizontal(object sender, RoutedEventArgs e)
        {
            chooserKind = ChooserKind.RadioButtons;
            chooserDirection = ChooserDirection.Horizontal;
            ManageButtonEnabling("radioButtonsHoriztonal");
            RefreshPage();
        }

        private void Button_Click_RadioButtonsVertical(object sender, RoutedEventArgs e)
        {
            chooserKind = ChooserKind.RadioButtons;
            chooserDirection = ChooserDirection.Vertical;
            ManageButtonEnabling("radioButtonsVertical");
            RefreshPage();
        }

        public void ManageButtonEnabling(string buttonToEnable)
        {
            switch (buttonToEnable)
            {
                case "dropDown":
                    ButtonForDropDown.IsEnabled = false;
                    ButtonForRadioButtonsHorizontal.IsEnabled = true;
                    ButtonForRadioButtonsVertical.IsEnabled = true;
                    break;
                case "radioButtonsHoriztonal":
                    ButtonForDropDown.IsEnabled = true;
                    ButtonForRadioButtonsHorizontal.IsEnabled = false;
                    ButtonForRadioButtonsVertical.IsEnabled = true;
                    break;
                case "radioButtonsVertical":
                    ButtonForDropDown.IsEnabled = true;
                    ButtonForRadioButtonsHorizontal.IsEnabled = true;
                    ButtonForRadioButtonsVertical.IsEnabled = false;
                    break;
                default:
                    break;
            }
        }

        #region INotifiedProperty Block
        public event PropertyChangedEventHandler PropertyChanged;

        protected void OnPropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;

            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }
        #endregion //test

    }

    public class ChooserGroup
    {
        public ChooserDirection ChooserDirection { get; set; }
        public ChooserKind ChooserKind { get; set; }

        private string idCode;
        private List<ChoiceItem> choiceItems = new List<ChoiceItem>();
        private List<RadioButton> internalRadioButtons = new List<RadioButton>();
        private ComboBox internalComboBox = new ComboBox();
        private List<ComboBoxItem> internalComboBoxItems = new List<ComboBoxItem>();


        public delegate void ChoiceItemChangedHandler(object obj, ChoiceItemArgs args);
        public event ChoiceItemChangedHandler OnChoiceItemChanged;


        public ChooserGroup(string chooserIdCode, string choiceList, string selectedChoice)
        {
            idCode = chooserIdCode;
            List<string> choices = choiceList.BreakIntoParts(',');
            choiceItems = ChoiceItem.GetChoiceItemsWithStringList(choices, selectedChoice);
            ChooserKind = ChooserKind.RadioButtons;
            ChooserDirection = ChooserDirection.Vertical;
        }

        public StackPanel Render()
        {
            switch (ChooserKind)
            {
                case ChooserKind.RadioButtons:
                    return RenderAsRadioButtons();
                case ChooserKind.DropDown:
                    return RenderAsDropDown();
                default:
                    return new StackPanel();
            }
        }

        StackPanel RenderAsDropDown()
        {
            StackPanel spWrapper = new StackPanel();
            int index = 0;
            foreach (var choiceItem in choiceItems)
            {
                ComboBoxItem comboBoxItem = new ComboBoxItem { Tag = choiceItem.IdCode, Content = choiceItem.Title };
                internalComboBox.Items.Add(comboBoxItem);
                if (choiceItem.IsSelected)
                    internalComboBox.SelectedIndex = index;
                index++;
                internalComboBoxItems.Add(comboBoxItem);
            }
            if (internalComboBox.SelectedItem == null)
            {
                if (internalComboBox.Items.Count > 0)
                    internalComboBox.SelectedItem = internalComboBox.Items[0];
            }
            spWrapper.Children.Add(internalComboBox);

            internalComboBox.SelectionChanged += new SelectionChangedEventHandler(internalComboBox_SelectionChanged);

            return spWrapper;

        }

        void internalComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ChoiceItemArgs args = new ChoiceItemArgs("");
            OnChoiceItemChanged(this, args);
        }

        StackPanel RenderAsRadioButtons()
        {
            StackPanel spWrapper = new StackPanel();

            StackPanel spDirectionWrapper = new StackPanel();
            WrapPanel wpDirectionWrapper = new WrapPanel();

            foreach (var choiceItem in choiceItems)
            {
                RadioButton rb = new RadioButton();
                rb.Content = choiceItem.Title;
                rb.Tag = choiceItem.IdCode;
                rb.GroupName = idCode;
                rb.Cursor = Cursors.Hand;
                if (choiceItem.IsSelected)
                    rb.IsChecked = true;
                else
                    rb.IsChecked = false;

                if (ChooserDirection == ChooserDirection.Horizontal)
                {
                    rb.Margin = new Thickness(5);
                    wpDirectionWrapper.Children.Add(rb);
                }
                else
                {
                    spDirectionWrapper.Children.Add(rb);
                }
                rb.Checked += new RoutedEventHandler(rb_Checked);
                internalRadioButtons.Add(rb);
            }

            if (ChooserDirection == ChooserDirection.Horizontal)
                spWrapper.Children.Add(wpDirectionWrapper);
            else
                spWrapper.Children.Add(spDirectionWrapper);

            return spWrapper;
        }

        void rb_Checked(object sender, RoutedEventArgs e)
        {
            ChoiceItemArgs args = new ChoiceItemArgs("");
            OnChoiceItemChanged(this, args);
        }

        public string GetSelectedIdCode()
        {
            switch (ChooserKind)
            {
                case ChooserKind.RadioButtons:
                    return GetSelectedIdCodeFromRadioButtons();
                case ChooserKind.DropDown:
                    return GetSelectedIdCodeFromDropDown();
                default:
                    return "";
            }
        }

        string GetSelectedIdCodeFromRadioButtons()
        {
            foreach (var internalRadioButton in internalRadioButtons)
            {
                if (internalRadioButton.IsChecked.Value)
                    return internalRadioButton.Tag.ToString();
            }
            return null;
        }

        string GetSelectedIdCodeFromDropDown()
        {
            int selectedIndex = internalComboBox.SelectedIndex;
            ComboBoxItem selectedComboBoxItem = internalComboBoxItems[selectedIndex];
            return selectedComboBoxItem.Tag.ToString();
        }
    }

    public class ChoiceItemArgs : EventArgs
    {
        public string Message { get; set; }

        public ChoiceItemArgs(string message)
        {
            Message = message;
        }
    }

    public enum ChooserDirection
    {
        Horizontal,
        Vertical
    }

    public enum ChooserKind
    {
        DropDown,
        RadioButtons
    }

    public class ChoiceItem
    {
        public string IdCode { get; set; }
        public string Title { get; set; }
        public bool IsSelected { get; set; }

        public static List<ChoiceItem> GetChoiceItemsWithStringList(List<string> rawChoices, string selectedValue)
        {
            if (rawChoices == null)
                return null;
            List<ChoiceItem> choiceItems = new List<ChoiceItem>();
            foreach (var rawChoice in rawChoices)
            {
                ChoiceItem ci = new ChoiceItem();
                ci.IdCode = rawChoice;
                TextInfo text = new CultureInfo("en-US", false).TextInfo;
                ci.Title = text.ToTitleCase(rawChoice);
                if (ci.IdCode == selectedValue)
                    ci.IsSelected = true;
                choiceItems.Add(ci);
            }
            return choiceItems;
        }
    }

    public static class StringHelpers
    {
        public static List<string> BreakIntoParts(this string line, char separator)
        {
            if (String.IsNullOrEmpty(line))
                return null;
            else
                return line.Split(separator).Select(p => p.Trim()).ToList();
        }
    }
}
 
C# CODE EXAMPLE created 3 days ago permalink
Base code to create a simple regex unit tester
Here's some base code I use when I've written a regex and need to test it with positive and negative cases as I tweak it.
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;

namespace Testreg2342
{
    public class Program
    {
        static void Main(string[] args)
        {
            bool unitTestPassed = true;

            List<string> goodEntries = new List<string>
            {
                "2008-12-22"
            };

            List<string> badEntries = new List<string>
            {
                "2010-12-12X",
                "2010-12-32 12:00:00"
            };

            foreach (var entry in goodEntries)
            {
                if (entry.IsValidDateFormat())
                    Console.WriteLine("ok: good entry correctly passed: " + entry);
                else
                {
                    Console.WriteLine("**FAIL** GOOD ENTRY INCORRECTLY DID NOT PASS: " + entry);
                    unitTestPassed = false;
                }
            }

            foreach (var entry in badEntries)
            {
                if (!entry.IsValidDateFormat())
                    Console.WriteLine("ok: bad entry corrcectly did not pass : " + entry);
                else
                {
                    Console.WriteLine("**FAIL** BAD ENTRY INCORRECTLY PASSED: " + entry);
                    unitTestPassed = false;
                }
            }

            Console.WriteLine();
            if(unitTestPassed)
                Console.WriteLine("unit test passed");
            else
                Console.WriteLine("UNIT TEST FAILED, CORRECT ALL ENTRIES MARKED **FAIL** ABOVE!");

            Console.ReadLine();

        }
    }

    public static class StringHelpers
    {
        public static bool IsValidDateFormat(this string purportedDateFormat)
        {
            return RegexHelpers.Matches(purportedDateFormat, @"^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$");
        }
    }

    public static class RegexHelpers
    {

        //use if you are expecting only one match, e.g. from "id = ???"
        public static string GetMatch(string text, string regex)
        {
            Match match = Regex.Match(text, regex);
            if (match.Success)
            {
                string theMatch = match.Groups[0].Value;
                return theMatch;
            }
            else
            {
                return null;
            }
        }

        public static bool Matches(string text, string regex)
        {
            if (GetMatch(text, regex) != null)
                return true;
            else
                return false;
        }
    }
}
 
WPF CODE EXAMPLE created 3 days ago permalink
How to use a WPF FileDialog to read in a text file
This example shows how you can allow the user to click on a button and choose a text file to view the contents of the file in a scrollable box on the screen.
XAML:
<Window x:Class="TestFileDialog2343.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="350">
    <StackPanel Margin="10" HorizontalAlignment="Left">
        <StackPanel HorizontalAlignment="Left">
            <Button Content="Load File"
                Click="Button_LoadFile_Click"
                Margin="0 0 0 10"/>
        </StackPanel>
        <ScrollViewer
            Width="300"
            Height="200">
            <TextBox x:Name="TextFileContent"
                 TextWrapping="Wrap"/>
        </ScrollViewer>
    </StackPanel>
</Window>

Code Behind:
using System.Windows;
using Microsoft.Win32;
using System.Text;
using System.IO;
using System;

namespace TestFileDialog2343
{
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
        }

        private void Button_LoadFile_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();
            dlg.DefaultExt = ".txt";
            dlg.InitialDirectory = @"C:test";
            dlg.Filter = "Text documents (.txt)|*.txt";

            bool? result = dlg.ShowDialog();

            if (result == true)
            {
                TextFileContent.Text =File.ReadAllText(dlg.FileName);
            }
        }

    }
}
 
XAML CODE EXAMPLE created 3 days ago permalink
How to stop a XAML button from expanding to the size of its parent width
A trick to get a XAML button to expand only to the size of its text content is to wrap it with a StackPanel that has a HorizontalAlignment="Left".
Button expands to fill width:
    <DockPanel Style="{DynamicResource BasePageItemDockPanelStyle}">
        <Border
            DockPanel.Dock="Top">
            <StackPanel
                HorizontalAlignment="Left"
                VerticalAlignment="Top">
                <TextBlock Text="{Binding PageTitle}" Style="{DynamicResource PageTitleStyle}"/>
                <TextBlock Text="{Binding PageDescription}" Style="{DynamicResource PageDescriptionStyle}"/>
                <Button Content="Upload File" Click="Button_Click"/>
            </StackPanel>
        </Border>
    </DockPanel>

Button exands only to width of text:
    <DockPanel Style="{DynamicResource BasePageItemDockPanelStyle}">
        <Border
            DockPanel.Dock="Top">
            <StackPanel
                HorizontalAlignment="Left"
                VerticalAlignment="Top">
                <TextBlock Text="{Binding PageTitle}" Style="{DynamicResource PageTitleStyle}"/>
                <TextBlock Text="{Binding PageDescription}" Style="{DynamicResource PageDescriptionStyle}"/>
                <StackPanel HorizontalAlignment="Left">
                    <Button Content="Upload File" Click="Button_Click"/>
                </StackPanel>
            </StackPanel>
        </Border>
    </DockPanel>
 
WPF CODE EXAMPLE created 7 days ago permalink
How to pass an event handler as a parameter
This example shows how you can pass an event handler into a method (here a constructor of a class) so that method or class can attach that method handler to controls, thus making "how to deal with a click event" something you can pass in as any other variable.
XAML:
<Window x:Class="TestDel234.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300">
    <StackPanel Margin="10" Orientation="Horizontal">
        <StackPanel x:Name="MainContentLeft"/>
        <StackPanel x:Name="MainContentRight"/>
    </StackPanel>
</Window>

Code Behind:
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;

namespace TestDel234
{
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
            List<string> items = new List<string> { "one", "two", "three" };
            SmartGrid sg = new SmartGrid(MainContentLeft, items, DisplayHelpText1);
            SmartGrid sg2 = new SmartGrid(MainContentRight, items, DisplayHelpText2);
        }

        private void DisplayHelpText1(object sender, MouseButtonEventArgs e)
        {
            MessageBox.Show("this is the help text for column 1");
        }

        private void DisplayHelpText2(object sender, MouseButtonEventArgs e)
        {
            MessageBox.Show("this is the help text for column 2");
        }
    }

    public class SmartGrid
    {
        public SmartGrid(StackPanel sp, List<string> items, EventHandler<MouseButtonEventArgs> eventHandler)
        {
            foreach (var item in items)
            {
                TextBlock tb = new TextBlock();
                tb.Text = item;
                tb.MouseDown += new MouseButtonEventHandler(eventHandler);
                tb.Margin = new Thickness(10);
                tb.Cursor = Cursors.Hand;
                sp.Children.Add(tb);
            }
        }
    }
}
 
JQUERY CODE EXAMPLE created on Monday, February 01, 2010 permalink
How to make open/close flashcards with JQuery
This example shows you how to make flashcards so that the user can click on the header to open and close them.
> > > View Demo
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <script type="text/javascript"
        src="http://www.google.com/jsapi"></script>
        <script type="text/javascript">
            google.load("jquery", "1.4.0");
            google.setOnLoadCallback(function() {
            $("div > div.question").click(function() {
                if($(this).next().is(':hidden')) {
                $(this).next().fadeIn("slow");
                } else {
                $(this).next().fadeOut("slow");
                }
            });    
            });
    
        </script>
        <style>
            div.flashcard {
                margin: 0 10px 10px 0;
            }
            div.flashcard div.question {
                background-color:#ddd;
                width: 400px;        
                padding: 5px;    
                cursor: hand;    
                cursor: pointer;
            }
            div.flashcard div.answer {
                background-color:#eee;
                width: 400px;
                padding: 5px;    
                display: none;        
            }
        </style>
    </head>

<body>
    <div id="1" class="flashcard">
    <div class="question">Who was Wagner?</div>
    <div class="answer">German composer, conductor, theatre director and essayist, primarily known for his operas (or "music dramas", as they were later called). Unlike most other opera composers, Wagner wrote both the music and libretto for every one of his works.</div>
    </div>
    
    <div id="2" class="flashcard">
    <div class="question">Who was Thalberg?</div>
    <div class="answer">a composer and one of the most distinguished virtuoso pianists of the 19th century.</div>
    </div>
</body>
</html>
 
C# CODE EXAMPLE created on Saturday, January 30, 2010 permalink
How to create a generic method to return a specific type specified by the call
This method allows the caller to specify the type of variable he knows he will be getting, useful e.g. if you are doing reflection and only the caller knows what types to expect from a generic method. There is a discussion at stackoverflow on where most people say that this example is a "misuse of generics", interesting, since it is a solution done in less code with the same outcome.
using System;
using System.Collections.Generic;

namespace TestGener234
{
    class Program
    {
        static void Main(string[] args)
        {
            List<Item> items = Item.GetItems();
            foreach (var item in items)
            {
                string firstName = item.GetPropertyValue<string>("firstName");
                int age = item.GetPropertyValue<int>("age");
                Console.WriteLine("First name is {0} and age is {1}.", firstName, age);
            }
            Console.ReadLine();
        }
    }

    public class Item
    {
        public string FirstName { get; set; }
        public string Age { get; set; }


        public static List<Item> GetItems()
        {
            List<Item> items = new List<Item>();
            items.Add(new Item { FirstName = "Jim", Age = "34" });
            items.Add(new Item { FirstName = "Angie", Age = "32" });
            return items;
        }

        public T GetPropertyValue<T>(string propertyIdCode)
        {
            if (propertyIdCode == "firstName")
                return (T)(object)FirstName;
            if (propertyIdCode == "age")
                return (T)(object)(Convert.ToInt32(Age));
            return default(T);
        }
    }
}
 
WPF CODE EXAMPLE created on Friday, January 29, 2010 permalink
How to use brackets to define scope
In the past especially in unit-test code I've found myself creating variables such as **customer1**, **customer2**, **customer3** in one method since it was all the same scope. Just discovered that you can use brackets like this to create scope so that you can use the same variable repeatedly.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TestScope8383
{
    class Program
    {
        static void Main(string[] args)
        {
            TheTest tt = new TheTest();
        }
    }

    public class TheTest
    {
        List<Customer> customers = new List<Customer>();

        public TheTest()
        {
            {
                Customer customer = new Customer { LastName = "Smith" };
                customers.Add(customer);
            }
            {
                Customer customer = new Customer { LastName = "Thompson" };
                customers.Add(customer);
            }

            customers.ForEach(c => Console.WriteLine(c.LastName));
            Console.ReadLine();
        }
    }
    public class Customer
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string Street { get; set; }
        public string Location { get; set; }
        public string ZipCode { get; set; }

    }
}
 
JQUERY CODE EXAMPLE created on Wednesday, January 27, 2010 permalink
JQuery all-in-one template page for quick examples
This is a HTML/Javascript/JQuery/CSS template that I use to quickly try out a JQuery example or post an issue on a forum. It loads the latest version of jquery from google, everything all in one page, just change the jquery, javascript, css, html as you need it.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <script type="text/javascript"
        src="http://www.google.com/jsapi"></script>
        <script type="text/javascript">
            google.load("jquery", "1.3.2");
            google.setOnLoadCallback(function() {
                $('#first').css("background-color","lightgreen");
                $('#toggleButton').css("background-color","yellow").click(highlightIt);
            });
            function highlightIt() {
                $('#selected').toggleClass('highlighted');
            }

        </script>
        <style>
            p.highlighted {
                background-color:yellow;
            }
            p.regular {
                font-weight: normal;
            }
        </style>
    </head>

<body>
    <p id="first">First</p>
    <p>Second</p>
    <p id="selected" class="regular">Third</p>
    <p>Fourth</p>
        <input id="toggleButton" type="button"
            value="toggle highlight on 3rd paragraph"/>
</body>
</html>
 
C# CODE EXAMPLE created on Wednesday, January 27, 2010 permalink
How to make StringBuilder have a .Clear() method
During the last decade everytime I wanted to clear a StringBuilder I had to look around for the code to do it (sb.Remove(0,sb.Length)), but if you put this in an extension method, you can simply call sb.Clear() to clear a StringBuilder.
using System;
using System.Text;

namespace TestStringBuil234
{
    public class Program
    {
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("one,");
            sb.Append("two");
            Console.WriteLine("[" + sb.ToString() + "]");
            sb.Clear();
            Console.WriteLine("[" + sb.ToString() + "]");

            Console.ReadLine();
        }
    }

    public static class StringHelpers
    {
        public static StringBuilder Clear(this StringBuilder sb)
        {
            return sb.Remove(0, sb.Length);
        }
    }
}