Convert to auto property problem

In code where a property with a backing field is a struct, converting to auto-property can introduce bugs. For example, if I have

public struct Vector2 { public int X; public int Y; }

private Vector2 _myVector;

public Vector2 MyVector { get { return _myVector; } set { _myVector = value; } }

// then in some method we have

_myVector.X = 1;

If MyVector is converted to an auto-property, _myVector.X = 1 becomes MyVector.X = 1 which is now changes a COPY of the vector.

Is there any way to easily check if such errors have been introduced (or better yet, to have ReSharper detect the problem and warn you)?

1 comment
Comment actions Permalink

Hello Scott
     I've created a request in our tracker: and you're welcome to monitor its status.

Andrey Serebryansky

Support Engineer

JetBrains, Inc

"Develop with pleasure!"

Please sign in to leave a comment.