Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Code Contracts + Sandcastle -- Any way to customize the exceptions section?

  • I'm using Code Contracts ver: 1.4.40602.0
  • I copied the necessary Content and Transforms files
  • Sandcastle outputs the exceptions based upon my contract requirements

Example Code:

public class MyClass
{
    public MyClass(Object obj)
    {
        Contract.Requires<ArgumentNullException>(obj != null);
    }
}

Resulting output (in my documentation):

| Exception                       | Condition                       |
|---------------------------------|---------------------------------|
| System.ArgumentNullException    | obj == null                     |

This isn't that bad, however I wonder if there is a way to customize the text of the Condition? I attempted to add a user message Contract.Requires<ArgumentNullException>(obj != null, "obj is null.");, however this did not solve anything.

In the past I had to write my own xml documentation section for exceptions. Am I going to have to do that again to get what I need?


Disclaimer: Since Code Contracts is (currently) a DevLabs project, this could change, but I'm wondering if it's already available right now... if not, I'll be sure to suggest it.

like image 725
myermian Avatar asked Dec 13 '11 19:12

myermian


1 Answers

With Code Contracts 1.4.51019.0 you may use the overload:

Requires<TException>(bool condition, string userMessage)

However, your message will be appended after "Precondition failed" followed by the unmatched condition. If Sandcastle doesn't recognize it, I believe that it's not a fault in Code Contracts, since the message appears correctly to me.

like image 147
Mir Avatar answered Sep 20 '22 00:09

Mir