mscorlib 4.0.0.0 System.Object

Code contract classes let you specify preconditions, postconditions, and object invariants in your code. Preconditions are requirements that must be met when entering a method or property. Postconditions describe expectations at the time the method or property code exits. Object invariants describe the expected state for a class that has no condition problems. For more information about preconditions, postconditions, and object invariants, see Code Contracts.

For tools and detailed instructions for using code contracts, see Code Contracts on the MSDN DevLabs Web site.

You must use a binary rewriter to insert run-time enforcement of contracts. Otherwise, contracts such as the method can only be tested statically and will not throw exceptions during run time if a contract is violated. You can download the binary rewriter CCRewrite from Code Contracts on the MSDN DevLabs Web site. CCRewrite comes with a Visual Studio add-in that enables you to activate run-time contract enforcement from the project Properties page. The binary rewriter and the Visual Studio add-in do not ship with vs_dev10_long or the Windows SDK.

Contains static methods for representing program contracts such as preconditions, postconditions, and object invariants.

- Method
  4.0.0.0
  System.Diagnostics.Conditional("DEBUG")
  System.Diagnostics.Conditional("CONTRACTS_FULL")
  System.Runtime.ConstrainedExecution.ReliabilityContract(System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState, System.Runtime.ConstrainedExecution.Cer.MayFail)
  System.Void ``

  The default escalation policy is to notify the attached debugger about a contract failure or to display an Assert dialog box if a debugger is not attached. Optionally, the analyzer can be instructed to throw an exception.

  Checks for a condition; if the condition is false, follows the escalation policy set for the analyzer.

  The conditional expression to test.
- Method
  4.0.0.0
  System.Diagnostics.Conditional("DEBUG")
  System.Diagnostics.Conditional("CONTRACTS_FULL")
  System.Runtime.ConstrainedExecution.ReliabilityContract(System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState, System.Runtime.ConstrainedExecution.Cer.MayFail)
  System.Void `` ``

  The default escalation policy is to notify the attached debugger about a contract failure or to display an Assert dialog box if a debugger is not attached. Optionally, the analyzer can be instructed to throw an exception. The parameter is passed to the debugger output. If is not a constant string literal, tools may not be able to read it.

  Checks for a condition; if the condition is false, follows the escalation policy set by the analyzer and displays the specified message.

  The conditional expression to test. A message to display if the condition is not met.
- Method
  4.0.0.0
  System.Diagnostics.Conditional("DEBUG")
  System.Diagnostics.Conditional("CONTRACTS_FULL")
  System.Runtime.ConstrainedExecution.ReliabilityContract(System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState, System.Runtime.ConstrainedExecution.Cer.MayFail)
  System.Void ``

  At run time, using this method is equivalent to using the method.

  Instructs code analysis tools to assume that the specified condition is true, even if it cannot be statically proven to always be true.

  The conditional expression to assume true.
- Method
  4.0.0.0
  System.Diagnostics.Conditional("DEBUG")
  System.Diagnostics.Conditional("CONTRACTS_FULL")
  System.Runtime.ConstrainedExecution.ReliabilityContract(System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState, System.Runtime.ConstrainedExecution.Cer.MayFail)
  System.Void `` ``

  If is not a constant string literal, the contract may not be understood by tools.

  At run time, using this method is equivalent to using the method.

  Instructs code analysis tools to assume that a condition is true, even if it cannot be statically proven to always be true, and displays a message if the assumption fails.

  The conditional expression to assume true. The message to post if the assumption fails.
- Event
  4.0.0.0
  System.EventHandler<System.Diagnostics.Contracts.ContractFailedEventArgs>

  The event information for this event is supplied by the object that is passed to the event handler. This event notifies a managed application environment such as an interactive interpreter or a Web browser host that a contract has failed. Before doing so, it will raise an event that an application can handle as it sees fit. For example, if code is being run in a testing framework, you can log a test failure and then end the test.

  The default implementation of the method in the .NET Framework class library is to call each handler that is registered with the event. Exceptions thrown by handlers are ignored, but each handler can indicate whether the failure is handled by calling the method for the event arguments. If any handler sets the failure as handled, the method returns null and no further action is taken. Alternatively, handlers can call the method to instruct the code to unwind. In that case, an exception is thrown after all handlers have executed.

  Occurs when a contract fails.

