Dew Drop – December 22, 2011 (#1,225)

Top Links

 

.NET / Visual Studio

 

Web Development

 

Design / Methodology / Testing

 

Silverlight / WPF / Windows Phone

 

Podcasts / Screencasts / Videos

 

Community / Events

 

Database

 

SharePoint

 

Miscellaneous

 

More Link Collections

 

The Geek Shelf

HTML5 Games: Creating Fun with HTML5, CSS3, and WebGL by Jacob Seidelin

 

Dew Drop – December 21, 2011 (#1,224)

Top Links

 

.NET / Visual Studio

 

Web Development

 

Design / Methodology / Testing

 

Silverlight / WPF / Windows Phone

 

Podcasts / Screencasts / Videos

 

Community / Events

 

Database

 

SharePoint

 

Miscellaneous

 

More Link Collections

 

The Geek Shelf

Essential C# 4.0 (3rd Edition) (Microsoft .NET Development Series) by Mark Michaelis

 

C# + ReSharper = Awesome: Tip #4 – Convert Abstract Class to Interface

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

Tip #4 – Convert Abstract Class to Interface

Use: This is used when the class(es) that will be inheriting from a base class also need to inherit from another base class. Derived types can inherit from only one base class but can implement multiple interfaces.

Before
   1:      public abstract class Book
   2:      {
   3:          public abstract string Title { get; set; }
   4:   
   5:          public abstract string Year { get; set; }
   6:   
   7:          public abstract string Author { get; set; }
   8:   
   9:          public abstract void Lend();
  10:   
  11:          public abstract void AddToInventory();
  12:      }
Right-click the class

image

After
   1:      public interface Book
   2:      {
   3:          string Title { get; set; }
   4:          string Year { get; set; }
   5:          string Author { get; set; }
   6:          void Lend();
   7:          void AddToInventory();
   8:      }

Note: Notice that this refactoring does not change the name of the type. At this point, there will be a squiggly line under the interface’s name, Book. Placing the cursor on Book and pressing <Alt+Enter> will prompt ReSharper to rename it to IBook.

 

Happy coding!