Quantcast
Channel: YouTrackReSharper (RSRP) - Bug and Issue Tracker
Viewing all articles
Browse latest Browse all 106942

RSRP-297863: Switching interface implementations between explicit, implicit and supporting both

$
0
0
Reporter Werner Strydom (bloudraak) Werner Strydom (bloudraak)
Created Apr 27, 2012 3:49:19 AM
Updated Apr 27, 2012 9:56:03 AM
Priority Normal
Type Feature
Fix versions No Fix versions
State Submitted
Assignee Alexey Kuptsov (alexey.kuptsov)
Subsystem Context Actions
Affected versions 6.1.1
Fixed in build No Fixed in build
Consider the following code

public interface IMyClass
{
  void DoSomthing();
  void DoNothing();
}

public class MyClass : IMyClass
{
  public void DoSomthing()
  {
    // Some Implementation
  }

  public void DoNothing()
  {
    // Some Implementation
  }
}


I'd like to select IMyClass and change the implementation to an explicit implementation so it looks like this:


public class MyClass : IMyClass
{
  void IMyClass.DoSomthing()
  {
    // Some Implementation
  }

  void IMyClass.DoNothing()
  {
    // Some Implementation
  }
}


Say I change my mind a couple of days later, I'd like to select IMyClass again and select to change the implementation to implicit, so that it looks like this again:


public class MyClass : IMyClass
{
  public void DoSomthing()
  {
    // Some Implementation
  }

  public void DoNothing()
  {
    // Some Implementation
  }
}


In some cases, one may need to implement an interface explicitly and then call through to the implicit methods, for example, when one implements IClonable in an abstract class. It would be beneficial if ReSharper can provide means to implement both such that MyClass looks like this:


public class MyClass : IMyClass
{
  public void DoSomthing()
  {
    // Some Implementation
  }

  public void DoNothing()
  {
    // Some Implementation
  }

 void IMyClass.DoSomthing()
  {
    this.DoSomthing();
  }

  void IMyClass.DoNothing()
  {
    this.DoNothing();
  }
}


The benefits for this feature are
  • When one works with code that implements interfaces explicitly, one can quickly convert them to implicit interfaces. The benefits increase the larger the interface is that was implemented.
  • One can easily implement interfaces such as ICloneable (be it bad or good).
  • One can quickly switch to explicit implementations to allow the class to be integrated with third party frameworks. In that case the interface serves to other purpose.

Viewing all articles
Browse latest Browse all 106942

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>