Summary


Even though the FxCop team is feverishly working on a completely new rules engine and will not be documenting the Introspection engine, I still feel that writing your own rules is worth exploring. I hope I was able to show you some nice tricks to get started and how to write any rule you think possible with the wonderful binary analysis tools in Code Analysis/FxCop. If you're interested in writing rules but don't have an idea of one you could write, I'll leave you with a few I'd love to see:

  • Permission Documentation Check Much like the ExceptionDocumention*Rules I presented in this chapter, the <permission> tag is just as important. Write a rule that looks for permission attributes on methods or Assert.Demand calls inline, and verify that the appropriate value is documented.

  • Add DebuggerDisplayAttribute to public classes In Chapter 5, "Advanced Debugger Usage with Visual Studio," I showed how important the DebuggerDisplayAttribute class is to getting quick help in DataTips and the Watch window. Write a rule that looks for public classes, and if a DebuggerDisplayAttribute or DebuggerTypeProxyAttribute are not present, flag it as an error.

  • Incorrect DebuggerDisplayAttribute string Also in regards to the DebuggerDisplayAttribute, the different expression evaluators in the debugger have varying capabilities. For example, the C# expression evaluator can handle calling methods, but Microsoft Visual Basic cannot. Write a rule that looks for invalid constructs in a DebuggerDisplayAttribute string, and flag an error if one occurs. Extra credit will be given if you also validate all the values to be displayed in braces as existing properties or fields.

  • Naming handles As I discussed in Chapter 6, "WinDBG, SOS, and ADPlus," the !handle command in WinDBG is wonderful for showing the state of all open handles in a process. However, if the handles aren't named, it's almost impossible to figure out what handle is what. Write a rule that verifies that all handle classes are called with the constructor that sets a name and that the name is not the empty string or null/Nothing.




Debugging Microsoft  .NET 2.0 Applications
Debugging Microsoft .NET 2.0 Applications
ISBN: 0735622027
EAN: 2147483647
Year: 2006
Pages: 99
Authors: John Robbins

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net