History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: RSRP-60700
Type: New Feature New Feature
Status: Open Open
Priority: Normal Normal
Assignee: Sergey Shkredov
Reporter: Yuri Astrakhan
Votes: 0
Watchers: 2
Operations

If you were logged in you would be able to see more operations.
ReSharper

Add "replace all instances" of lambda -> named method conversion

Created: 07 Mar 08 19:01   Updated: 11 Mar 08 14:57
Component/s: Refactorings
Fix Version/s: None
Security Level: Everybody (All jira users)

Original Estimate: Unknown Remaining Estimate: Unknown Time Spent: Unknown

Build: 746


 Description  « Hide
Sometimes multiple copies of identical lamda expressions are placed in various parts of the code. It is now possible to convert a lambda expression into a named method, but it would be convenient to have a "replace all" option to identify identical lambda expressions and replace them all with a common named method. In case where lambda expressions are all within the same method, an alternative would be to introduce a local delegate variable and use that.

This will work easily if no variables are used from outside of the lambda expression (non-lambda parameters).

void Bar()
{
   Foo( s => s == 2 ? s + 10 : s + 5 );
   Foo( r => r == 2 ? r + 10 : r + 5 );
}

would get replaced into:

void Bar2(int s)
{
   return s == 2 ? s + 10 : s + 5;
}
void Bar()
{
   Foo(Bar2);
   Foo(Bar2);
}

or as a variable:

void Bar()
{
   var func = s => s == 2 ? s + 10 : s + 5;
   Foo(func);
   Foo(func);
}


 All   Comments   Work Log   Change History      Sort Order:
There are no comments yet on this issue.