Raise PropertyChanged (obsolete in v2.0.0)

Note: starting with ReSharper 7.0, INotifyPropertyChanged support is built-in so this feature has been removed from GammaXaml 2.0.0. See this post on JetBrains .NET blog for more information.


Implementing INotifyPropertyChanged can be cumbersome. Each property setter must ensure that it raises the PropertyChanged event with the correct property name.

Context action

GammaXaml adds a context action to properties contained in types implementing INotifyPropertyChanged to simply call an event invocator method.

PropertyChanged.png

The generated code looks like the following:

if (backingField != value) {
    backingField = value;
    OnPropertyChanged("PropertyName");
}

Remarks

  • If the ReSharper annotation CannotApplyEqualityOperatorAttribute is specified on the property type, !Equals is used instead of the != operator.
  • OnPropertyChanged is not hard-coded: every void method in the type hierarchy, having a single string parameter, and whose name contains at least two of the following words: "Property", "Notify" and "Change" are proposed for auto-completion when the context action is invoked.
  • The context action is only available on properties that have a simple setter: backingField = value;
  • For auto properties, start by invoking the "To property with backing field" ReSharper context action, then the GammaXaml context action.
  • This feature is currently only available in C# files, not Visual Basic files.

This feature correspond to RSRP-47280

Last edited Nov 10, 2012 at 12:22 PM by MrJul, version 7

Comments

No comments yet.