With reSharper -> Edit -> Generate Code -> Properties from this:
private int _age;
I get this
public int Age
{
get { return _age; }
set { _age = value; }
}
which is alright, but what can I do if I want something like this:
public int Age
{
get { return _age; }
set
{
if (_age != value)
{
_age = value;
OnPropertyChanged("Age");
}
}
}
Is there a way to customise ReSharper’s output? FYI I’m on Visual Studio 2008, ReSharper v5.1.
You could write your own ReSharper Live Template like so:
Then you can enter new properties with backing field and OnPropertyChangedEvent call by one step by typing in first letters of live template shortcut:
propWithChangeEvents.Then an intellisence list appears. You select propWithChangeEvents, type the field type (i.e. int) and ENTER, then field name (i.e. age) and ENTER.
Then all is generated as you need.
That’s for new fields/properties. If you really need the same for existing fields let me know it.