Contract 클래스
정의
사전 조건, 사후 조건, 개체 고정 조건 같은 프로그램 계약을 나타내는 정적 메서드가 포함됩니다.Contains static methods for representing program contracts such as preconditions, postconditions, and object invariants.
public ref class Contract abstract sealed
public static class Contract
type Contract = class
Public Class Contract
- 상속
-
Contract
설명
코드 계약 클래스를 사용 하 여 코드에서 사전 조건, 사후 조건 및 개체 고정을 지정할 수 있습니다.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.
코드 계약 사용에 대 한 도구 및 자세한 지침은 Visual Studio Marketplace의 코드 계약 을 참조 하세요.For tools and detailed instructions for using code contracts, see Code Contracts on the Visual Studio Marketplace.
중요
런타임에 계약 적용을 삽입 하려면 이진 재작성 기를 사용 해야 합니다.You must use a binary rewriter to insert run-time enforcement of contracts. 그렇지 않으면 메서드와 같은 계약은 Contract.Ensures 정적 으로만 테스트할 수 있으며, 계약이 위반 되는 경우 런타임 중에 예외를 throw 하지 않습니다.Otherwise, contracts such as the Contract.Ensures method can only be tested statically and will not throw exceptions during run time if a contract is violated. Visual Studio Marketplace의 코드 계약 에서 이진 재작성 기 작성을 다운로드할 수 있습니다.You can download the binary rewriter CCRewrite from Code Contracts on the Visual Studio Marketplace. CCRewrite는 프로젝트 속성 페이지에서 런타임 계약 적용을 활성화할 수 있는 Visual Studio 추가 기능을 제공 합니다.CCRewrite comes with a Visual Studio add-in that enables you to activate run-time contract enforcement from the project Properties page. 이진 재작성 기 및 Visual Studio 추가 기능이 또는 Windows SDK와 함께 제공 되지 않습니다 Visual Studio 2010Visual Studio 2010 .The binary rewriter and the Visual Studio add-in do not ship with Visual Studio 2010Visual Studio 2010 or the Windows SDK.
메서드
Assert(Boolean) |
조건을 확인합니다. 조건이 |
Assert(Boolean, String) |
조건을 확인합니다. 조건이 |
Assume(Boolean) |
조건이 항상 |
Assume(Boolean, String) |
조건이 항상 |
EndContractBlock() |
메서드의 계약에 |
Ensures(Boolean) |
바깥쪽 메서드 또는 속성에 대한 사후 조건 계약을 지정합니다.Specifies a postcondition contract for the enclosing method or property. |
Ensures(Boolean, String) |
제공된 종료 조건에 대한 사후 조건 계약과 조건이 |
EnsuresOnThrow<TException>(Boolean) |
제공된 예외와 조건에 따라 바깥쪽 메서드 또는 속성에 대한 사후 조건 계약을 지정합니다.Specifies a postcondition contract for the enclosing method or property, based on the provided exception and condition. |
EnsuresOnThrow<TException>(Boolean, String) |
제공된 예외와 조건에 따라 바깥쪽 메서드 또는 속성에 대한 해당 조건이 |
Exists(Int32, Int32, Predicate<Int32>) |
정수 범위 내의 정수에 대해 지정된 테스트가 true인지 여부를 확인합니다.Determines whether a specified test is true for any integer within a range of integers. |
Exists<T>(IEnumerable<T>, Predicate<T>) |
요소 컬렉션에 속하는 요소가 함수에 존재하는지 확인합니다.Determines whether an element within a collection of elements exists within a function. |
ForAll(Int32, Int32, Predicate<Int32>) |
지정된 범위의 모든 정수에 대해 특정 조건이 유효한지 여부를 확인합니다.Determines whether a particular condition is valid for all integers in a specified range. |
ForAll<T>(IEnumerable<T>, Predicate<T>) |
컬렉션의 모든 요소가 함수에 존재하는지 확인합니다.Determines whether all the elements in a collection exist within a function. |
Invariant(Boolean) |
바깥쪽 메서드 또는 속성에 대한 고정 계약을 지정합니다.Specifies an invariant contract for the enclosing method or property. |
Invariant(Boolean, String) |
바깥쪽 메서드나 속성에 대한 invariant 계약을 지정하고 계약의 조건이 실패한 경우 메시지를 표시합니다.Specifies an invariant contract for the enclosing method or property, and displays a message if the condition for the contract fails. |
OldValue<T>(T) |
값을 메서드나 속성의 시작 위치에 있었던 그대로 나타냅니다.Represents values as they were at the start of a method or property. |
Requires(Boolean) |
바깥쪽 메서드 또는 속성에 대한 사전 조건 계약을 지정합니다.Specifies a precondition contract for the enclosing method or property. |
Requires(Boolean, String) |
바깥쪽 메서드나 속성에 대한 사전 조건 계약을 지정하고 계약의 조건이 실패한 경우 메시지를 표시합니다.Specifies a precondition contract for the enclosing method or property, and displays a message if the condition for the contract fails. |
Requires<TException>(Boolean) |
바깥쪽 메서드나 속성에 대한 사전 조건 계약을 지정하고 계약의 조건이 실패한 경우 예외를 throw합니다.Specifies a precondition contract for the enclosing method or property, and throws an exception if the condition for the contract fails. |
Requires<TException>(Boolean, String) |
바깥쪽 메서드 또는 속성에 대한 사전 조건 계약을 지정하고 계약의 조건이 실패할 경우 제공된 메시지와 함께 예외를 throw합니다.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. |
Result<T>() |
메서드나 속성의 반환 값을 나타냅니다.Represents the return value of a method or property. |
ValueAtReturn<T>(T) |
메서드에서 반환되는 |
이벤트
ContractFailed |
계약이 실패한 경우 발생합니다.Occurs when a contract fails. |