1

Say I have a property implementing INotifyPropertyChanged:

public WhichHandle LastHandleFC
{
    get => _lastHandleFc;
    set => SetField(ref _lastHandleFc, value);
}

I can replace with regex: \r\n^\s+ to (space), select the property 5 lines, select replace all in selection (alt+a), then confirm with OK.

Result:

public WhichHandle LastHandleFC { get => _lastHandleFc; set => SetField(ref _lastHandleFc, value); }

But now I would like to have my cursor somewhere on the property (not selection) and make it happen with a defined shortcut (like a resharper or VS operation, with alt+enter or ctrl+.).

Is there a way to achieve this ? Is there a way to achieve this after selection a block with several properties and have each of them transformed like this, while respecting the distance between properties ?

To be complete, INotifyPropertyChanged is implemented with:

public event PropertyChangedEventHandler? PropertyChanged;

protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
{
    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}

protected bool SetField<T>(ref T field, T value, [CallerMemberName] string? propertyName = null)
{
    if (EqualityComparer<T>.Default.Equals(field, value)) return false;
    field = value;
    OnPropertyChanged(propertyName);
    return true;
}

1 Answer 1

0

Since you haven't received any answers yet, I thought I give it a try although it's not exactly what you're looking for.

Instead of changing an existing property, you could create a R# template for a new property. Those templates come with some built-in macros to automate various things, the following docs will give you a good starting point:

I also wrote two blog posts which touch this topic - you might find them useful:

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.