Click here to Skip to main content
14,458,940 members
Rate this:
Please Sign up or sign in to vote.
Hi Friends,

I want to check DB Layer or Business Layer is not directly invoked from Controller using FxCop.

I want to check whether all the method has try/catch using FxCop.

Please help me.
Posted
Comments
bbirajdar 5-Jun-13 9:06am
   
Not a programming question
   
Why not programming? I can assure you: it is programming.... Ah, I see, this is not a question, formally.

Anyway, I even answered, please see.
—SA

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

As to the first question, I can answer only partially, and I'm afraid that would be not the most essential part — how to create custom rules. Please see this CodeProject article:
7 Steps to Write Your Own Custom Rule using FXCOP[^].

Unfortunately, your first rule itself could be very difficult to implement, or maybe even impossible. Can you even strictly define it? Maybe, I'm missing something; and you can; then it's your luck. Well, couple of ideas: you can easily determine which assembly or even a separate type belongs to which layer, if you simply define and use some .NET attributes classifying them. But how to check up if those attributes are misused. But another think is more difficult: the check of "directly invoked" should involve the check ups of the bodies of all methods: is come invocation call done or not. And here reflection is not enough, you would also need some decompilation. I even know where to learn decompilation onto CIL: source-code ILSpy:
http://en.wikipedia.org/wiki/.NET_Reflector[^],
http://ilspy.net/[^],
http://sourceforge.net/projects/sharpdevelop/files/ILSpy/2.0/ILSpy_Master_2.1.0.1603_RTW_Source.zip/download[^].

Anyway, this is quite difficult.

As to the second question, the answer, in contrast, is quite simple: there is nothing to check up: you should never ever use try/catch in every method. This would totally defeat the purpose of structures exception handling. Honestly, misusing exception handling that badly is much worse than not doing any programming at all. You need to stop doing what you are doing and fix your understanding of this part of technology and then the practice. Should I even help you with that? OK, just some links to my past answers:
Does Exception in C# Constructor Cause Caller Assignment to Fail?[^],
Exception Details: System.Runtime.InteropServices.COMException: Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error:...[^],
Handling exceptions in class library (dll)[^].

—SA
   
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100