Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Q: Why doesn't C# warn on unused methods?
A: This is something that the C# compiler could do, subject to a few caveats:
- Virtual functions would have to be excluded
- Interface implementations wouldn have to be excluded
- You would get false positives if you used reflection
- You might get false positives if you used delegates (the compiler might be able to be smart here)
Other than that, it would be possible for us to do this, and we may do it in a future version.
[Author: Eric Gunnerson]
Comments
Anonymous
March 19, 2004
Also there are special methods for designer, which are usually private and not virtual, e.g. ShouldSerializeNNN, ResetNNN where NNN is property name. This links computer with library and design environment too tight...Anonymous
March 20, 2004
Thanks for the reply.
Just for a thought, the compiler could look at the access modifier of the method in determining whether a warning is necessary. For instance, unused internal, protected internal, and private methods could generate warnings, but public methods in class library projects would not.Anonymous
March 23, 2004
FxCop can be used to find unused methods & types.
Look under the Performance rules for "Avoid building non-callable code into assemblies" and "Avoid building uninstantiated internal classes into assemblies". It takes in account delegates & well known latebinding scenarios. Ofcourse it still gives false positives for other reflection scenarios.Anonymous
July 17, 2004
my web:
http://www.sj55.com/pic_sort http://www.zw88.com/paopaotang.htm http://www.zw88.com/sj.htm http://www.zw88.com/sm/
http://www.zw88.com/sms/ http://www.zw88.com/zw.htm http://www.resou.com/8888.htm http://www.sj55.com/pic/pic_1130.htmAnonymous
December 27, 2004
[http://itpeixun.51.net/][http://aissl.51.net/][http://kukuxz003.freewebpage.org/][http://kukuxz001.51.net/][http://kukuxz003.51.net/][http://kukuxz005.51.net/][http://kukuxz002.51.net/][http://kukuxz004.freewebpage.org/][http://kukuxz007.51.net/][http://kukuxz001.freewebpage.org/][http://kukuxz006.51.net/][http://kukuxz002.freewebpage.org/][http://kukuxz004.51.net/][http://kukuxz008.51.net/][http://kukuxz009.51.net/][http://kukuxz005.freewebpage.org/][http://kukuxz006.freewebpage.org/][http://kukuxz007.freewebpage.org/][http://kukuxz009.freewebpage.org/]Anonymous
August 30, 2010
maybe they will be call out of this class , maybe you add this library to another project !Anonymous
February 18, 2013
What about methods that aren't used by one assembly itself but in other assemblies that depend on the first one (and they are not together in the same solution)? The method would likely be marked as "unused" but the depending assembly would be broken upon removal of that method. Not a problem with consistent definition and usage of interfaces, however.