@@ -24,23 +24,26 @@ public static class Contract
2424 /// Specifies a precondition that must hold true when the enclosing method is called.
2525 /// </summary>
2626 /// <param name="precondition">The precondition that is required to be <c>true</c>.</param>
27- /// <param name="conditionDescription">An optional English description of what the precondition is.</param>
28- /// <param name="conditionCode">An optional source code representation of the condition expression.</param>
27+ /// <param name="userMessage">Optional English description of what the precondition is.</param>
28+ /// <param name="conditionText">Optional pseudo- code representation of the condition expression.</param>
2929 /// <exception cref="ContractException">
3030 /// Thrown when <paramref name="precondition"/> is <c>false</c>.
3131 /// </exception>
32- public static void Requires ( bool precondition , string ? conditionDescription = null , string ? conditionCode = null )
32+ public static void Requires ( bool precondition , string ? userMessage = null , string ? conditionText = null )
3333 {
34- if ( ! precondition ) ReportFailure ( ContractFailureKind . Precondition , conditionDescription , conditionCode ) ;
34+ if ( ! precondition ) ReportFailure ( ContractFailureKind . Precondition , userMessage , conditionText ) ;
3535 }
3636
3737 /// <summary>
38- /// Argument not null precondition .
38+ /// Requires that argument be not null. If it is, raises an ArgumentNullException .
3939 /// </summary>
4040 /// <param name="argument"></param>
41- public static void RequiresNotNull ( object ? argument )
41+ /// <param name="userMessage">Defaults to 'Argument must not be null'</param>
42+ /// <param name="conditionText">Optional pseudo-code representation of the not null expression.</param>
43+ public static void RequiresNotNull ( object ? argument , string ? userMessage = "Argument must not be null"
44+ , string ? conditionText = null )
4245 {
43- Requires < ArgumentNullException > ( argument != null , "Argument should not be null" ) ;
46+ Requires < ArgumentNullException > ( argument != null , userMessage , conditionText ) ;
4447 }
4548
4649 /// <summary>
@@ -52,20 +55,22 @@ public static void RequiresNotNull(object? argument)
5255 /// The type must have a public constructor that accepts a single <see cref="string"/> parameter.
5356 /// </typeparam>
5457 /// <param name="precondition">The condition that must be <c>true</c>.</param>
55- /// <param name="conditionDescription">An optional message describing the precondition.</param>
58+ /// <param name="userMessage">Optional user readable message describing the precondition.</param>
59+ /// <param name="conditionText">Optional user readable message describing the precondition.</param>
5660 /// <exception cref="ContractException">
5761 /// Thrown when the specified exception type cannot be constructed.
5862 /// </exception>
5963 /// <exception cref="Exception">
6064 /// An instance of <typeparamref name="TException"/> when <paramref name="precondition"/> is <c>false</c>.
6165 /// </exception>
62- public static void Requires < TException > ( bool precondition , string ? conditionDescription = null )
66+ public static void Requires < TException > ( bool precondition , string ? userMessage = null ,
67+ string ? conditionText = null )
6368 where TException : Exception
6469 {
6570 if ( precondition ) return ;
6671
6772 // Try to honor the requested exception type first.
68- string message = BuildFailureMessage ( ContractFailureKind . Precondition , conditionDescription , conditionText : null ) ;
73+ string message = BuildFailureMessage ( ContractFailureKind . Precondition , userMessage , conditionText ) ;
6974
7075 Exception ? exception = null ;
7176 try
@@ -83,7 +88,7 @@ public static void Requires<TException>(bool precondition, string? conditionDesc
8388 }
8489
8590 // Fall back to standard handling if we cannot construct TException.
86- ReportFailure ( ContractFailureKind . Precondition , conditionDescription , conditionText : null ) ;
91+ ReportFailure ( ContractFailureKind . Precondition , userMessage , conditionText : null ) ;
8792 }
8893
8994
0 commit comments