Thursday, August 09, 2012 11:38 AM
I am a senior developer and i want to create a rule to identify expensive resources like socket etc are not pooled.
Thursday, August 09, 2012 2:45 PM
Good luck :) I'd love to see the result! I don't really see a question here, but I suspect you're looking for pointers on where to start. And given the size of the scope of your idea I can imagine. What you'll first have to do is identify good and bad patterns in the code. Get a lot of samples of the good ways to do the thing you're checking and a lot of examples of the bad way to do it.
Try to find a pattern, expressed in terms of code, which you can then verify. Something like:
- If a socket is created in a method
- and it is not added to a ICollection or IDictionary during the lifetime of that method.
- and it is not stored in a private field or property
Then it is a problem.
After you've figured them out, create a few of these samples in a simple class library project and use Introspector to see what that looks like to FxCop.
When you've figured out how to detect the good and the bad samples, write your rule by looking for all the signs of the bad code and verifying it isn't one of the good ones.
My blog: blog.jessehouwing.nl
- Marked As Answer by Jack Zhai - MSFTMicrosoft Contingent Staff, Moderator Tuesday, August 21, 2012 1:52 AM