Friday, August 25, 2006

ReSharper 2.0.1 Maintenance Release Now Available

 

ReSharper 2.0.1 Maintenance Release Now Available

JetBrains ReSharper version 2.0.1 is now available for download at http://www.jetbrains.com/resharper/download/.
This release fixes a number of bugs and usability issues, in addition to substantial performance improvements. For more information, please see online Release Notes.
The update is a free maintenance release for all licensed users of previous ReSharper versions. All current users are highly encouraged to upgrade, due to the transition of the ReSharper development project to a new issue tracking system. So, the new release automatically sends bugs and exceptions to this new system.
Keep developing with pleasure!

Source: JetBrains .NET Tools Blog » Blog Archive » ReSharper 2.0.1 Maintenance Release Now Available

Wednesday, August 23, 2006

Code Formatter Plugin now on Codeplex

Check it out on Codeplex.  Please leave feedback on anything you'd like see.  The source code is there if you want to look around.  Let me know if you'd like to contribute.

Tuesday, August 22, 2006

Resharper 2.0.1 RC2 is now available.

One of the best tools ever just keeps getting better and better! Get RC2 here.

New version of the Code Formatter plugin for Windows Live Writer now available.

The new binaries are here. One small bug fixed in the form where you edit the code: pressing return caused the OK button to fire. Doh! Thanks to JTB World for spotting it.

Windows Live Writer - Bug

When content in a smart plugin exceeds the height of the canvas area, dragging on the size points on the surrounding rectangle causes strange behaviour.  Is anyone else seeing this or is it just me?

Windows Live Writer - Additions to API

Maybe this already exists, but it's not immediately obviose.  When developing a plugin, the component that sits along the right side of the screen is the Content Editor.  WLW has its own color scheme and to intermingle* nicely with it, it'd be nice if the color(s) used were available.

*is that a word?!

Sunday, August 20, 2006

Code Formatter Plugin for Windows Live Writer

I'm quite new to blogging and have recently discovered Windows Live Writer. I've downloaded various plugins for code formatting but none provided me with what I wanted:

  • The ability to format the code 'live'
  • The ability to wrap lines
  • The ability to change the background color
  • The ability to just quickly paste what's in the clipboard as code

The plugin I implemented formats and highlights code and also does all the above. Here's a screen shot of it in use:



Here you can see that the content editor on the right can change the tab width, background color, language, and line numbers.

Below are some sample of code used with the plugin.

Here's some C# code:

public int TabWidth

{

get

{

return _content.Properties.GetInt( @"TabWidth", 4 );

}

set

{

_content.Properties.SetInt(
@"TabWidth", value );

}

}






and some XML markup...


<Triggers>

<KeyPressTrigger Key="PropertyListTrigger" Character=" ">

<KeyPressTriggerValidStates>

<KeyPressTriggerValidState State="PropertyState" />

</KeyPressTriggerValidStates>

</KeyPressTrigger>

<KeyPressTrigger Key="ValueListTrigger" Character=" ">

<KeyPressTriggerValidStates>

<KeyPressTriggerValidState State="ValueState" />

</KeyPressTriggerValidStates>

</KeyPressTrigger>

</Triggers>






I've made available the source and the binaries for this plugin.



To use it, extract the binaries to \Windows Live Writer\Plugins and run WLW. The source is in C# 2.0 and comes with a Visual Studio 2005 solution.



Note that the .NET 2.0 Framework must be installed before this plugin will work.



Going forward



I plan to put this plugin onto CodePlex (if they let me!). I also plan on making a few additions to the defaults via the Options screen. New languages can easily be added too thanks to the great ActiPro Code Highlighter. I'd also like to thank Christophe De Baene for his syntax highlighting tool. It's a great plugin and also helped me understand how to use the ActiPro control.



Please let me know if you'd like to contribute on CodePlex or if there are any features you'd like to see at steve at dunnhq d.o.t. com

Friday, August 18, 2006

Converting System.Drawing.Color to HTML color (and vice-versa)

 

This is something I need very rarely.  So rare in fact that in-between uses it is completely removed from my memory, leaving just the fact that I know I've searched for it before!

To convert a .NET Color object to an HTML RGB or named color, use

 

string colorAsString = ColorTranslator.ToHtml( _backgroundColor ) ;

and vice-versa

 

Color c= ColorTranslator.FromHtml( @"#RRGGBB" ) ;

Wednesday, August 16, 2006

Reshaper Live Templates for validating arguments

I strongly agree with the 'contract' mataphor in API design, hence my interest in Spec# (that I've blogged about before).  

To assist in this and to eliminate the tedium of writing argument checks, I've created 3 Resharper Live Templates.  These check for

  • null parameters for any object passed
  • invalid parameters for any object passed
  • null or empty check for any String passed. 

