"With Clause" and "Refactor -> Extract Method"

I have been having this problem with "Extract Method" ever since .NET 2.0 when I use the "WITH CLAUSE". I was hoping
someone might fix it some time. I filed a JIRA but no response for years:

Suppose you have:

With someobj
.DoSOmething()
.DoOther()
.Blah
End With

Supose I want to refactor that using a new method. If I select:

With someobj
<SELECTION STARTS HERE>
.DoSOmething()
.DoOther()
.Blah
<SELECTION ENDS HERE>
End With

And then click "Refactor -> Extract Method" then R# does something really wierd. I would imagine "Extract Method" should be easy.

Just do:

RefactoredMethod(someObj)

and then:

Public Sub RefactoredMethod(someObj as SomeType)
with someObj
.DoSOmething()
.DoOther()
.Blah
End With

0
2 comments
Avatar
Permanently deleted user

why you don't include the "with / end with" in your selection? I think when you do so, the refactoring will be done correct.

Regards
Klaus

0

I gave a poor example. Here's a more accurate one.

With someobj
.DoAction1()
.DoAction2()
<SELECTION STARTS HERE>
.DoSOmething()
.DoOther()
.Blah
<SELECTION ENDS HERE>
.DoCleanup()
End With

0

Please sign in to leave a comment.