Resharper Create custom refactoring for ReactiveUI ReactiveObject

So, I have a ton of models and models in my code that require each property to use the ReactiveUI method to observe their changes:

private bool _myProperty;
public Boolean MyProperty
{
    get { return _myProperty; }
    set { this.RaiseAndSetIfChanged(ref _myProperty, value); }
}

Using Resharper, I can convert this:

public Boolean MyProperty { get; set; }

In it:

private bool _myProperty;
public Boolean MyProperty
{
    get { return _myProperty; }
    set { _myProperty = value; }
}

Then I need to manually convert it to the first code snippet above to enable the ReactiveUI built-in functions.

, Resharper, " " , , . ? ( " -" " " .

! TON ...

+4
2

ReSharper ReactiveUI ReactiveUI.raisePropertyChanged(string), , :

:

:

ReSharper INotifyPropertyChanged, ReSharper 7. , , , ReactiveUI.raisePropertyChanged(string), ReSharper [NotifyPropertyChangedInvocator]. , INotifyPropertyChanged, ReSharper "change notification".

. RaiseAndSetIfPropertyChanged . , ReactiveObject, :

public abstract class ReactiveObjectBase : ReactiveObject
{
    [NotifyPropertyChangedInvocator]
    protected void RaiseAndSetIfPropertyChanged<T>(ref T obj, T value, string propertyName)
    {
        // call real raise method here
    }
}

( ), NotifyPropertyChangedInvocator.

ReactiveObjectBase, :

, !

+10

, R #. post, ?

private $Type$ $BackingField$;
public $Type$ $Property$
{
  get
  {
    return this.$BackingField$;
  }
  set
  {
    this.RaiseAndSetIfPropertyChanged(ref $BackingField$, value); 
  }
}
+2

All Articles