Geeks With Blogs

News This is the *old* blog. The new one is at blog.sixeyed.com
Elton Stoneman
This is the *old* blog. The new one is at blog.sixeyed.com

[Source: http://geekswithblogs.net/EltonStoneman]

FxCop allows you to define rules as having configurable settings, and through the native UI you can override the settings and save them for each FxCop project. This is useful if you want to have a generic set of rules that can be used to enforce differing sets of standards, without having to modify the rule assemblies.

It's not well documented, but you need to implement IConfigurableRule and provide default setting values. There's a straightforward sample on Dennis Forbes' blog, but you can move the IConfigurableRule implementation to a base class and just have the specific setting code in the child class:

Bear in mind that FxCop will instantiate an instance of the rule prior to firing it during analysis, and will cache that instance for all analysis runs, so your configuration code should account for this. Key things to note:

  • Settings are held in two IDictionary objects, representing the default settings and the current settings. In theory any dictionary type will do, but I had problems with using generic dictionaries, so resorted to using Hashtable;
  • Add values to the default setting collection in a static constructor, then use ConfigurationHelper.CopyFromDefault() to copy default settings to the current setting collection. This has to be in a static constructor, lazy-loading the DefaultSettings property won't work;
  • Use ConfigurationHelper.LoadSettings() in your implementation of LoadSettings, to update the current dictionary with saved values from the FxCop project file;
  • Use ConfigurationHelper.SaveSettings() in your SaveSettings implementation to copy the current setting values back to the FxCop project file. FxCop will only call this if the current settings differ from the defaults;
  • There's no event model to notify when current settings have been changed, so if you're caching downstream based on a setting value, you'll need to check the cache is valid before each call.

The need to set up defaults in a static constructor complicates the implementation of the base class. One option is to store a static collection of Hashtables in the base class, keyed by the child class type name (this is the implementation I used in BizTalkCop, full code samples there).

Posted on Monday, November 17, 2008 7:41 PM FxCop | Back to top


Comments on this post: Configurable FxCop Rules

# re: Configurable FxCop Rules
Requesting Gravatar...
Really its one of the fabulous post and I just like to say you,its very informative blog which I like a lot.Some great information to be absorbed in this post.Thanks a lot for sharing.Keep blogging.
Left by network backup-99 on Apr 27, 2010 10:54 AM

# re: Configurable FxCop Rules
Requesting Gravatar...
That's great, i've been struggling with the IConfigurableRule and didn't realise the default setting values couls be changed- thanks.
Left by virtual receptionist on Jul 02, 2010 2:36 PM

# re: Configurable FxCop Rules
Requesting Gravatar...
Thanks I have finally configured. I love this blog
Left by Building Chicken Coops on Nov 12, 2010 10:00 AM

# re: Configurable FxCop Rules
Requesting Gravatar...
It's a great idea to enforce differing sets of standards. So far, I always use single standard.
Left by online law degree on May 13, 2011 7:42 AM

# re: Configurable FxCop Rules
Requesting Gravatar...
Nice post. This post is different from what I read on most blog. And it have so many valuable things to learn. Thank you for your sharing.
Left by Barber Colman Siebe company on Jun 14, 2011 5:45 AM

# re: Configurable FxCop Rules
Requesting Gravatar...
This is something that more people need to consider and discuss about openly about coding part. Hubpage Creation
Left by Hubpage creation on Sep 01, 2011 4:36 PM

# re: Configurable FxCop Rules
Requesting Gravatar...
Reading is my passion. Browsing through your site gives me a lot of knowledge in so many ways. Thank you for the efforts you made in writing and sharing your points of view. Looking forward to learn some more from you. Keep it up.dating sites
Left by m20 on Sep 11, 2011 6:16 PM

# re: Configurable FxCop Rules
Requesting Gravatar...
Just saying thanks will not just be adequate, for the great lucidity in your writing. I will directly grab your rss feed to stay abreast of any updates.
Left by cheap seo on Oct 03, 2011 3:49 AM

# re: Configurable FxCop Rules
Requesting Gravatar...
This is such a great resource that you are providing and you give it away for free. I enjoy seeing websites that understand the value of providing a prime resource for free. I truly loved reading your post. Thanks!florida bass fishing</a
Left by florida bass fishing on Oct 08, 2011 8:09 PM

# re: Configurable FxCop Rules
Requesting Gravatar...
I understand this issue and it seems that they are doing their best for it.
Left by windows support australia on Nov 02, 2011 11:55 AM

# re: Configurable FxCop Rules
Requesting Gravatar...
It started as hard to initiate the troubleshoot but after re reading and carefully doing all the necessary steps, I was able to do it! Thanks for this step by side guide! More power!
Left by more info on Nov 10, 2011 10:45 AM

# re: Configurable FxCop Rules
Requesting Gravatar...
North Face Jackets, both North Face Jackets For Women and North Face Jackets For men, are playing an important role in our fall, winter and spring life. They can be your daily necessities. They can also be a great gift to your families or friends to show your love. An awesome North Face Jackets as a birthday, Thanks Given Day, Christmas Day or Valentine's Day gift would surely make the receiver full of gratitude and love towards you.e
Left by North Face Jackets For Women on Nov 19, 2011 7:52 AM

# re: Configurable FxCop Rules
Requesting Gravatar...
It makes me feel so surprise. I never know there is such a wonderful place that I can find what I need, the site offers different kinds of handbags, sunglasses and jeans etc with world-famous brands. They are all cheap, nice with high quality. I believe it won't let you down. Join it now!
Left by annuity cash now on Dec 01, 2011 4:57 AM

# re: Configurable FxCop Rules
Requesting Gravatar...
There are a lot of great points here, but I'm not sure I agree with real-time search being discarded. I agree that it's not very relevant, but isn't the point of it to show what people are currently saying about a topic.
Left by buy annuity payments on Dec 01, 2011 4:58 AM

# re: Configurable FxCop Rules
Requesting Gravatar...
Thanks on your marvelous posting! I actually enjoyed reading it; you might be a great author. I will make certain to bookmark your blog and may come back very soon. I want to encourage you to continue your great work, have a nice weekend!
Left by cash for structured settlement on Dec 01, 2011 4:59 AM

# re: Configurable FxCop Rules
Requesting Gravatar...
You are awesome! This blog is so great. I really hope more people read this and get what you’re saying, because let me tell you, it’s important stuff. I never would’ve thought about it this way unless Id run into your blog. Thanks for putting it up. I hope you have great success
Left by skip hire on Dec 09, 2011 1:40 PM

# re: oakley outlet
Requesting Gravatar...
I saw something about this topic on TV last night. Good article.
Left by oakley outlet on Dec 23, 2011 1:04 AM

# re: Configurable FxCop Rules
Requesting Gravatar...
As I did in the last column, I need to make a small disclaimer here. The FxCop team has not documented the Introspection engine yet and its implementation is subject to change in future releases. However, as you'll see in the implementation section. Thanks for sharing.
Regards,
Left by Homes For Sale Chandler AZ on Feb 01, 2012 7:34 AM

# Zahnarzt düsseldorf pempelfort-Configurable FxCop Rules
Requesting Gravatar...
Thanks for Shearing it.Configuration manual is easy to see.I will try it later.Then see what will happen.Till then keep bloging
Left by Zahnarzt düsseldorf pempelfort on Apr 08, 2012 9:55 AM

# re: Configurable FxCop Rules
Requesting Gravatar...
I was exploring for this Lycium Barbarum for weight-loss management; when I chanced upon this Configurable FxCop Rules published in your web site. I did adore it and I'm looking forward in going back one more time.
Left by noellerc10 on Sep 27, 2013 10:04 AM

# re: Configurable FxCop Rules
Requesting Gravatar...
Being alone here in the motor inn gives me goose bumps; making use of my blackberry phone I Go Here to find good stuffs. And surely, I realized Configurable FxCop Rules worthwhile of my effort viewing.
Left by germnley72 on Nov 05, 2013 5:33 AM

# re: Configurable FxCop Rules
Requesting Gravatar...
I'm not really usually driven by educational posts, though your take on Configurable FxCop Rules seriously made me carefully consider your sentiments. You have provided valuable and stable opinions which are sensible and fascinating. I professionally like to comment on best hair salon silver lake. So I know the hard work it requires to produce an educational write-up similar to this. Thanks for featuring your advantageous work.
Left by Cesar Azevedo on Dec 19, 2013 7:36 AM

# re: Configurable FxCop Rules
Requesting Gravatar...
What's up fellas! Whilst reading through Configurable FxCop Rules, I ran into this phrase travail a domicile; to my inquisitiveness I searched it up on the world wide web.
Left by Jonas Furst on Jan 17, 2014 3:05 AM

# re: Configurable FxCop Rules
Requesting Gravatar...
The subject matter on Configurable FxCop Rules is to some degree very fascinating; I unearthed number's of points to evaluate in on this article. I was searching for debt consolidation guidebooks however.
Left by Mark Osbourn on Jan 30, 2014 1:17 AM

# re: Configurable FxCop Rules
Requesting Gravatar...
I've had an exhausting time trying to find Josh Groban lyrics on Youtube . Pleased I was able to read a couple of informative elements at your blog; At this time I get higher potency.
Left by Randal Porter on Feb 20, 2014 2:29 AM

# re: Configurable FxCop Rules
Requesting Gravatar...
fxcop rules have changed slightly check infinity on loop post about it phones compatible
Left by rounak on Jan 01, 2017 9:29 AM

Your comment:
 (will show your gravatar)


Copyright © Elton Stoneman | Powered by: GeeksWithBlogs.net