ObjectExtensionsThrowIfTObject, TException Method
Throws the specified exception if the given condition in the source object is true.
Namespace: DevCase.Extensions.ObjectExtensionsAssembly: DevCase.net48 (in DevCase.net48.dll) Version: 6.0.0.0 (6.0)
XMLNS for XAML: Not mapped to an xmlns.
[EditorBrowsableAttribute(EditorBrowsableState.Always)]
public static void ThrowIf<TObject, TException>(
this TObject obj,
Func<TObject, bool> predicate,
TException ex = null
)
where TException : Exception
<ExtensionAttribute>
<EditorBrowsableAttribute(EditorBrowsableState.Always)>
Public Shared Sub ThrowIf(Of TObject, TException As Exception) (
obj As TObject,
predicate As Func(Of TObject, Boolean),
Optional ex As TException = Nothing
)
Dim obj As TObject
Dim predicate As Func(Of TObject, Boolean)
Dim ex As TException
obj.ThrowIf(predicate, ex)
public:
[ExtensionAttribute]
[EditorBrowsableAttribute(EditorBrowsableState::Always)]
generic<typename TObject, typename TException>
where TException : Exception
static void ThrowIf(
TObject obj,
Func<TObject, bool>^ predicate,
TException ex = nullptr
)
[<ExtensionAttribute>]
[<EditorBrowsableAttribute(EditorBrowsableState.Always)>]
static member ThrowIf :
obj : 'TObject *
predicate : Func<'TObject, bool> *
?ex : 'TException
(* Defaults:
let _ex = defaultArg ex null
*)
-> unit when 'TException : Exception
No code example is currently available or this language may not be supported.
- obj TObject
-
The object to evaluate.
- predicate FuncTObject, Boolean
-
The predicate function to evaluate the object.
- ex TException (Optional)
-
Optionally, a instance of the exception to throw when
the predicate condition is true.
If this value is null, a default instance of the exception type will be used.
- TObject
-
The type of object to evaluate.
- TException
-
The type of exception to throw.
In Visual Basic and C#, you can call this method as an instance method on any object of type
TObject. When you use instance method syntax to call this method, omit the first parameter. For more information, see
Extension Methods (Visual Basic) or
Extension Methods (C# Programming Guide).
This is a code example.
No code example is currently available or this language may not be supported.
Dim value As Integer = 0
' value.ThrowIf(Of ArgumentOutOfRangeException)(Function(x) x = 0)
value.ThrowIf(Function(x) x = 0, New ArgumentOutOfRangeException(paramName:=NameOf(value)))
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.