Geeks With Blogs
John Conwell: aka Turbo Research in the visual exploration of data

The tool I referred to in my last post about code uniqueness was FxCop.  I'm sure most people have heard of FxCop, but for those that haven't: FxCop provides a way to validate your compiled assemblies against a list of about 200 canned rules.  These rules are anything from design guidelines, security checks, performance checks, to globalization standards.  FxCop also provides a way for you to create your own rules and hook them into its validation process.  Behind the scenes FxCop uses what Microsoft calls an Introspection engine to parse apart the IL opcodes and metadata tables in your assembly and it builds an object graph that represents all interconnections between Namespaces, Types, Members, Fields...all the way down to the individual IL opcodes.  This provides an incredibly powerful way to inspect an assembly.

I had some ideas for some tools that needed to go through the detailed internal structure of an assembly, and the object graph that FxCop provided fit the bill perfectly.  But there was no easy way to get at it without writing a custom rule to gather the information and running the rule through the FxCop UI.  This quickly became a hassle.

So next I spent many hours reading through the FxCop assemblies with Reflector in order to figure out how I can use the underlying introspection engine without the FxCop UI.  But the FxCop team tightly integrated the engine into there two different exes (one WinForm and one cmd line tool).  So if you want to utilize this object graph you have to either put up with their UI, or do what I tried to do.  Call into the introspection engine directly.  Well after many hours of poking around I did get it to work, but only for one assembly at a time and I could run the analyze once.  If I tried it again, the engine blew chunks.  Not to mention about 100 other hacks and hoops I had to jump through in order to actually get the object graph that represents the internals on my assemblies.

Enter Cecil!  Cecil is a mono project that a friend turned me onto that basically does exactly what FxCop's introspection engine does...AND MORE!  I've become a huge Cecil fan.  In fact I love Cecil!  With very little effort and NO hoops or hacks, Cecil returned to me an object graph that represented the internals of my assembly.  And, the API representing the assembly object graph very much mirrors FxCop's Cci (Common Compiler Infrastructure) API that FxCop uses to model the assembly internals.  So it took no time at all to migrate the tools I wrote against FxCop's assemblies and change them to use Cecil.

The only caveat that I've found to using Cecil is that it does blow chunks on some of the assemblies that I have tried to feed into it.  I suspect its because the offending assembles aren't CLS compliant.  I'll have to figure that one out.

Posted on Friday, November 4, 2005 6:15 AM | Back to top


Comments on this post: More about code uniqueness and....Cecil ROCKS!!!!!

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © John Conwell | Powered by: GeeksWithBlogs.net