Refactoring by altering reference of something to its container or its part.
Given this code:
Private void DoSomething(int n)
{
Something(n);
}
Invoked like this:
DoSomething(Person.Age)
I wish to get here:
Private void DoSomething(person p)
{
Something(p.Age);
}
What is the easiest refactoring? Both ways.
Please sign in to leave a comment.
Disregard "both ways". I didn't think straight
If I have
Private void DoSomething(person p)
{
Something(p.Age);
}
and wish to have
Private void DoSomething(int age)
{
Something(age);
}
instead.
Then I just extract "p.Age" as an extra parameter, which will render parameter "p" to be no longer in use and can be safely removed with alt-enter.
Hello Tormod,
Basically you can manually edit the DoSomething method from
Private void DoSomething(int n)
{
Something(n);
}
to
Private void DoSomething(person p)
{
Something(p.Age);
}
and then use Structural Search and Replace to replace DoSomething(p.Age)
calls with DoSomething(p).
Thank you!
Andrey Serebryansky
Support Engineer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"