ThrowIfDisposed Method
Definition
ThrowIfDisposed(bool, object, string)
Validates and throws an ObjectDisposedException if the specified condition is true.
public static void ThrowIfDisposed(bool condition, object instance, string message = "Cannot access a disposed object.")
Parameters
conditionboolThe condition to evaluate.
instanceobjectThe object whose type's full name should be included in any resulting ObjectDisposedException.
messagestringA message that describes the error.
Remarks
This guard should be called when performing an operation on a disposed object - not when validating arguments passed to a member.
Exceptions
- ObjectDisposedException
The
conditionistrue.
ThrowIfDisposed(bool, Type, string)
Validates and throws an ObjectDisposedException if the specified condition is true.
public static void ThrowIfDisposed(bool condition, Type type, string message = "Cannot access a disposed object.")
Parameters
conditionboolThe condition to evaluate.
typeTypeThe type whose full name should be included in any resulting ObjectDisposedException.
messagestringA message that describes the error.
Remarks
This guard should be called when performing an operation on a disposed object - not when validating arguments passed to a member.
Exceptions
- ObjectDisposedException
The
conditionistrue.