'Delegating members' doesn't work properly in some cases

Summary: 'Delegating members' doesn't work properly if a class has a method with the same name as explicitly implemented interface method.

Suppose you have the following code (you also can see full code in attachments):

using System;

interface IColor
{
void Foo();
}

class Red : IColor
{
public int Foo(int x) { throw new NotImplementedException(); }
void IColor.Foo() { throw new NotImplementedException(); }
}

class Wrapper
{
private Red _red = new Red();
}

Note that class Red has int Foo(int) method with the same name as explicitly implemented interface method void Foo().
Choose menu item ReSharper | Code | Generate | Delegating members, or press Alt+Ins, D. Then click both Red and IColor checkboxes. The following code will be generated:

class Wrapper
{
private Red _red = new Red();

public int Foo(int x)
{
return _red.Foo(x);
}

public void Foo()
{
_red.Foo(); /* Method 'Foo' has 1parameters(s) but is invoked with 0 argument(s) */
}
}

Expected result:

class Wrapper
{
private Red _red = new Red();

public int Foo(int x)
{
return _red.Foo(x);
}

public void Foo()
{
((IColor) _red).Foo(); /* Proper method is invoked */
}
}

It is a bug, isn't it?



Attachment(s):
source.cs
result.cs
expected.cs

Please sign in to leave a comment.