[B2] Small Issue: Inline Method Quick Fix Leaves Inlined Method Behind

Start with this:

using System;
class Class1
{
public event EventHandler MyEvent;
public void Demo()
{
MyEvent += delegate
{
return;
};
}
}

Click in "delegate" and you get a lightbulb. Select "To named method" and
accept the default name:

public void Demo()
{
MyEvent += OnEvent;
}

private void OnEvent(object sender, EventArgs e)
{
return;
}

Click inside of "OnEvent" and select "Inline method". It works, but
"OnEvent" is left behind unreferenced.

If nothing else, shouldn't the fact that it's a private method be enough to
get it removed when inlined?
--
John


2 comments
Comment actions Permalink

Hello John,

how do you invoke 'Inline Method'? Neither VS itself nor ReSharper 3.0 has
such a refactoring. You should be using some 3rd party
tool...

Dmitry Shaporenkov
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"


Start with this:

using System;
class Class1
{
public event EventHandler MyEvent;
public void Demo()
{
MyEvent += delegate
{
return;
};
}
}
Click in "delegate" and you get a lightbulb. Select "To named method"
and accept the default name:

public void Demo()
{
MyEvent += OnEvent;
}
private void OnEvent(object sender, EventArgs e)
{
return;
}
Click inside of "OnEvent" and select "Inline method". It works, but
"OnEvent" is left behind unreferenced.

If nothing else, shouldn't the fact that it's a private method be
enough to get it removed when inlined?



0
Comment actions Permalink

Hello Dmitry,

We have context action to replace named method in event subscription with
its body as anonymous delegate.
It leaves original method intact, because it is not a refactoring and doesn't
do any analysis. If it is private method, it will be highlighted with gray
so you can remove it with quickfix.

Sincerely,
Ilya Ryzhenkov

JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"


DS> Hello John,
DS>
DS> how do you invoke 'Inline Method'? Neither VS itself nor ReSharper
DS> 3.0 has
DS> such a refactoring. You should be using some 3rd party
DS> tool...
DS> Dmitry Shaporenkov
DS> JetBrains, Inc
DS> http://www.jetbrains.com
DS> "Develop with pleasure!"
>> Start with this:
>>
>> using System;
>> class Class1
>> {
>> public event EventHandler MyEvent;
>> public void Demo()
>> {
>> MyEvent += delegate
>> {
>> return;
>> };
>> }
>> }
>> Click in "delegate" and you get a lightbulb. Select "To named method"
>> and accept the default name:
>> public void Demo()
>> {
>> MyEvent += OnEvent;
>> }
>> private void OnEvent(object sender, EventArgs e)
>> {
>> return;
>> }
>> Click inside of "OnEvent" and select "Inline method". It works, but
>> "OnEvent" is left behind unreferenced.
>> If nothing else, shouldn't the fact that it's a private method be
>> enough to get it removed when inlined?
>>


0

Please sign in to leave a comment.