Code Contracts + Sandcastle - Any way to set up an exception section?

  • I am using Code Contracts ver: 1.4.40602.0
  • I copied the necessary Content and Transforms files
  • Sandcastle throws exceptions based on my contract requirements.

Code example:

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

Result (in my documentation):

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

It is not that bad, however I am wondering if there is a way to customize the condition text? I tried adding a message to the user 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. Do I have to do this again to get what I need?


Disclaimer: since Code Contracts (currently) is a DevLabs project, this may change, but I wonder if it is already available right now ... if not, I will definitely offer it.

+7
source share
1 answer

With code contracts 1.4.51019.0 you can use overloading:

Requires<TException>(bool condition, string userMessage)

However, your message will be added after "Precondition failed" and then an unsurpassed condition. If Sandcastle does not recognize it, I believe that this is not a mistake in Code Contracts, as the message seems correct to me.

+3
source

All Articles