How can I suppress a single instance of ReSharper's suggestion to convert my foreach loop to a LINQ expression?
c#, resharper
Solution
I'm not sure, but try to manually insert
// ReSharper disable LoopCanBePartlyConvertedToQuery
...
// ReSharper restore LoopCanBePartlyConvertedToQuery
around your code
Problem
Normally, if I disagree with some ReSharper-suggested code transformation, there is an option in the action list to suppress the suggestion by placing comments in the code. The following are some examples of these comments: ``` // ReSharper disable UseObjectOrCollectionInitializer var addresses = new MailAddressCollection(); // ReSharper restore UseObjectOrCollectionInitializer ``` and ``` // ReSharper disable ReturnTypeCanBeEnumerable.Local private static MailAddressCollection GetEventStatusNotificationRecipients(UserAccountProfile submitter, UserAccountProfile projectPrincipalInvestigator) // ReSharper restore ReturnTypeCanBeEnumerable.Local ``` I don't know why, but the action list for the "Part of loop's body can be converted into LINQ-expression" rule does not include an option to suppress the ReSharper suggestion. I already tried the transformation into a LINQ expression to see what sort of output it produces. It turned a crystal-clear foreach loop into obfuscated garbage, so I reverted the change. But, I'd like to be able to suppress the message. Is there a way to suppress the suggestion (other than completely turning off the rule, which I don't want to do because there might be other instances where converting a loop body into a LINQ expression makes sense)?