C# + ReSharper = Awesome: Tip #7–Move String to Resource

This is the seventh in a series of quick how-to articles on ReSharper.

Tip #7 – Move String to Resource

Use: Moves a string into a resource file to enable localization.

Tip: Ensure your project contains at least one Resource (resx) file or the operation will fail.

Before
   1:       public string YouRock()
   2:       {
   3:           return "No, YOU rock Mr. Method-Caller!";
   4:       }
Right-click the string –> Refactor –> Refactor This…

image

Move to Resource

SNAGHTML6f7080

After
   1:       public string YouRock()
   2:       {
   3:           return StringResources.No_YOU_rock_Mr_Method_Caller;
   4:       }

Happy coding!

 

Visual Studio Achievements – The Beta Goes Live!

image001

The gang over at Channel 9 have just released the first beta of their Visual Studio Achievements project. I tried it out last night and it’s very cool. Here’s what it’s all about:

Bring Some Game To Your Code!

A software engineer’s glory so often goes unnoticed. Attention seems to come either when there are bugs or when the final project ships. But rarely is a developer appreciated for all the nuances and subtleties of a piece of code–and all the heroics it took to write it. With Visual Studio Achievements Beta, your talents are recognized as you perform various coding feats, unlock achievements and earn badges.

You can read the full announcement here and grab the beta from the Visual Studio Gallery here.

 

C# + ReSharper = Awesome: Tip #6 – Extract Interface

This is the sixth in a series of quick how-to articles on ReSharper.

Tip #6 – Extract Interface

Use: Creates a new interface based on the selected class and updates the class to implement the new interface. This is most useful when working with an existing code base because we all define our interfaces first when doing greenfield development, right?  Smile

Before
   1:      public class Shooter
   2:      {
   3:          public string Name { get; set; }
   4:   
   5:          public string ReleaseDate { get; set; }
   6:   
   7:          public int MaxPlayers { get; set; }
   8:   
   9:          public bool HasZombies { get; set; }
  10:   
  11:          public bool IsHalo { get; set; }
  12:   
  13:          public void Borrow()
  14:          {
  15:              //TODO: Implement borrow logic.
  16:          }
  17:      }
Right-click the class

image

Select members

SNAGHTML4614fae1

After
   1:      public interface IGame
   2:      {
   3:          string Name { get; set; }
   4:          string ReleaseDate { get; set; }
   5:          int MaxPlayers { get; set; }
   6:          void Borrow();
   7:      }
   8:   
   9:      public class Shooter : IGame
  10:      {
  11:          public string Name { get; set; }
  12:   
  13:          public string ReleaseDate { get; set; }
  14:   
  15:          public int MaxPlayers { get; set; }
  16:   
  17:          public bool HasZombies { get; set; }
  18:   
  19:          public bool IsHalo { get; set; }
  20:   
  21:          public void Borrow()
  22:          {
  23:              //TODO: Implement borrow logic.
  24:          }
  25:      }

Happy coding!