Login or Sign Up to become a member!

EXPERTS, INFORMATION, IDEAS & KNOWLEDGE

Social bookmarker Add this

Your profile

Search

November 2008
Mon Tue Wed Thu Fri Sat Sun
 << <   > >>
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30

XML Feeds

Tags: resharper

All the LessThanDot Journals

VB.Net: Resharper New version 4.1

by chrissie1


Permalink 03 Sep 2008 05:58 , Categories: Microsoft Technologies Tags: resharper, vb.net

I don’t know when they released it, but it has a huge amount of fixes and improvements.

The Release notes page says it all.

Edit:

Apparently they did it yesterday.

Today, we’re excited to announce the release of ReSharper 4.1! This minor version is highlighted by:

* Support for Microsoft Visual Studio 2008 SP1
* Enhanced ASP.NET experience
* Improved performance and usability: quicker solution load, optimized Unit Test Explorer behavior, and more
* New minor features, including name editing in code generation UI, generating backing fields for implemented interface properties, highlighting usages of XML tags and attributes
* Stability improvements and bug fixes

See Release Notes for details on bug fixes, cosmetics, new features, resolved performance and usability problems.

Leave a comment »Send a trackback » 220 views

VB.Net: Resharper SurroundTemplate for Try Catch

by chrissie1


Permalink 03 Sep 2008 05:55 , Categories: Microsoft Technologies Tags: resharper, surround, template, vb.net

Apparently someone at JetBrains forgot to add a surround template for Try catch in VB.Net. It is there for C#. So I created it for myself.

This is the xml. Just save it in a file and import it in resharper.

  1. <TemplatesExport family="Surround Templates">
  2.   <Template uid="febffd83-d964-4b7d-96fe-abd071be9c50" text="Try&#xD;&#xA;  $SELECTION$&#xD;&#xA;Catch ex As Exception&#xD;&#xA;&#xD;&#xA;End Try" shortcut="" description="Try…Catch" reformat="true" shortenQualifiedReferences="true">
  3.     <Context>
  4.       <VBContext context="Expression" />
  5.     </Context>
  6.     <Categories />
  7.     <Variables />
  8.     <CustomProperties />
  9.   </Template>
  10. </TemplatesExport>
Leave a comment »Send a trackback » 78 views

Let Resharper do the heavy lifting for you.

by chrissie1


Permalink 26 Aug 2008 04:54 , Categories: Microsoft Technologies, VB.NET, C# Tags: equals, generate, gethashcode, properties, resharper, vb.net

Reshaper is a cool tool that can save you plenty of time (unless you start blogging about it of course ;-))

I will give the examples in VB.Net but this will also work in C#.

We all know what a DomainEntity looks like, right?

Ok so here is a simple example.

  1. Public Class person
  2.     Private _id As Guid
  3.     Private _name As String
  4. End Class

First thing to do is create properties for it.
For this we use the Reshaper generate option, which is available via the shortcut Alt+Ins or via the menu Resharper->Generate.

This brings up the following contextmenu:

We choose Read-only properties:

And get this as a result:

  1. Public Class person
  2.     Private _id As Guid
  3.  
  4.     Overridable Public ReadOnly Property _idProperty() As Guid
  5.         Get
  6.             Return _id
  7.         End Get
  8.     End Property
  9.  
  10.     Private _name As String
  11. End Class

Not ideal, but a timesaver none the less.

We do the same but then as a normal property for name.

And get this as a result:

  1. Public Class person
  2.     Private _id As Guid
  3.  
  4.     Overridable Public ReadOnly Property _idProperty() As Guid
  5.         Get
  6.             Return _id
  7.         End Get
  8.     End Property
  9.  
  10.     Private _name As String
  11.  
  12.     Overridable Public Property _nameProperty() As String
  13.         Get
  14.             Return _name
  15.         End Get
  16.         Set (ByVal value As String)
  17.             _name = value
  18.         End Set
  19.     End Property
  20. End Class

But now for the most important part. The overriding of the Equals and GetHashCode methods.

So we do Alt+Ins again and choose Equality members and get this dialog. We choose name and some other things that seem useful.

And we get this as a result:

  1. Public Class person
  2.     Implements IEquatable(Of person)
  3.     Private _id As Guid
  4.  
  5.     Overridable Public ReadOnly Property _idProperty() As Guid
  6.         Get
  7.             Return _id
  8.         End Get
  9.     End Property
  10.  
  11.     Private _name As String
  12.  
  13.     Public Overloads Function Equals (ByVal obj As person) as Boolean
  14.         If ReferenceEquals (Nothing, obj) Then Return False
  15.         if ReferenceEquals (Me, obj) Then Return True
  16.         Return Equals (obj._name, _name)
  17.  
  18.     End Function
  19.  
  20.     Public Overloads Overrides Function Equals (ByVal obj As Object) as Boolean
  21.         If ReferenceEquals (Nothing, obj) Then Return False
  22.         if ReferenceEquals (Me, obj) Then Return True
  23.         If Not Equals (obj.GetType(), GetType (person)) Then Return False
  24.         Return Equals (DirectCast (obj, person))
  25.  
  26.     End Function
  27.  
  28.     Public Overrides Function GetHashCode() as Integer
  29.         If _name IsNot Nothing Then Return _name.GetHashCode()
  30.         Return 0
  31.  
  32.     End Function
  33.  
  34.     Overridable Public Property _nameProperty() As String
  35.         Get
  36.             Return _name
  37.         End Get
  38.         Set (ByVal value As String)
  39.             _name = value
  40.         End Set
  41.     End Property
  42. End Class

Cool, right, in a few clicks we got a whole lot of code. And a whole lot of working code to boot. It isn’t pretty, but there are things you can do about that.

There is also Formatting members which creates a ToString.

Which creates something like this.

  1. Public Overrides Function ToString() as String
  2.         Return string.Format ("_id: {0}, _name: {1}", _id, _name)
  3.     End Function

I don’t know who came up with the names but they should look at Eclipse, it is much clearer there. And the property names aren’t what I would expect, a return to hungarian comes to mind.

4 comments »Send a trackback » 475 views