I was just wondering how it would be to have a “Did You Know” section in our blog. The objective of this section would be to have a max of 4 lines of text where in the first line would be the Title (duh), second line would be Solution, third line would be how it could be useful and finally a simple example. Let me know what you think.

Let me start of by giving the DYK series # 1

Did You Know that “It is possible to have default Binding in WPF?”

Solution : Just specify the FallbackValue

How can it be helpful: Helps designers to see some value before the control gets bound.

What is dirty checking?

Dirty checking is simply a way to check an object to see if it contains changes. This can be used to prevent unnecessary database updates. Properly implemented it should also account for the object changing back to its original state.

For example:

We change the spelling of a dog’s name “Spottie” to “Spotty". If we were to test the object it should return dirty.

Then if we decide the original spelling was correct and change it back to “Spottie” the object should no longer return dirty.

How we implemented it:

We wanted to extend our LINQtoSQL generated classes to implement dirty checking. All we had to do was extend the OnLoaded() method to call our copy constructor so that we had a private copy of the original object. Then we can simply check that private object against the current object state property by property to determine if the object was dirty.

We all know about Partial Classes (in case you dont know read here) but I was intriqued when I look at LINQ to SQL generated designer.cs. I saw methods like

partial void OnLoaded();

partial void OnCreated();

After a bit of researching I came to know that these are called as Partial Methods and their implementation is pretty neat. Check out this blog to get an overview about partial method implementation Or check out this blog for a detailed explanation about Partial methods.

This is a code script which I did while I was helping out a friend in his project. This is a pretty neat implementation of having overloaded methods in JQuery. For this to work I utilized a sweet method which John Resig wrote as given below:

Visual Studio is such a powerful tool. I believe it is one of the major reasons why I enjoy .Net development over other platforms.

I thought I would share my top 10 favorite Visual Studio features with their keyboard shortcuts. The ones I couldn’t live without. Then I realized I could only come up with 5. This made me think I need to spend some time exploring the application I use more than any other application (Firefox not included) in my toolbox. So here are my top 5. Check back later for my “Top 5 Newly Discovered Features” post.

In no particular order…

-Find All (Ctrl+Shift+F)

Highlight a search term and you can search across the current document, all open documents, an entire solution or an entire project. Your results window will pop up and you’ll be able to view the line that contains the search term. Double click the line to go to it in code. I don’t know why everyone uses the classic find and next when this is just as easy but much more powerful.

-Comment\Uncomment selected lines (Ctrl+K, Ctrl+C), (Ctrl+K, Ctrl+U)

This has to be one of the most used features ever. It is so basic I wouldn’t consider an IDE without it an actual IDE. Without this you might as well be developing in notepad.

-Collapse\Open code (Ctrl+M, Ctrl+O), (Ctrl+M, Ctrl+L)

This one is really great. Assuming you aren’t using regions (which really can interfere with the usability\readability here) you can enter this shortcut chord (Ctrl+M, Ctrl+O) to collapse all properties and method details for a nice clean view of your class. Pressing (Ctrl+M, Ctrl+L) will open the whole class again or you can open individual section using the (+/-) toggle to the left.

-Refactor Rename (Ctrl+R, Ctrl+R)

Naming is huge in writing good code. Sometimes it just isn’t easy to find that perfect name when you first create something or a better name becomes apparent as you add additional items that have similar names. With this feature renaming a variable, method, property or class becomes 2 seconds of work. A lot of people may use search and replace but this actually uses the compiler to ensure it only renames what it should.

-Go to Definition (F12)

I remember when I first saw another developer use this and I couldn’t believe I had been working in VS for almost 6 months without knowing about it. Again it is so basic some may forget it is actually a feature but I’m sure if I captured my keyboard shortcuts it would be up at the top of the list of most used.