Thursday, November 20, 2008
C# 4 - Default Parameters
void foo(int a, int b, int c=3, int d=4)
It wouldn't let you do:
void foo(int a=1, int b=2, int c, int d)
C# will, so for the example above, you'd end up with method calls that could look like:
foo( , , 3, 4)
One feature that I still really miss from C++ is const. This keyword could be applied to methods or parameters, so a method declared as:
void foo(int a, int b) const
{
}
would be guaranteed to not modify the state of the object (except for mutable members)
A method declared as:
void foo(const Person person)
{
}
would be guaranteed to not modify the person.
Maybe C# 5?
Wednesday, November 19, 2008
Adding folders to the Class View in Visual Studio
Thanks to Sara Ford for her post describing this.
There's more good news! When you're editing code in the editor and you're over a class or method, you can use the 'Synchronise Class View' command (I've mapped mine to a keyboard short-cut, but you can add a toolbar item) to synchronise the Class View to the item you're currently editing. Once synchronised, you can go to Class View and drag that into one of your folders.
Also, when you do this, you won't upset any of your team with changes to the solution or project files - because these are your settings, and hence are stored in the .suo file (which, on the other hand could be a pain, because user option files shouldn't be checked into your source repository).
Anyway, this is the next best thing to a 'bread-crumb' feature in the editor that let's you jump around to favourite places in the the code. Maybe the bread-crumb feature will be in the next version of ReSharper?
Monday, October 20, 2008
Displaying values in the Visual Studio Debugger
If you wanted to copy a value value to the clipboard (maybe because you landed on an exception and you want to send the error to

To get rid of formatting (the quotes and the control characters), use the ,nq option:

This is useful in itself, but it really becomes invaluable if you want to show some XML. With the magical ,nq switch, the following code:

produces the following output in the immediate window:

Pretty useless, but if you add ,nq, you get:

Much nicer.
nq stands for nice'n quick, because it doesn't waste time writing quotes. Probably.
Friday, June 27, 2008
Excluding Items From Code Coverage
There's an attribute in nCover that can be applied to your code to exclude it when doing code coverage. This is handy for auto-generated types such as web services etc.
The attribute is in the nCover assembly, but most people wouldn't want to ship with their assemblies. Fortunately, you can define your own attribute. If you're using TestDriven.NET, call it 'CoverageExcludeAttribute', if not, call it what you want.
When using NCover, pass the name of the attribute in the /ea WhateverYouCalledTheAttribute command line attribute.
Here's the code, with comments. Remember, don't put this in a namespace!
/// <summary>
/// Use this attribute on types that do not need code coverage analysis.
/// Such types are auto-generated types, such as web services etc.
///
/// This attribute is used by TestDriven.NET to exclude the type/method in the 'test with coverage' functionality.
/// This attribute can also be passed to NCover proper by using the /ea CoverageExcludeAttribute command line.
/// </summary>
/// <remarks>
/// Note that this should NOT be part of a namespace!
/// </remarks>
[CoverageExclude]
class CoverageExcludeAttribute : Attribute { }
Saturday, June 21, 2008
Wednesday, December 12, 2007
Code Formatter Plug-in for Windows Live Writer
Version 1.0.0.4 of my plug-in for Windows Live Writer (WLW) is now available. This version is for the released version of WLW. As with the previous version, the following languages are supported:
- Assembly
- BatchFile
- CSharp
- CSS
- HTML
- INIFile
- Java
- JScript
- Lua (pronounced LOO-ah)
- MSIL
- Pascal
- Perl
- PHP
- PowerShell
- Python
- SQL
- VBDotNet
- VBScript
- XAML
- XML
Download it now from my tools page.
Thanks to everyone who left comments and feedback; this addressed two issues reported - 1 with inserting pictures and then editing a block of code, and the other was with duplicate scroll-bar options.
Sunday, September 23, 2007
New version of the Code Formatter Plug-in for Windows Live Writer.
Version 1.0.0.3 of my plug-in for Windows Live Writer is now available. This version works with the new Beta 3 version of WLW (and also older versions).
Languages now include:
- Assembly
- BatchFile
- CSharp
- CSS
- HTML
- INIFile
- Java
- JScript
- Lua (pronounced LOO-ah)
- MSIL
- Pascal
- Perl
- PHP
- PowerShell
- Python
- SQL
- VBDotNet
- VBScript
- XAML
- XML
Download it now from my tools page.
