I just had one of those WOW experience today when I happened to use the switch code snippet with an enum.
I had an enum like this:
1: enum MyEnum
Start the video to se what happened when I tapped out of the snippet "switch_on" field.
WOW the snippet automatically created:
for each element in the enum. But how did it do that? Looking into the switch.snippet file I found:
It's the GenerateSwitchCases function that's doing the job - one out of 3 pre defined functions that available to "snippets"
I don’t know about you but I for my part often end out writing linear code.
Maybe it’s a hangover from writing to much BASIC code in the mid 80’s or maybe it’s just me thinking linear and not that much object-oriented. After all I often end up with “long functions” that includes code that could be isolated in “sub functions”.
Today one of my colleges pointed out the Refactor->Extract Method function. This function takes a part of your code and isolate it’s in a separate function.
Look at the code in this Page_Load: its includes some silly greeting stuff (just for the demo), the function is long and hard to read, lets try to separate the greetings part in a separate function.
Highlight the code you want to move to a new function, right click and select Refactor -> Extract Metod.
Give the function a nice name (getGreeting). Notice the signature preview show what parameters the function will be created with.
The Page_Load after generating the getGreeting function - nice and easy to read ;-)
The auto generated function takes 2 parameters and return a string
In Visual Studio 2005 typing "prop[tab][tab]" will give you something like this:
This is fine and one of the most time saving code snippets ever invented. If one type the same in Visual Studio 2008 it's ends out a little different:
This is due to the new Automatic Properties Feature in .NET 3.0/VS 2008. This is somehow also fine as long as one don't want to maintain a .NET 2.0 project with VS 2008, doing this will end up with an compile time error saying:".. must declare a body because it is not marked abstract or extern"
A solution to this is to download this file:
prop.zip (604,00 bytes)
place in your "My Code Snippets" folder:
C:\users\*your user name*\Documents\Visual Studio 2008\Code Snippets\Visual C#\My Code Snippets
Now you can simply type propp[tab][tab] in Visual Studio 2008 and get the VS 2005 style property snippet. Why propp? After typing porp your finger is over the [p] button so I thought it would be the fastest solution. If you don't like it: open the prop.snippet file with Visual Studio or any text editor and edit the shortcut tag:
21. Februar 2008 22:40
by Henrik Stenbæk
Generate it at http://creatr.cc/creatr/
alternative make one at ***NO LONGER ONLINE*** http://www.logogenerador.com/
21. Februar 2008 00:30
by Henrik Stenbæk
I couldn't help it, I have started another "theme adaption" ... take a sneak peek on my work-in-Progress:
Yet another WordPress theme on it's way to BlogEngine.NET. This one also original designed by Design Disease.
UPDATE 22. OCT 2008
The BE version of this theme is finally ready - please visit this post