7
  • 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.

myermian
  • 31,823
  • 24
  • 123
  • 215

1 Answers1

3

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.

e_ne
  • 8,340
  • 32
  • 43