reflection issues, General feedback
Resharper doesn't seem to be able to recognize reflections in C#, I agree it isn't easy, and extended to the extreme it can be impossible. This said, I accidentally allowed Resharper to remove a method, wrongly identified as unused, burried deep inside the code, and created a very nasty bug. Obviously a combination of many bad practices culminated in hiding the cause of this.
Please sign in to leave a comment.
"Charbel Gereige" <no_reply@jetbrains.com> wrote in message
news:11105109.1158054440030.JavaMail.itn@is.intellij.net...
How could R# possibly know that yuo were referencing the method through
reflection? Was this a private method? If so, why should it even imagine
that you would want to use reflection to reference private methods?
John
unfortunately, I haven't written the original code, I inherited it and need to maintain it. I was cleaning up using R# and introduced the bug. The code relies on Databinding and reflection a lot, and not used warning are sometime misleading.
Is there comment directive or something like that I could use to tell R# that this particular string references through reflexion something else, say:
///R#obj]]>
or something similar
You could just mark your private method with some attribute.
In this case it won't be counted as redundant
--
Eugene Pasynkov
Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
"Charbel Gereige" <no_reply@jetbrains.com> wrote in message
news:24286042.1158063449276.JavaMail.itn@is.intellij.net...
>
>
>
"Eugene Pasynkov (JetBrains)" <Eugene.Pasynkov@jetbrains.com> wrote in
message news:ee6egt$1au$1@is.intellij.net...
If your method is being accessed through reflection from outside of the
class which contains it, then I recommend marking it with the "public"
attribute, since it's misleading to call it private.
I would also continue refactoring the code into something more sensible.
Most databinding techniques I'm familiar with don't involve using reflection
to access private members.
Private members are meant to be private; if they are accessed outside of the
class, whether by reflection, or by black magic, then they're not private
any more!
Note that if the method had been public, then R# wouldn't have told you it
was unused.
John