- Method
  4.0.0.0
  System.Diagnostics.Conditional("CONTRACTS_FULL")
  System.Runtime.ConstrainedExecution.ReliabilityContract(System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState, System.Runtime.ConstrainedExecution.Cer.Success)
  System.Void

  Most code already contains some parameter validation in the form of if-then-throw code. The contract tools recognize if-then-throw statements as preconditions when the statements appear first inside a method, and the entire set of such statements is followed by an explicit method call, such as a , , , or .

  When if-then-throw statements appear in this form, the contract tools recognize them as legacy-require statements. The form is used only if no other contracts follow the if-then-throw sequences, but they should still be tagged as legacy-requires.

  Marks the end of the contract section when a method's contracts contain only preconditions in the if-then-throw form.

- Method
  4.0.0.0
  System.Diagnostics.Conditional("CONTRACTS_FULL")
  System.Runtime.ConstrainedExecution.ReliabilityContract(System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState, System.Runtime.ConstrainedExecution.Cer.MayFail)
  System.Void ``

  The parameter specifies a postcondition that is expected to be true when the enclosing method or property returns normally.

  This method call must be at the beginning of a method or property, before any other code.

  You must use the binary rewriter (available at Code Contracts on the MSDN DevLabs Web site) for run-time enforcement of this postcondition.

  Specifies a postcondition contract for the enclosing method or property.

  The conditional expression to test. The expression may include , , and values.
- Method
  4.0.0.0
  System.Diagnostics.Conditional("CONTRACTS_FULL")
  System.Runtime.ConstrainedExecution.ReliabilityContract(System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState, System.Runtime.ConstrainedExecution.Cer.MayFail)
  System.Void `` ``

  The parameter specifies a postcondition that is expected to be true when the enclosing method or property returns normally.

  This method call must be at the beginning of a method or property, before any other code.

  This contract is exposed to clients; therefore, it must only reference members that are at least as visible as the enclosing method.

  You must use the binary rewriter (available at Code Contracts on the MSDN DevLabs Web site) for run-time enforcement of this postcondition.

  If is not a constant string literal, the contract may not be understood by tools.

  Specifies a postcondition contract for a provided exit condition and a message to display if the condition is false.

  The conditional expression to test. The expression may include and values. The message to display if the expression is not true.
- Method
  4.0.0.0
  System.Diagnostics.Conditional("CONTRACTS_FULL")
  System.Runtime.ConstrainedExecution.ReliabilityContract(System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState, System.Runtime.ConstrainedExecution.Cer.MayFail)
  System.Void System.Exception ``

  The parameter specifies a postcondition that is expected to be true when the enclosing method or property terminates abnormally and an exception of type is thrown.

  This method call must be at the beginning of a method or property, before any other code.

  This contract is exposed to clients; therefore, it must only reference members that are at least as visible as the enclosing method.

  You must use the binary rewriter for run-time enforcement of this postcondition.

  Specifies a postcondition contract for the enclosing method or property, based on the provided exception and condition.

  The conditional expression to test. The type of exception that invokes the postcondition check.
- Method
  4.0.0.0
  System.Diagnostics.Conditional("CONTRACTS_FULL")
  System.Runtime.ConstrainedExecution.ReliabilityContract(System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState, System.Runtime.ConstrainedExecution.Cer.MayFail)
  System.Void System.Exception `` ``

  The parameter specifies a postcondition that is expected to be true when the enclosing method or property terminates abnormally and an exception of type is thrown. The parameter specifies a message to display if the condition is false.

  This method call must be at the beginning of a method or property, before any other code.

  This contract is exposed to clients; therefore, it must only reference members that are at least as visible as the enclosing method.

  You must use the binary rewriter for run-time enforcement of this postcondition.

  If is not a constant string literal, the contract may not be understood by tools.

  Specifies a postcondition contract and a message to display if the condition is false for the enclosing method or property, based on the provided exception and condition.

  The conditional expression to test. The message to display if the expression is false. The type of exception that invokes the postcondition check.
- Method
  4.0.0.0
  System.Runtime.ConstrainedExecution.ReliabilityContract(System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState, System.Runtime.ConstrainedExecution.Cer.MayFail)
  System.Boolean `` `` ``

  The parameter is one more than the last integer to facilitate using the length of a range of integers starting at 0. For example, it would be set to 5 for integers 0 through 4.

  Determines whether a specified test is true for any integer within a range of integers.

  true if returns true for any integer starting from to - 1.

  The first integer to pass to . One more than the last integer to pass to . The function to evaluate for any value of the integer in the specified range.
- Method
  4.0.0.0
  System.Runtime.ConstrainedExecution.ReliabilityContract(System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState, System.Runtime.ConstrainedExecution.Cer.MayFail)
  System.Boolean `` `` This method can be used within a contract condition to allow contracts to be applied to collections.

  Determines whether an element within a collection of elements exists within a function.

  true if and only if returns true for any element of type in .

  The collection from which elements of type will be drawn to pass to . The function to evaluate for an element in . The type that is contained in .
