Domanda

If I ask ReSharper to implement INotyfyPropertyChanged interface for me it creates below code

[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
    PropertyChangedEventHandler handler = PropertyChanged;
    if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
}

Is it possible (and if yes then where should I look for it) to restyle this snippet and to make ReSharper generate the changed one e.g. replace PropertyChangedEventHandler with var keyword and move condition body to the next line?

È stato utile?

Soluzione

Both those options are in "code clean up" options:

Go to Resharper->Options...

Then go to Code Editing->Code Cleanup

  1. Set the use 'var' in declaration option.
  2. Check/tick Reformat code.
  3. Save the profile and set the "Profile to use with silent clean-up:" to it.

This has set up the silent clean-up, but to explicitly clean up at anytime, there is a key shourtcut which is usually Ctrl+E, F

If this doesn't resolve the new line after the if, then look under Code Editing->C#->Formatting Style. This is where the rules of "Reformat code" are defined.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top