Contract.Assume Method

Definition

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

Overloads

Assume(Boolean)

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

Assume(Boolean, String)

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.

Assume(Boolean)

Source:
Contracts.cs
Source:
Contracts.cs
Source:
Contracts.cs

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

C#
[System.Diagnostics.Conditional("DEBUG")]
[System.Diagnostics.Conditional("CONTRACTS_FULL")]
public static void Assume(bool condition);

Parameters

condition
Boolean

The conditional expression to assume true.

Attributes

Remarks

At run time, using this method is equivalent to using the Assert(Boolean) method.

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1
UWP 10.0

Assume(Boolean, String)

Source:
Contracts.cs
Source:
Contracts.cs
Source:
Contracts.cs

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.

C#
[System.Diagnostics.Conditional("DEBUG")]
[System.Diagnostics.Conditional("CONTRACTS_FULL")]
public static void Assume(bool condition, string userMessage);
C#
[System.Diagnostics.Conditional("DEBUG")]
[System.Diagnostics.Conditional("CONTRACTS_FULL")]
public static void Assume(bool condition, string? userMessage);

Parameters

condition
Boolean

The conditional expression to assume true.

userMessage
String

The message to post if the assumption fails.

Attributes

Remarks

If userMessage 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 Assert(Boolean, String) method.

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1
UWP 10.0