C# + ReSharper = Awesome: Tip #2 – Create Field

This is the second in a series of quick how-to posts on ReSharper.

Tip #2 – Create Field

Use: Within the body of a class or property, you can type the name of a non-existent variable name. When you place your cursor on the variable, ReSharper provides several options to resolve the impending compilation error. Create Field is one of the options.

Before
   1:          public void AddAlbum(string album)
   2:          {
   3:              if (String.IsNullOrWhiteSpace(album))
   4:                  throw new ArgumentOutOfRangeException("album",
   5:                                                        album,
   6:                                                        "Please provide an album name.");
   7:   
   8:              _albums.Add(album);
   9:          }
Press <Alt+Enter>

image

After
        private IList<string> _albums = new List<string>();

        public void AddAlbum(string album)
        {
            if (String.IsNullOrWhiteSpace(album))
                throw new ArgumentOutOfRangeException("album",
                                                      album,
                                                      "Please provide an album name.");

            _albums.Add(album);
        }

Note: I chose the type IList<string>. The default type selected by ReSharper in this case was object. I also added the initializer to the field to avoid null reference exceptions. Please don’t take any of these examples as best coding practices, they are contrived to demonstrate a particular refactoring.

Happy coding!

 

del.icio.us Tags: ,,

.NET Devs: Need an MSDN Ultimate Subscription? Here are Two Chances to Win One

Like my fellow Microsoft MVPs under the development umbrella, I have been given some MSDN Ultimate licenses to give to influential members of the community. I have found a deserving home for one of them. To find homes for the other two licenses, I decided to have two separate contests.

This hopefully goes without saying (Yes, I am saying it), but these licenses are not for resale. They have unique, traceable keys. Please enter the contests only if you really need the software and plan to give back to the community in some way as a result of winning.

Here are some things not included in these licenses, which would be available with a paid MSDN Ultimate subscription: MSDN Magazine, support calls, Office 2010 licenses.

Update: Office 2010 licenses are included for development and test purposes only.

Contest number one is simple. Send me an email at alashcraft [at] gmail [dot] com and explain (honestly) why you need the subscription and what you plan to do with the tools. Keep in mind that this is all about community. I will choose the winner based on need and community influence. I must receive your entry by Friday, July 9 at 8:00am EDT (UTC – 4) and will announce the winner at 12pm that same day.

For the second contest, I want to make things a little more challenging. Email me a .NET-related technical article to be published on alvinashcraft.com as a guest post. The content must be original, written by the submitter, and not available on any other web sites or blogs. Please include a short bio for yourself as well. All must should be emailed to alashcraft [at] gmail [dot] com, and they must be received no later than Friday, July 16 at 8:00am EDT (UTC – 4). I will select the winner that weekend and announce the winner on Monday, July 19th. If I receive an overwhelming number of great articles, I may dig up some smaller prizes for 2nd and 3rd place (probably books). The winning post will be published the week of the 19th.

I will do my best to scan my spam folder for entries, but please try not to mention Viagra, cheap meds, free Photoshop software or foreign bank accounts in your emails to me.

Any attempts to shamelessly promote my blog or Twitter account will have no effect on the outcome of the contests but are welcome nonetheless.  Angel

If you have any questions, leave a comment, email me, or send me a reply on Twitter.

 

 

Halo-Inspired Theme for Visual Studio

I will eventually get this posted to Studio Styles. Until then, here is a dark theme for Visual Studio that I created. The green and orange give it a Halo-ish feel. Let me know what you think in the comments.

HaloVibe theme in VS2010

Downloads

HaloVibe theme for VS2008

HaloVibe theme for VS2010

 

Mastodon
github.com/alvinashcraft