Easy trick to speed up Visual Studio 2005

Posted on June 28, 2007

I found this on a Microsoft Forum Posting – apparently the navigation bar was slowing things down a bit – and if you’re anything like me, you never use it anyway.

The navigation bar is this thing at the top:

Go to Tools > Options > Text Editor > C# and click the Navigation Bar check box.

You should notice a speed boost when you type code or use intellisense!

(Be sure to turn it off for HTML if you use Asp.net as well. Tools > Options > Text Editor > HTML)

(I haven’t proved scientifically that this speeds things up yet…)

Snippet in Visual Studio to create static method

Posted on June 27, 2007

After using Textmate for a couple of weeks I’ve come to realise how incredibly powerful and beautiful it is! Creating text snippets is a breeze – and improves productivity no end!

To achieve the same affect in Visual Studio though is a right pain in the butt-ocks. All I wanted to do was create a very basic snippet to define a static method (because I was creating a bunch of them all at the same time) and had to get down and dirty with some XML.

Anyhoo – here’s my result:

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <Title>Public Static Method Declaration</Title>
      <Shortcut>pubs</Shortcut>
      <Description>Code snippet for creating a static method</Description>
      <Author>Chris O'Sullivan</Author>
      <SnippetTypes>
        <SnippetType>Expansion</SnippetType>
      </SnippetTypes>
    </Header>
    <Snippet>
      <Declarations>
        <Literal>
          <ID>return_type</ID>
          <ToolTip>Return Type</ToolTip>
          <Default>void</Default>
        </Literal>
        <Literal>
          <ID>method_name</ID>
          <ToolTip>Method Name</ToolTip>
          <Default>method</Default>
        </Literal>
        <Literal>
          <ID>param_type</ID>
          <ToolTip>Param Type</ToolTip>
          <Default>param_type</Default>
        </Literal>
        <Literal>
          <ID>param</ID>
          <ToolTip>Name of Param</ToolTip>
          <Default>param</Default>
        </Literal>
      </Declarations>
      <Code Language="csharp">
        <![CDATA[public static $return_type$ $method_name$($param_type$ $param$)
            {
            }
          ]]>
        </Code>
      </Snippet>
    </CodeSnippet>
    </CodeSnippets>
Then you just type pubs[tab] and it will create a declation like this:
public static void method(param_type param)
{
}

With the ability to tab between the different fields.

But oh man what a pain that was to do! (I love you textmate – xx)

Enumerating through .Net enums

Posted on June 18, 2007

So, I was working on something that required a loop through enumerated types (in this case, go through the different repayment methods of a mortgage calculator)

public enum RepaymentMethod
 {
     RepaymentOnly ,
     InterestOnly,
     MixOfBoth,
 }

To loop through this, use Enum.GetValues() to grab an array of the enumerations, and walk through it like this:

Array repaymentMethods = Enum.GetValues(typeof(RepaymentMethod));
foreach (RepaymentMethod method in repaymentMethods)
{
  calculator.RepaymentMethod = method;
  calculator.doStuff();   
  Assert.AreEqual(0, calculator.MonthlyPayments);
}

Free dotnet profiler

Posted on June 15, 2007

So yesterday I was working on an application that was going ridiculously slow and I couldn’t figure out why. That’s when I used the open source program nprof to profile my application to see where the bottlenecks are! (Download it here )

According to the documentation, this can also be used to profile web apps too!

It’s really easy to use. Open nprof exe

Input your executable path into the Application textbox (and any command line args in the Arguments textbox) and then hit F5. This will spawn a copy of your app that you can use normally. After the application successfully closes then you get a list of what methods were called during the running of the app and what percent of application time was spent in that application e.g:

Also on the left hand side in the Runs list you can see previous times you’ve run the program in the profiler – allowing you to make comparisons to see what methods are currently slowing you down.

Pretty cool!

Beautifully format your .net source code in seconds!

Posted on June 02, 2007
Ok, so you're creating a beautiful .aspx page - and then you flip to design mode to use an auto tag or something. You flip back to the source and WHAMMO your beautiful layout has been messed up by the stinking asp.net design mode!

So, you spend the next 5 minutes wasting your life by ensuring all the div tags etc line up...

OR

You hit Ctrl K then Ctrl D and in seconds your code is wonderfully, beautifully, elegantly laid out!

Fantastic!

This works on code-behind files as well