ShouldSerialize private methods shown as unused code

If you write user controls and have code like this:

private bool ShouldSerializeXXX()
{
}

Resharper shows this as unused code, which it isn't due to the DNF using reflection to hit the property. What is equally interesting is that a private ResetXXX method isnt shown as unused by Resharper, despite it not having any callers either...

I swear this problem didn't happen with at least some of the 2.x versions of Resharper (and the ResetXXX behaviour adds weight to this), but it does exist in v3. Did JetBrains remove the "workaround" I think used to exist or did I imagine it?

I appreciate one "workaround" is to make the method protected but that is then effectively changing the behaviour of the control for an add-in, which doesnt sound ideal?

Thanks,
Grant.

5 comments
Comment actions Permalink

Hello Grant,

Those methods are called via reflection and cannot be analysed by ReSharper.
Also, there are plenty of other similar methods which are subject to the
same problem. The best solution is to mark those methods with any attribute.
We have special attribute in our code for this purpose, like:


public class UsedIndirectlyAttribute : Attribute {}

You can be more specific and create attributes like "UsedByDesigner" or "CalledByReflection".

Sincerely,
Ilya Ryzhenkov

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


IR> If you write user controls and have code like this:
IR>
IR> private bool ShouldSerializeXXX()
IR> {
IR> }
IR> Resharper shows this as unused code, which it isn't due to the DNF
IR> using reflection to hit the property. What is equally interesting is
IR> that a private ResetXXX method isnt shown as unused by Resharper,
IR> despite it not having any callers either...
IR>
IR> I swear this problem didn't happen with at least some of the 2.x
IR> versions of Resharper (and the ResetXXX behaviour adds weight to
IR> this), but it does exist in v3. Did JetBrains remove the
IR> "workaround" I think used to exist or did I imagine it?
IR>
IR> I appreciate one "workaround" is to make the method protected but
IR> that is then effectively changing the behaviour of the control for
IR> an add-in, which doesnt sound ideal?
IR>
IR> Thanks,
IR> Grant.


0
Comment actions Permalink

Hi IIya,

Thanks for the response. Not quite sure how it is that the ResetXXX methods are not listed as unused code by Resharper though? I do a find usages and it says there are none, there are no attributes on them and they are private like the ShouldSerializeXXX method.

Appreciate your suggested workaround using the attributes.

Regards,
Grant.

0
Comment actions Permalink

We should not highlight "ShouldSerializeXXX" as unused. There are special
checks in our code.
Please could you send me the class example where our analysis fails

--
Eugene Pasynkov
Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
"Grant Drake" <no_reply@jetbrains.com> wrote in message
news:9348003.1185285572005.JavaMail.itn@is.intellij.net...

If you write user controls and have code like this:

>

private bool ShouldSerializeXXX()
{
}

>

Resharper shows this as unused code, which it isn't due to the DNF using
reflection to hit the property. What is equally interesting is that a
private ResetXXX method isnt shown as unused by Resharper, despite it not
having any callers either...

>

I swear this problem didn't happen with at least some of the 2.x versions
of Resharper (and the ResetXXX behaviour adds weight to this), but it does
exist in v3. Did JetBrains remove the "workaround" I think used to exist
or did I imagine it?

>

I appreciate one "workaround" is to make the method protected but that is
then effectively changing the behaviour of the control for an add-in,
which doesnt sound ideal?

>

Thanks,
Grant.



0
Comment actions Permalink

Hi Eugene,

Dissention within the ranks, eh? ;)

Any user control I get this behaviour - I just created a new project, added a user control and did this and got the same behaviour:

public partial class TestUserControl : UserControl
{
private string _foo;

public TestUserControl()
{
InitializeComponent();
}

public string Foo
{
get { return _foo; }
set { _foo = value; }
}

private bool ShouldSerializeFoo()
{
return true;
}

private void ResetFoo()
{
_foo = "Reset";
}
}

ShouldSerializeFoo is shown as unused, ResetFoo is not. Currently I am using 3.0.504.27 under VSTS 2005.

Regards,
Grant.

0
Comment actions Permalink

I've found the problem in our analysis, and I'll fix it shortly.
Anyway, I'm not sure we'll fix this problem in 3.0.2

--
Eugene Pasynkov
Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
"Grant Drake" <no_reply@jetbrains.com> wrote in message
news:8347943.1185372259318.JavaMail.itn@is.intellij.net...

Hi Eugene,

>

Dissention within the ranks, eh? ;)

>

Any user control I get this behaviour - I just created a new project,
added a user control and did this and got the same behaviour:

>

public partial class TestUserControl : UserControl
{
private string _foo;

>

public TestUserControl()
{
InitializeComponent();
}

>

public string Foo
{
get { return _foo; }
set { _foo = value; }
}

>

private bool ShouldSerializeFoo()
{
return true;
}

>

private void ResetFoo()
{
_foo = "Reset";
}
}

>

ShouldSerializeFoo is shown as unused, ResetFoo is not. Currently I am
using 3.0.504.27 under VSTS 2005.

>

Regards,
Grant.



0

Please sign in to leave a comment.