Incorrect "use object initializer" advice from R#

Given the code...

public interface I { string Name { get; set; } }

class A : I
{
     string I.Name { get; set; }
}

class Program
{
     static void Main(string[] args)
     {
          I a = new A();
          a.Name = "a";
     }
}


R# marks the keyword "new" with "Use object initializer". However, accepting the refactor ends up with an error on the Name assignment "Cannot access private property 'Name' here".

Two issues:

  1. The "Use object initializer" is not taking into account the inability to set Name on an object of type A without going through the interface.
  2. The "Cannot access private property here" is a misleading message. The compiler error is "A does not contain a definition for 'Name'" which is more accurate.

This occurs in both the released 5.1.1 and 5.1.1753.3.

1 comment
Comment actions Permalink

Thank you for the feedback.

The problem is fixed in ReSharper 6.0

0

Please sign in to leave a comment.