Out of the box, ReSharper supports ReactiveUI's ReactiveUI.raisePropertyChanged(string)
overload to turn an automatic property into a property with change invocation, i.e.:
Turns this:
Into this:
This is done by ReSharper's support for INotifyPropertyChanged
that was introduced in ReSharper 7. The way it works, is that the ReactiveUI.raisePropertyChanged(string)
method is decorated with ReSharper's Annotation attribute called [NotifyPropertyChangedInvocator]
. This attribute, when decorating a method with a particular signature, on a type that implements the INotifyPropertyChanged
interface will automatically allow ReSharper to use it as the 'change notification' refactoring.
In your case, with relatively small amount of code, you can utilize the same mechanism. Your RaiseAndSetIfPropertyChanged
method, however, needs to have a particular signature. What you could do is, create an abstract class, deriving from ReactiveObject
, and implement your method there:
public abstract class ReactiveObjectBase : ReactiveObject
{
[NotifyPropertyChangedInvocator]
protected void RaiseAndSetIfPropertyChanged<T>(ref T obj, T value, string propertyName)
{
// call real raise method here
}
}
This method will need to have this exact signature (method name could be different), and it will have to be decorated with the NotifyPropertyChangedInvocator
attribute.
After that, simply change the base type of your view models to ReactiveObjectBase
, and now you'll be able to turn your automatic properties into change notifications:
Hope this helps!