IT Community - Software Programming, Web Development and Technical Support

Ordering custom rules for Code analysis

This is a discussion on Ordering custom rules for Code analysis within the C# Programming forums, part of the Software Development category; Ordering custom rules for Code analysis I am currently working on quite a big project, and we are trying to ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > C# Programming

Register FAQ Members List Calendar Mark Forums Read
  #1  
Old 06-18-2009, 02:04 AM
bluesky bluesky is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 667
bluesky is on a distinguished road
Default Ordering custom rules for Code analysis

Ordering custom rules for Code analysis


I am currently working on quite a big project, and we are trying to implement rules for Code analysis. We would then run code analysis on each developper 's Visual Studio.

First objective is to create custom rules. This I will try handle this on my own.

Secund point is to apply our rules to restricted namespaces in our project, to avoid getting a huge number of errors/warnings.
Some rules should be applied to namespace1, some others to namespace2, etc...

Two solutions came to my mind:
* Solution 1 comes with my question: Is there a way to set a top priority rule (I mean a rule that would be run before any other), that depending on which namespace is being checked would trigger the corresponding rules for that namespace ?
Solution 2: Else, I guess I should create for all rules a custom rule including a pre-test in the override of the Check Method, that would do (this example is for rule MyRule, which exists in FxCop/Rules):
IF (namespace == ...) // Namespaces for which we do not run the check
return null;
ELSE
Problems.Add(MyRule.Check()); // Run the Check for MyRule

I would greatly appreciate any help, even giving mere keys, documentation on FxCop SDK (I could not find any...), related topics...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2  
Old 06-18-2009, 02:04 AM
shaalini shaalini is offline
D-Web Architect
 
Join Date: Apr 2007
Posts: 633
shaalini is on a distinguished road
Default Re: Ordering custom rules for Code analysis

hi,

Code analysis does not include any functionality for ordering rules or creating dependencies between rules. Your conditional execution of rules should, therefore, be implemented as a verification within the rule code (your solution #2).
__________________
Shaalini.S
Be the Best of Whatever you are...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3  
Old 06-18-2009, 02:05 AM
bluesky bluesky is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 667
bluesky is on a distinguished road
Default Re: Ordering custom rules for Code analysis

Hi,

Thanks your replay,

I am currently trying to create a custom rule that would substitute the existing Naming rule "Identifiers should be cased correctly" in FxCop.
This principle would be to check the namespace of an assembly, and for some namespaces doing nothing (we want to perform the check only on some namespaces) , and for others triggering the existing Naming rule defined by FxCop in NamingRules.dll.

My problem is: Is there a way to extend this existing rule (then calling base.Check() would be ok I guess) or to call the Check Method corresponding to this Naming rule (something like NamingRule.Check() ?) ?
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4  
Old 06-18-2009, 02:05 AM
shaalini shaalini is offline
D-Web Architect
 
Join Date: Apr 2007
Posts: 633
shaalini is on a distinguished road
Default Re: Ordering custom rules for Code analysis

Hi,

You can't subclass the existing IdentifiersShouldBeCasedCorrectly rule class since it is sealed. It also has internal visibility only, as does the CasingWordParser type, which does most of the actual verification for the rule. You could potentially use CasingWordParser via reflection from your custom rule in order to get the result you want.

That said, I have to wonder a bit about your namespace-specificity approach. Could you please explain why some namespaces do not need to be checked?
__________________
Shaalini.S
Be the Best of Whatever you are...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5  
Old 06-18-2009, 02:06 AM
bluesky bluesky is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 667
bluesky is on a distinguished road
Default Re: Ordering custom rules for Code analysis

Hi,

Thanks again for your answer.


Actually we are trying to "clean up" a huge project, which was developped throught several years . Hencefore, it is just impossible to scan some namespaces since it would raise (ten of ?) thousands of warnings/errors. We decided then to separate the new parts of the code, and to check it separatly, when possible.

Unfortunatly we are extremely short in time for this project, so I do not have time for defining sophisticated custom rules. Then I will not be able to tell you the result of a custom rule using this CasingWordParser function.
I guess we will just skip the naming rule for some projects...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Code Analysis Dictionary for ASP.Net Web Project in VS2008 arjkhanna ASP and ASP.NET Programming 4 09-29-2009 03:01 PM
Sharepoint assembly error on Code Analysis arjkhanna Server Management 3 06-18-2009 07:20 PM
Bill Gates Rules Sabari The Lounge 0 09-06-2007 03:49 AM
Rules that must be followed by an XML document vigneshgets XML and SOAP 1 07-11-2007 06:39 AM
Cars and Bikes Can Mix, When the Rules of the Road Are Clear vigneshgets The Lounge 0 06-06-2007 02:20 AM


All times are GMT -7. The time now is 12:11 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.
Our Partners
One Way Moving Companies | Stamford Dentist | Euro Millions Lottery | Home Loans| Furniture

SEO by vBSEO 3.0.0