10 [__DynamicallyInvokable]
14 private static bool _assertingMustUseRewriter;
17 [__DynamicallyInvokable]
18 public static event EventHandler<ContractFailedEventArgs>
ContractFailed 21 [__DynamicallyInvokable]
27 [__DynamicallyInvokable]
36 [Conditional(
"DEBUG")]
37 [Conditional(
"CONTRACTS_FULL")]
38 [ReliabilityContract(
Consistency.WillNotCorruptState,
Cer.MayFail)]
39 [__DynamicallyInvokable]
40 public static void Assume(
bool condition)
51 [Conditional(
"DEBUG")]
52 [Conditional(
"CONTRACTS_FULL")]
53 [ReliabilityContract(
Consistency.WillNotCorruptState,
Cer.MayFail)]
54 [__DynamicallyInvokable]
55 public static void Assume(
bool condition,
string userMessage)
65 [Conditional(
"DEBUG")]
66 [Conditional(
"CONTRACTS_FULL")]
67 [ReliabilityContract(
Consistency.WillNotCorruptState,
Cer.MayFail)]
68 [__DynamicallyInvokable]
69 public static void Assert(
bool condition)
80 [Conditional(
"DEBUG")]
81 [Conditional(
"CONTRACTS_FULL")]
82 [ReliabilityContract(
Consistency.WillNotCorruptState,
Cer.MayFail)]
83 [__DynamicallyInvokable]
84 public static void Assert(
bool condition,
string userMessage)
94 [Conditional(
"CONTRACTS_FULL")]
95 [ReliabilityContract(
Consistency.WillNotCorruptState,
Cer.MayFail)]
96 [__DynamicallyInvokable]
105 [Conditional(
"CONTRACTS_FULL")]
106 [ReliabilityContract(
Consistency.WillNotCorruptState,
Cer.MayFail)]
107 [__DynamicallyInvokable]
108 public static void Requires(
bool condition,
string userMessage)
116 [ReliabilityContract(
Consistency.WillNotCorruptState,
Cer.MayFail)]
117 [__DynamicallyInvokable]
127 [ReliabilityContract(
Consistency.WillNotCorruptState,
Cer.MayFail)]
128 [__DynamicallyInvokable]
136 [Conditional(
"CONTRACTS_FULL")]
137 [ReliabilityContract(
Consistency.WillNotCorruptState,
Cer.MayFail)]
138 [__DynamicallyInvokable]
147 [Conditional(
"CONTRACTS_FULL")]
148 [ReliabilityContract(
Consistency.WillNotCorruptState,
Cer.MayFail)]
149 [__DynamicallyInvokable]
150 public static void Ensures(
bool condition,
string userMessage)
158 [Conditional(
"CONTRACTS_FULL")]
159 [ReliabilityContract(
Consistency.WillNotCorruptState,
Cer.MayFail)]
160 [__DynamicallyInvokable]
170 [Conditional(
"CONTRACTS_FULL")]
171 [ReliabilityContract(
Consistency.WillNotCorruptState,
Cer.MayFail)]
172 [__DynamicallyInvokable]
181 [ReliabilityContract(
Consistency.WillNotCorruptState,
Cer.Success)]
182 [__DynamicallyInvokable]
192 [ReliabilityContract(
Consistency.WillNotCorruptState,
Cer.Success)]
193 [__DynamicallyInvokable]
204 [ReliabilityContract(
Consistency.WillNotCorruptState,
Cer.Success)]
205 [__DynamicallyInvokable]
213 [Conditional(
"CONTRACTS_FULL")]
214 [ReliabilityContract(
Consistency.WillNotCorruptState,
Cer.MayFail)]
215 [__DynamicallyInvokable]
224 [Conditional(
"CONTRACTS_FULL")]
225 [ReliabilityContract(
Consistency.WillNotCorruptState,
Cer.MayFail)]
226 [__DynamicallyInvokable]
227 public static void Invariant(
bool condition,
string userMessage)
242 [ReliabilityContract(
Consistency.WillNotCorruptState,
Cer.MayFail)]
243 [__DynamicallyInvokable]
244 public static bool ForAll(
int fromInclusive,
int toExclusive, Predicate<int> predicate)
246 if (fromInclusive > toExclusive)
250 if (predicate ==
null)
254 for (
int i = fromInclusive; i < toExclusive; i++)
272 [ReliabilityContract(
Consistency.WillNotCorruptState,
Cer.MayFail)]
273 [__DynamicallyInvokable]
276 if (collection ==
null)
280 if (predicate ==
null)
284 foreach (
T item
in collection)
286 if (!predicate(item))
304 [ReliabilityContract(
Consistency.WillNotCorruptState,
Cer.MayFail)]
305 [__DynamicallyInvokable]
306 public static bool Exists(
int fromInclusive,
int toExclusive, Predicate<int> predicate)
308 if (fromInclusive > toExclusive)
312 if (predicate ==
null)
316 for (
int i = fromInclusive; i < toExclusive; i++)
334 [ReliabilityContract(
Consistency.WillNotCorruptState,
Cer.MayFail)]
335 [__DynamicallyInvokable]
338 if (collection ==
null)
342 if (predicate ==
null)
346 foreach (
T item
in collection)
357 [Conditional(
"CONTRACTS_FULL")]
358 [ReliabilityContract(
Consistency.WillNotCorruptState,
Cer.Success)]
359 [__DynamicallyInvokable]
364 [DebuggerNonUserCode]
365 [ReliabilityContract(
Consistency.WillNotCorruptState,
Cer.MayFail)]
368 if (failureKind < ContractFailureKind.Precondition || failureKind >
ContractFailureKind.Assume)
379 [SecuritySafeCritical]
382 if (_assertingMustUseRewriter)
384 System.
Diagnostics.
Assert.Fail(
"Asserting that we must use the rewriter went reentrant.",
"Didn't rewrite this mscorlib?");
386 _assertingMustUseRewriter =
true;
387 Assembly assembly = typeof(Contract).Assembly;
388 StackTrace stackTrace =
new StackTrace();
390 for (
int i = 0; i < stackTrace.FrameCount; i++)
392 Assembly assembly3 = stackTrace.GetFrame(i).GetMethod().DeclaringType.Assembly;
393 if (assembly3 != assembly)
395 assembly2 = assembly3;
399 if (assembly2 ==
null)
401 assembly2 = assembly;
405 _assertingMustUseRewriter =
false;
static void Requires(bool condition)
Specifies a precondition contract for the enclosing method or property.
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
static void Invariant(bool condition)
Specifies an invariant contract for the enclosing method or property.
static T ValueAtReturn< T >(out T value)
Represents the final (output) value of an out parameter when returning from a method.
static void Assume(bool condition, string userMessage)
Instructs code analysis tools to assume that a condition is true, even if it cannot be statically pro...
static void EnsuresOnThrow< TException >(bool condition)
Specifies a postcondition contract for the enclosing method or property, based on the provided except...
virtual AssemblyName GetName()
Gets an T:System.Reflection.AssemblyName for this assembly.
static T OldValue< T >(T value)
Represents values as they were at the start of a method or property.
static bool Exists(int fromInclusive, int toExclusive, Predicate< int > predicate)
Determines whether a specified test is true for any integer within a range of integers.
Contains static methods for representing program contracts such as preconditions, postconditions,...
static void Requires< TException >(bool condition)
Specifies a precondition contract for the enclosing method or property, and throws an exception if th...
Provides methods that the binary rewriter uses to handle contract failures.
static bool ForAll< T >(IEnumerable< T > collection, Predicate< T > predicate)
Determines whether all the elements in a collection exist within a function.
Cer
Specifies a method's behavior when called within a constrained execution region.
Provides information about, and means to manipulate, the current environment and platform....
static void Assert(bool condition, string userMessage)
Checks for a condition; if the condition is false, follows the escalation policy set by the analyzer ...
string Name
Gets or sets the simple name of the assembly. This is usually, but not necessarily,...
static string RaiseContractFailedEvent(ContractFailureKind failureKind, string userMessage, string conditionText, Exception innerException)
Used by the binary rewriter to activate the default failure behavior.
Represents an assembly, which is a reusable, versionable, and self-describing building block of a com...
static void EndContractBlock()
Marks the end of the contract section when a method's contracts contain only preconditions in the if-...
static void Invariant(bool condition, string userMessage)
Specifies an invariant contract for the enclosing method or property, and displays a message if the c...
static EventHandler< ContractFailedEventArgs > ContractFailed
Occurs when a contract fails.
static void Ensures(bool condition, string userMessage)
Specifies a postcondition contract for a provided exit condition and a message to display if the cond...
static bool ForAll(int fromInclusive, int toExclusive, Predicate< int > predicate)
Determines whether a particular condition is valid for all integers in a specified range.
static void Assert(bool condition)
Checks for a condition; if the condition is false, follows the escalation policy set for the analyzer...
The exception that is thrown when one of the arguments provided to a method is not valid.
static bool Exists< T >(IEnumerable< T > collection, Predicate< T > predicate)
Determines whether an element within a collection of elements exists within a function.
static T Result< T >()
Represents the return value of a method or property.
Represents errors that occur during application execution.To browse the .NET Framework source code fo...
Consistency
Specifies a reliability contract.
static void TriggerFailure(ContractFailureKind kind, string displayMessage, string userMessage, string conditionText, Exception innerException)
Triggers the default failure behavior.
static void Ensures(bool condition)
Specifies a postcondition contract for the enclosing method or property.
static void Assume(bool condition)
Instructs code analysis tools to assume that the specified condition is true, even if it cannot be st...
static void Requires(bool condition, string userMessage)
Specifies a precondition contract for the enclosing method or property, and displays a message if the...
ContractFailureKind
Specifies the type of contract that failed.