RSS Feed
 
 
4.5.2009 at 9:02 AM

C#.NET - Initialize auto-properties in Visual Studio 2008 like 2005

If you're like me, you like to use the "prop" snippet from Visual Studio 2005. If you don't know what I'm talking about, with a C# file open in Visual Studio 2005 (or 2008), type: prop then hit tab twice. In 2005, you are able to initialize the variable like so:

private string _name = "default"; public string Name { get { return _name; } set { _name = value; } }


However, in 2008, prop tab tab gives you the following..

public string Name { get; set; }


This is a problem because there's no simple quick way to initialize the variable.
You can initialize it in a constructor, but what if you're using a static class? You're only other option is to use a DefaultValue attribute like so:

[DefaultValue("default")] public string Name { get; set; }


The problem with using the DefaultValue attribute is that, as far as I know, it requires using Reflection. So not only is it a pain to type, you also take a performance hit.

The way that 2005 handled it still works in 2008, so the easiest solution is to use the snippet from 2005 in 2008. I have created a propx snippet to handle just that. Simply unzip and put the propx.snippet file into your My Code Snippets folder (in Windows 7 this is located at C:\Users\Gordon\Documents\Visual Studio 2008\Code Snippets\Visual C#\My Code Snippets\), restart visual studio then type propx tab tab to use it.
 
3.22.2009 at 1:34 PM

How to format XML in Smultron

In my quest to find a great text/code editor for Mac OS-X, so far, I've chosen Smultron. It has a nice set of features for what I need: It supports Unicode, can display East Asian characters just fine (shame on you TextMate), has project support, syntax highlighting, auto-complete and more, and it's free. Most importantly, it also has support to configure and run shell commands, which means you can use other apps to modify the text. One thing I found missing right off the bat was the ability to format, tabify, and indent XML, so it's time to find a command to format XML and integrate it with Smultron.

Read more to find out how to format XML in Smultron
 
1.17.2009 at 10:01 AM

Apps To Install After Windows 7

Everyone has a slew of apps they can't live without. I've compiled a list of apps I snag after a fresh Windows 7 install...

Hit the jump to see the list of apps and start downloading like mad. o_0
 
1.13.2009 at 8:37 PM

Windows 7 Tips

Tim Sneath on msdn.com has compiled a list of 30 Windows 7 secrets. Excellent for anyone who enjoys productivity.

The new keyboard shortcuts (and mouse gesture equivalents) for the new window management features allow you to dock windows to the sides, maximize/restore the window vertically (without changing window width), move a window to another monitor, hide all non-active windows, peek at the desktop (allowing you to see gadgets or icons without moving windows), set focus to the taskbar, or launch apps from the taskbar, all just with simple key combinations involving the Windows key.

Another useful tip is to Shift+Right-Click a folder to show the "Open Command Prompt Here" option in the context menu, which sets current working directory to that folder within the command shell.

Hit the jump to see more Windows 7 tips
 

 
 
alphatrak

Bringing you the coding smackdown since '95

Twitter Updates

    follow me on Twitter

    Now Playing

    • StarCraft - PC

    Now Reading

    • Death Note
    • Ikigami: The Ultimate Limit
    • Infinite Game Universe: Mathematical Techniques
    • Microserfs by Douglas Coupland
    • Pro Android 2