- Method
  4.0.0.0
  System.Runtime.ConstrainedExecution.ReliabilityContract(System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState, System.Runtime.ConstrainedExecution.Cer.MayFail)
  System.Boolean `` `` ``

  The parameter is one more than the last integer to facilitate using the length of a range of integers starting at 0. For example, it would be set to 5 for integers 0 through 4.

  Determines whether a particular condition is valid for all integers in a specified range.

  true if returns true for all integers starting from to - 1.

  The first integer to pass to . One more than the last integer to pass to . The function to evaluate for the existence of the integers in the specified range.
- Method
  4.0.0.0
  System.Runtime.ConstrainedExecution.ReliabilityContract(System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState, System.Runtime.ConstrainedExecution.Cer.MayFail)
  System.Boolean `` `` This method can be used within a contract condition to allow contracts to be applied to collections.

  Determines whether all the elements in a collection exist within a function.

  true if and only if returns true for all elements of type in .

  The collection from which elements of type will be drawn to pass to . The function to evaluate for the existence of all the elements in . The type that is contained in .
- Method
  4.0.0.0
  System.Diagnostics.Conditional("CONTRACTS_FULL")
  System.Runtime.ConstrainedExecution.ReliabilityContract(System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState, System.Runtime.ConstrainedExecution.Cer.MayFail)
  System.Void ``

  contracts are contained within a method that is identified by the attribute; typically, the method is named ObjectInvariant.

  This contract can be specified only in a dedicated invariant method that is declared on a class. If the method is not sealed, it should refer only to protected members, not private members, so that subclasses can be sure to maintain the invariants.

  This contract is not exposed to clients; therefore, it may reference members that are less visible than the enclosing method.

  You must use the binary rewriter for run-time enforcement of this invariant.

  Invariants are conditionally defined based on the presence of the CONTRACTS FULL symbol. During run-time checking, invariants are checked at the end of each public method. If an invariant mentions a public method in the same class, the invariant check that would normally happen at the end of that public method is disabled and checked only at the end of the outermost method call to that class. This also happens if the class is re-entered because of a call to a method on another class.

  Specifies an invariant contract for the enclosing method or property.

  The conditional expression to test.
- Method
  4.0.0.0
  System.Diagnostics.Conditional("CONTRACTS_FULL")
  System.Runtime.ConstrainedExecution.ReliabilityContract(System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState, System.Runtime.ConstrainedExecution.Cer.MayFail)
  System.Void `` ``

  contracts are contained within a method that is identified by the attribute; typically, the method is named ObjectInvariant.

  This contract can be specified only in a dedicated invariant method that is declared on a class.

  This contract is not exposed to clients; therefore, it may reference members that are less visible than the enclosing method.

  You must use the binary rewriter for run-time enforcement of this invariant.

  Invariants are conditionally defined on the CONTRACTS FULL symbol. During run-time checking, invariants are checked at the end of each public method. If an invariant mentions a public method in the same class, the invariant check that would normally happen at the end of that public method is disabled and checked only at the end of the outermost method call to that class. This also happens if the class is re-entered because of a call to a method on another class.

  Specifies an invariant contract for the enclosing method or property, and displays a message if the condition for the contract fails.

  The conditional expression to test. The message to display if the condition is false.
- Method
  4.0.0.0
  System.Runtime.ConstrainedExecution.ReliabilityContract(System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState, System.Runtime.ConstrainedExecution.Cer.Success)
  T `` The type of the value. The field or parameter of which to represent the initial value. Used within a postcondition to represent an initial value. The initial value. The code contract rewriter tool must be used for this method to be effective. Otherwise the default value for the type is returned.
- Method
  4.0.0.0
  System.Diagnostics.Conditional("CONTRACTS_FULL")
  System.Runtime.ConstrainedExecution.ReliabilityContract(System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState, System.Runtime.ConstrainedExecution.Cer.MayFail)
  System.Void ``

  This method call must be at the beginning of a method or property, before any other code.

  This contract is exposed to clients; therefore, it must only reference members that are at least as visible as the enclosing method.

  Use this method instead of the method when backward compatibility does not force you to throw a particular exception.

  Specifies a precondition contract for the enclosing method or property.

  The conditional expression to test.
