Search used and not used properties - c#

I have a project , there is several classes. I want to search used and not used properties in project.
is visual studio have any way to search ueed properties.
Programing language is C#.net

ReSharper

I suppose you have to use some third party tools available in the market.Just Google it and you will find many.I recommend resharper which gives you many added functionality

Find all references.

Just use the "Run Code Analysis" option. It will show the unused calls (if they are not public and available to everyone.

Even if code analysis tools might help in searching this properties, you can't rely on code analysis tools completely, because a client code might access a property with reflection.
This includes data contracts your client proxies might have in case of WCF, javasript json serialization dependencies and the like.
You can try comment out properties suspected to have no usages, but you have not only to make sure it compiles, but also have all the the tests to pass.
Hope you have a decent test coverage and intergated test suites in place.

Related

How can I get code coverage info on code called by CSLA?

I'm currently researching and deciding on a code coverage tool for my company, and have so far tried NCover (Bolt and Desktop), DotCover, and NCrunch. All tools I've tried so far work well for measuring/highlighting code coverage in code called directly by unit tests, but any code called through CSLA (DataPortal_Fetch, for example) is never detected as being covered. As much of our code base resides in these functions, I'm finding the tools to be next to useless for much of what I need tested and measured.
My question then is how can I get code coverage results for CSLA code? Does anyone know of a tool that would work with these kinds of calls, or certain options/extensions I can use to get coverage results with the tools I'm using?
The project is coded in C#, and I'm using Visual Studio 2013 Professional, CSLA 3.8, and .NET 4.0. I have the latest versions of NCover Bolt and DotCover (both on trial), as well as the newest OpenCover that I could find.
Thanks in advance!
NCover Support here.
If you are using NCover Desktop, you can auto-configure to detect any .NET code that is being loaded by your testing (Bolt can only profile test runners).
We have this video that shows auto-detecting NUnit, as an example:
http://www.ncover.com/resources/videos/ncover-creating-a-new-code-coverage-project
And a lot of the same info in this help doc:
http://www.ncover.com/support/docs/desktop/user-guide/coverage_scenarios/how_do_i_collect_data_from_nunit
Please contact us at support#ncover.com if you have extra questions. Hope this helps.
Unlike TyCobb's entirely outdated opinion, current versions of CSLA don't invoke methods via reflection (except on iOS) and haven't since around 2007. But the data portal does use dynamic invocation via expression trees and that's probably the issue causing you trouble.
One option in current versions of CSLA is that the data portal is now described by an interface so you can mock the data portal, potentially creating a mock that does nothing but invoke your DP_XYZ methods directly. Even that's tricky though, unless you make them public and allow other code in your app to easily break encapsulation (yuck). The problem is that you won't be able to call the methods without using reflection, or rewriting the dynamic expression tree invocation code used inside CSLA...
Though perhaps the code coverage tools would see the code executing if it were run via reflection instead of via a runtime compiled expression?

cleaning up redundant code in an external library

I am using a huge open source library in C#, but I'm only using it for a handful of specific functions. Is there a tool that I can use to automatically clean out all unused code?
I tried going about it manually using resharper but the code is so deeply nested that it is impossible...
Try something like this: include a project containing code that calls the methods you need. Maybe this should be a unit test project. Use solution-wide analysis to remove code that is completely unused.
Then start making the public classes private. Revert this as soon as you "see red".
Also be sure to remove unused references.
If you have Ultimate, you can use a dependency diagram to give you. Visual clue about what's not used.
As far as I know there is no simple way to do this. In order to isolate specific methods you'll need to understand all of their dependencies and make sure those remain intact. From what you've said - which isn't enough for me to really know, this is pure speculation - you're going to have to take a lot or take nothing at all.
As recommended by DJ KRAZE, if you really only want a small subset of the functionality, make it yourself.

How should I make a library (.dll) file for other devs to use in their projects using C#?

Sure, there's a type of project in Visual Studio that outputs a DLL that people can use. I know that. I'm just wondering what are some of the standards that devs will expect when using my DLL file.
I'll be providing a class that searches for movies in IMDB and returns results for a dev to consume.
Not a webservice, but a local DLL file. (I'm aware that IMDB frowns upon web scraping, but I'm also aware that they give permission to people if asked. My permission is already sent.)
How should I approach this?
Check out Microsoft's Design Guidelines for Class Library Developers.
Or the newer version of same (thanks to paper1337).
You're then interested in best practices when designing a class library. There is much to say to this thema.
One of the first and foremost things you need to do is to publish all your dependencies. Avoid any hidden dependencies in your code.
For example, don't rely on some key to be set in a shared key-value collection, such as Session. There is no way a user of your library can find it out.
If some method requires some service to be preinitialized, require a valid reference to be passed as an argument.
You need to provide a simple to use API, full documentation and worked examples as a minimum. If you can provide unit tests that would be a bonus.
Internally, you need to verify all inputs into your routines, as well as clearly document what configuration the user is expected to do. Solid exception handling is a given, and you should possibly consider some localisation support in there as well.
If you, or anybody, is serious about creating a good framework for others to use, check out http://www.amazon.com/Framework-Design-Guidelines-Conventions-Libraries/dp/0321246756
What ever you make public, should remain public and their signatures cannot be changed in your next version and you must support it forever.
So, take care in establishing your contracts and document them with examples. Make public members only if it needs to be.
Easy-to-use API with appropriate class, method and property names.
API has been tested (e.g. unit tests)
Supporting documentation.

Is there an automatic way in ASP.NET to tell which resources are not used anywhere in code and markup?

I believe lots of us have been presented with a challenge to check manually through hundreds of string constants to check which ones are used and which are not (orphans). Although I do not have that many yet in my current project, I still find it difficult already to do a code review and check for dropped constants manually.
Is there any way to automate this? Maybe some secret hidden feature in VS?
I have an ASP.NET MVC project with VS 2008. So I'd like to check for all possible references to resources in both .cs and .aspx files.
My guess is that would not be possible. Still, maybe there is something to help me with this task?
CodeRush from Developer Express provides all sorts of orphan checks. They just released a free version - CodeRush Express - although I'm not entirely sure what features are in the free version. Would seem plausible that a feature like this would have been left in, though.
It's a pretty powerful tool, so I'd recommend it anyway.
Also Resharper is the best tool for VS IDE,it does all that for you plus many other options.
hope this helps.
NDepend supports searching for unused public methods / properties etc. Also, Resharper 4.5 now highlights all unused non-private members if you turn on solution wide analysis.

C# Call Graph Generation Tool

I just got a heaping pile of (mostly undocumented) C# code and I'd like to visualize it's structure before I dive in and start refactoring. I've done this in the past (in other languages) with tools that generate call graphs.
Can you recommend a good tool for facilitating the discovery of structure in C#?
UPDATE
In addition to the tools mentioned here I've seen (through the tubes) people say that .NET Reflector and CLR Profiler have this functionality. Any experience with these?
NDepend is pretty good at this. Additionally Visual Studio 2008 Team System has a bunch of features that allow you to keep track of cyclomatic complexity but its much more basic than NDepend. (Run code analysis)
Concerning NDepend, it can produce some usable call graph like for example:
The call graph can be made clearer by grouping its method by parent classes, namespaces or projects:
Find more explanations about NDepend call graph here.
It's bit late, but http://sequenceviz.codeplex.com/ is an awesome tool that shows the caller graph/Sequence diagram. The diagrams are generated by reverse engineering .NET Assemblies.
As of today (June 2017), the best tool in class is Resharper's Inspect feature. It allows you to find all incoming calls, outgoing calls, value origin/destination, etc.
The best part of ReSharper, compared to other tools mentioned above: it's less buggy.
I've used doxygen to some success. It's a little confusing, but free and it works.
Visual Studio 2010.
Plus, on a method-by-method basis - Reflector (Analyzer (Ctrl+R); "Depends On" and "Used By")
SequenceViz and DependencyStructureMatrix for Reflector might help you out: http://www.codeplex.com/reflectoraddins
I'm not sure if it will do it over just source code, but ANTS Profiler will produce a call graph for a running application (may be more useful anyway).

Categories