Priority
Normal
Type
Bug 
State
Fixed 
Assignee
Sergey Shkredov 
Subsystem
No subsystem 
Affected versions
Fixed in
Fixed in build
5.0.1612.107  
Build
819
Fixed in build
910
  • Submitted by   Jeroen Haegebaert
    18 months ago (17 Jul 2008 13:33)
  • Updated by Jeroen Haegebaert
    18 months ago (17 Jul 2008 14:35)
  • Jira: RSRP-75137
    (history, comments)

RSRP-75137

'Convert To Auto Property' incorrectly re-initializes fields that are already initialized in constructor

0
The class below contains a property called TestProperty with a backing field. The backing field is by default initialized to 'true', but explicitly initialized to a constructor argument in the first constructor. When using the 'Convert to Automatic Property' refactoring, Resharper adds a 'TestProperty = true;' statement at the end of the constructor, invalidating the . This statement should probably be put at the front.

class ConvertToAutomaticPropertyTest
  {
    public ConvertToAutomaticPropertyTest(bool testInitialValue)
    {
      mTest = testInitialValue; // <- note the explicit initialization of the backing field
    }

    public ConvertToAutomaticPropertyTest()
    {
    }

    private bool mTest = true;
    public bool TestProperty
    {
      get { return mTest; }
      set { mTest = value; }
    }

  }


Here's the result after the refactoring TestProperty to Automatic Property with Resharper:

  class ConvertToAutomaticPropertyTest
  {
    public ConvertToAutomaticPropertyTest(bool testInitialValue)
    {
      TestProperty = testInitialValue; // Resharper correctly changed mTest to TestProperty here
      TestProperty = true;             // <- BUT: the initialization is overwritten!
    }

    public ConvertToAutomaticPropertyTest()
    {
      TestProperty = true; //<- correct!
    }

    public bool TestProperty { get; set; }
  }


Issue was closed
Comments (0)
 
History (0)
 
Links
 
Issue has no comments