- Method
  4.0.0.0
  System.Diagnostics.Conditional("CONTRACTS_FULL")
  System.Runtime.ConstrainedExecution.ReliabilityContract(System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState, System.Runtime.ConstrainedExecution.Cer.MayFail)
  System.Void `` ``

  This method call must be at the beginning of a method or property, before any other code.

  This contract is exposed to clients; therefore, it must only reference members that are at least as visible as the enclosing method.

  Use this method instead of the method when backward compatibility does not force you to throw a particular exception.

  Specifies a precondition contract for the enclosing method or property, and displays a message if the condition for the contract fails.

  The conditional expression to test. The message to display if the condition is false.
- Method
  4.0.0.0
  System.Runtime.ConstrainedExecution.ReliabilityContract(System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState, System.Runtime.ConstrainedExecution.Cer.MayFail)
  System.Void System.Exception ``

  You must turn on run-time checking to use the method. If run-time checking is turned off, the process will be terminated. To obtain the tools for runtime checking, see Code Contracts on the MSDN DevLabs Web site.

  This method call must be at the beginning of a method or property, before any other code.

  This contract is exposed to clients; therefore, it must only reference members that are at least as visible as the enclosing method.

  Use this method instead of the method when you want to throw an exception if the precondition fails.

  Specifies a precondition contract for the enclosing method or property, and throws an exception if the condition for the contract fails.

  The conditional expression to test. The exception to throw if the condition is false.
- Method
  4.0.0.0
  System.Runtime.ConstrainedExecution.ReliabilityContract(System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState, System.Runtime.ConstrainedExecution.Cer.Success)
  System.Void System.Exception `` The exception type that causes this precondition to be verified. The precondition to verify. Specifies a precondition contract for when an exception is thrown. All code contract method calls must be at the beginning of the method or property. The code contract rewriter tool must be used to enable contracts to be verified at runtime.
- Method
  4.0.0.0
  System.Runtime.ConstrainedExecution.ReliabilityContract(System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState, System.Runtime.ConstrainedExecution.Cer.MayFail)
  System.Void System.Exception `` To be added. To be added. To be added. To be added.
- Method
  4.0.0.0
  System.Runtime.ConstrainedExecution.ReliabilityContract(System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState, System.Runtime.ConstrainedExecution.Cer.MayFail)
  System.Void System.Exception `` To be added. To be added. To be added. To be added.
- Method
  4.0.0.0
  System.Runtime.ConstrainedExecution.ReliabilityContract(System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState, System.Runtime.ConstrainedExecution.Cer.MayFail)
  System.Void System.Exception `` ``

  You must turn on run-time checking to use the method. If run-time checking is turned off, the process will be terminated. To obtain the tools for runtime checking, see Code Contracts on the MSDN DevLabs Web site.

  This method call must be at the beginning of a method or property, before any other code.

  This contract is exposed to clients; therefore, it must only reference members that are at least as visible as the enclosing method.

  Use this method instead of the method when you want to throw an exception if the precondition fails.

  Specifies a precondition contract for the enclosing method or property, and throws an exception with the provided message if the condition for the contract fails.

  The conditional expression to test. The message to display if the condition is false. The exception to throw if the condition is false.
- Method
  4.0.0.0
  System.Runtime.ConstrainedExecution.ReliabilityContract(System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState, System.Runtime.ConstrainedExecution.Cer.MayFail)
  System.Void System.Exception `` `` To be added. To be added. To be added. To be added. To be added.
- Method
  4.0.0.0
  System.Runtime.ConstrainedExecution.ReliabilityContract(System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState, System.Runtime.ConstrainedExecution.Cer.Success)
  System.Void System.Exception `` `` The exception type that causes this precondition to be verified. The precondition to verify. Message to display on contract failure. Specifies a precondition contract for when an exception is thrown. All code contract method calls must be at the beginning of the method or property. The code contract rewriter tool must be used to enable contracts to be verified at runtime.
- Method
  4.0.0.0
  System.Runtime.ConstrainedExecution.ReliabilityContract(System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState, System.Runtime.ConstrainedExecution.Cer.MayFail)
  System.Void System.Exception `` `` To be added. To be added. To be added. To be added. To be added.
- Method
  4.0.0.0
  System.Runtime.ConstrainedExecution.ReliabilityContract(System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState, System.Runtime.ConstrainedExecution.Cer.Success)
  T

  This method can be used only in the conditional expression for the contract.

  Represents the return value of a method or property.

  Return value of the enclosing method or property.

  Type of return value of the enclosing method or property.
- Method
  4.0.0.0
  System.Runtime.ConstrainedExecution.ReliabilityContract(System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState, System.Runtime.ConstrainedExecution.Cer.Success)
  T `` The type of the out parameter. The out parameter. Used within a postcondition to represent the final value of an out parameter. The final value of the out parameter. The code contract rewriter tool must be used for this method to be effective. Otherwise the default value for the type is returned in the out parameter and the return value.