Convert public variable to property accessor

I just ran across a bug with ReSharper 1.5 that I hadn't seen before. I was working on a project that has a struct with public variables:

public struct Address
{
public string Name;
public string Street;
public string City;
public string State;
public string Zip;
}

I wanted to eventually translate this struct into a real class so I began by right clicking each variable to implement a property accessor for each. The code in the struct worked fine:

public struct Address
{
private string name;
private string street;
private string city;
private string state;
private string zip;

public string Name { get { return name; } set { name = value; } }
...
public string Zip { get { return zip; } set { zip = value; } }
}

I then had to do a double-take when I saw the code using the class:

public Address NewAddress(string name, string street..., string zip)
{
Address address;
address.A = name;
address.A = street;
address.A = city;
address.A = state;
address.A = zip;
return address;
}

In other words, all of the property names in all methods that reference Address had been renamed to A instead of to the actual property names.

Please sign in to leave a comment.