Is it possible to change 'default refactoring's'? Enable, Disable and/or Modify?

Hello!

I am asking this question because it does not seem to be asked before or answered previously. I found one similar question here from 2016, however it is not answered.

My question is:

1.)  Can I change default refactoring patterns? Mainly I want to change the functionality of Rider using the `!` symbol for 'false', and have it automatically use `.IsFalse()` instead.  In all of our projects we use `.IsTrue()` and `.IsFalse()` extension methods on booleans for increased readability.

2.) Can I turn off default suggestions?

For example:

If I have this code:

````csharp

remote.Connect();
// Refactoring will be suggested for 'foreach' -- converting foreach to a LINQ statement
foreach (var item in items)
{
// Refactoring will be suggested for 'if statement' -- inverting if statement
if (item.IsCompleted())
{
var exists = remote.Exists(item.ContentPath);

if (exists.IsFalse())
{
listOfHashesToRemove.Add(item.Hash);
}
}
}

 

````

If I apply the inverted if statement, Rider will generate:

````csharp

remote.Connect();
foreach (var item in items)
{
if (!item.IsCompleted())
{
continue;
}

var exists = remote.Exists(item.ContentPath);

if (exists.IsFalse())
{
listOfHashesToRemove.Add(item.Hash);
}
}

````

I would like Rider to instead generate:

````csharp

remote.Connect();
foreach (var item in items)
{
if (item.IsCompleted().IsFalse())
{
continue;
}

var exists = remote.Exists(item.ContentPath);

if (exists.IsFalse())
{
listOfHashesToRemove.Add(item.Hash);
}
}

````

 

Summary:

1.) How can I alter default refactoring to use `.IsFalse()` instead of `!`

2.) How can I disable the LINQ refactoring suggestion on foreach?

 

0
1 comment

Hi Jeff Ward

Thank you for contacting us. 

2. To disable suggestions for LINQ refactorings go to `File | Settings | Editor | Inspection Settings | Inspection Severity | C#`, type LINQ in the search field and check off the boxes of the proper refactorings. 

1. Unfortunately, it is not possible to change the refactoring template. You can disable suggestions for this the same way by setting off checkboxes for Invert statement and Invert if... inspections. 

I hope this helps! Please let me know if you have any other questions. 

Have a great day! 

0

Please sign in to leave a comment.