ThrowIfInvalidState Method
Definition
ThrowIfInvalidState(bool, string, string)
Validates and throws an InvalidOperationException if the specified condition is true.
public static void ThrowIfInvalidState(bool condition, string message = "Operation is not valid due to the current state of the object.", string expression = null)
Parameters
conditionboolThe value that determines if an InvalidOperationException is thrown.
messagestringA message that describes the error.
expressionstringThe
conditionexpressed as a string.
Remarks
This guard should be called when validating the state of an object - not when validating arguments passed to a member.
Exceptions
- InvalidOperationException
conditionistrue.