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 ...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
|
#1
| |||
| |||
| 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... |
|
#2
| |||
| |||
| 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... |
|
#3
| |||
| |||
| 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() ?) ? |
|
#4
| |||
| |||
| 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... |
|
#5
| |||
| |||
| 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... |
![]() |
| Thread Tools | |
| Display Modes | |
| |
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 |
Our Partners |