These templates are called 'arg', 'argnull' and 'argempty' respectivly.

Resharper 1.5 doesn't allow importing or exporting of Live Templates from the GUI.  They are however stored in an XML file at %userprofile%\Application Data\JetBrains\ReSharper\UserSettings.xml.   Below is a chunk of XML that must be placed under the TemplateManager\Templates node.  If you have any others, please let me know!

 

<Template text="if( $TYPE$$EXPRESSION$ )&#xA; throw new ArgumentException( @&quot;Cannot $ACTION$ as the value passed was invalid. Please provide a valid value.&quot;, @&quot;$TYPE$&quot; ) ;&#xA;" shortcut="arg" description="Throws an ArgumentException" kind="livetemplate" reformat="false" fileMask="" context="Everywhere" fileContext="CSharp" enabled="False" id="1723695683">

<Variables>

<Variable name="TYPE" expression="variableOfType(&quot;System.Object&quot;)" initialRange="0" />

<Variable name="EXPRESSION" expression="constant(&quot; != 1&quot;)" initialRange="0" />

<Variable name="ACTION" expression="constant(&quot;PERFORM AN ACTION&quot;)" initialRange="0" />

</Variables>

</Template>

<Template text="if( $TYPE$ == null || $TYPE$.Length == 0 )&#xA;throw new ArgumentNullException( @&quot;$TYPE$&quot;, @&quot;Cannot $ACTION$ as the value passed was null or empty. Please provide a valid non null value.&quot; ) ;&#xA;" shortcut="argempty" description="Throws an ArgumentNullException when a string is null or empty" kind="livetemplate" reformat="true" fileMask="" context="Everywhere" fileContext="CSharp" enabled="False" id="1705884294">

<Variables>

<Variable name="TYPE" expression="variableOfType(&quot;System.String&quot;)" initialRange="0" />

<Variable name="ACTION" expression="constant(&quot;PERFORM AN ACTION&quot;)" initialRange="0" />

</Variables>

</Template>

<Template text="if( $TYPE$ == null )&#xA;throw new ArgumentNullException( @&quot;$TYPE$&quot;, @&quot;Cannot $ACTION$ as the value passed was null. Please provide a valid non-null value.&quot; ) ;&#xA;" shortcut="argnull" description="Throws an ArgumentNullException" kind="livetemplate" reformat="true" fileMask="" context="Everywhere" fileContext="CSharp" enabled="False" id="1497171628">

<Variables>

<Variable name="TYPE" expression="variableOfType(&quot;System.Object&quot;)" initialRange="0" />

<Variable name="ACTION" expression="constant(&quot;PERFORM AN ACTION&quot;)" initialRange="0" />

</Variables>

</Template>

Spec#

Spec# is an addition to C# to allow specifications to be explicitly added to methods. Specifications can state that a method takes a string (which must be non-nul), an integer (which must be between 0 and n), or an array (of which all entries must be non null).  Previously in C#, this would have meant a fair few lines of code that manually checked parameters and threw the respective exceptions.  Furthermore, without specifications, you cannot force any over-ridden method to comply to the same specification.

Spec# is currently a research project and can be downloaded at http://research.microsoft.com/specsharp/

It can be installed to run in Visual Studio 2003 and 2005.  For both systems, it requires an application called Simplify.  This is a java application that can be downloaded at HP Labs Java Programming Toolkit page.  The zipped file that contains Simplify.exe can be found at http://www.hpl.hp.com/downloads/crl/jtk/download-escjava.html, but don't forget to first read the licence at http://www.hpl.hp.com/downloads/crl/jtk/agreement.html ;)

Quicky StringBuilder Tip

StringBuilder has an Append method that returns a reference to itself. This is useful for when you want to append several items in one go. The following code is an example. Obviously, you'll get more benefit the more items you add:

      StringBuilder sb = new StringBuilder( ) ;
      string s = sb.Append( @"Hello " )
        .Append( @"World" )
        .ToString( ) ;

If you've been forced into programming in VB, then check out the original text of this tip at devx.com:

http://www.devx.com/tips/Tip/28152

Quicker loading of the Visual Studio .NET IDE

A handy tip from the Bug Slayer MSDN column:

Tip 57 - To hasten the startup of the Visual Studio .NET IDE, get rid of the Start Page. Because the Start Page requires all Web-browsing components to be loaded, you can chop off a considerable amount of startup time by skipping it. To turn off the Start Page, select Options from the Tools menu to bring up the Options dialog. In the Environment/General property page, select "Show empty environment" in the "at Startup" combobox.

Of course, with Resharper installed, this causes the the IDE's start-up time to become terribly slow.  But it's worth it!