2

I have hundreds occurences of this kind of lines in my app :

public ICommand MyCommandName => ReactiveCommand.Create(TriggerCommand);

I tried without luck to add a Custom Pattern in resharper to change it to :

private ICommand _MyCommandName;
public ICommand MyCommandName => _MyCommandName ??= ReactiveCommand.Create(TriggerCommand);

Here is my pattern : enter image description here

the pattern is ambiguous and can't be saved. Here are the placeholders :

enter image description here enter image description here enter image description here enter image description here

1
  • 1
    Not an answer, just pointing out that your ??= is not thread-safe. You may want to consider making _MyCommandName lazily initialized. Commented Sep 18, 2024 at 0:46

1 Answer 1

1

I'm not using R# in Visual Studio anymore, therefore I don't have access to the Structural Search and Replace feature in VS. However, using JetBrains Rider I was able to solve your task with the following RegEx which should also work in Visual Studio 🤞🏻

Search:

public (\w*) (\w*) \=\> (\w*)\.(\w*)\((\w*)\)\;

Replace:

public $1 _$2;
public $1 $2 => _$2 ??= $3.$4($5);
Sign up to request clarification or add additional context in comments.

2 Comments

I could do it with Visual studio with the Search & Replace (with regex) : Search : public ICommand (\w*) \=\> Reactive Replace : private ICommand _$1;\n\t\tpublic ICommand $1 => _$1 ??= Reactive
I accept this solution, even if it isn't done using Resharper

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.