Elton Stoneman

  Home  |   Contact  |   Syndication    |   Login
  120 Posts | 0 Stories | 3607 Comments | 0 Trackbacks

News

Archives

Post Categories

[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).

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati
posted on Monday, November 17, 2008 7:41 PM

Feedback

# re: Configurable FxCop Rules 4/27/2010 10:54 AM network backup-99
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.

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

# re: Configurable FxCop Rules 11/12/2010 10:00 AM Building Chicken Coops
Thanks I have finally configured. I love this blog

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

# re: Configurable FxCop Rules 6/14/2011 5:45 AM Barber Colman Siebe company
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.


# re: Configurable FxCop Rules 9/1/2011 4:36 PM Hubpage creation
This is something that more people need to consider and discuss about openly about coding part. Hubpage Creation

# re: Configurable FxCop Rules 9/11/2011 6:16 PM m20
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

# re: Configurable FxCop Rules 10/3/2011 3:49 AM cheap seo
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.

# re: Configurable FxCop Rules 10/8/2011 8:09 PM florida bass fishing
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

# re: Configurable FxCop Rules 11/2/2011 11:55 AM windows support australia
I understand this issue and it seems that they are doing their best for it.

# re: Configurable FxCop Rules 11/10/2011 10:45 AM more info
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!

# re: Configurable FxCop Rules 11/19/2011 7:52 AM North Face Jackets For Women
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

# re: Configurable FxCop Rules 12/1/2011 4:57 AM annuity cash now
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!

# re: Configurable FxCop Rules 12/1/2011 4:58 AM buy annuity payments
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.

# re: Configurable FxCop Rules 12/1/2011 4:59 AM cash for structured settlement
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!

# re: Configurable FxCop Rules 12/9/2011 1:40 PM skip hire
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

# re: oakley outlet 12/23/2011 1:04 AM oakley outlet
I saw something about this topic on TV last night. Good article.


# re: Configurable FxCop Rules 2/1/2012 7:34 AM Homes For Sale Chandler AZ
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,


Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: