Click or drag to resize

TryCastWorkerTValue, TResult Class

Provide fluent notation for try-casting types and returning a result.

Create this object using ReturningTResult

Inheritance Hierarchy
SystemObject
  TomsToolbox.DesktopTryCastWorkerBaseTValue, TResult
    TomsToolbox.DesktopTryCastWorkerTValue, TResult

Namespace: TomsToolbox.Desktop
Assembly: TomsToolbox.Desktop (in TomsToolbox.Desktop.dll) Version: 2.21.0+44d18b541fc9419ec3c549350a832394661b2a4d
XMLNS for XAML: Not mapped to an xmlns.
Syntax
public class TryCastWorker<TValue, TResult> : TryCastWorkerBase<TValue, TResult>
where TValue : class

Type Parameters

TValue
The type of the value.
TResult
The type of the result.

The TryCastWorkerTValue, TResult type exposes the following members.

Properties
 NameDescription
Protected propertyInternalResult Gets the result of the action of the first succeeded cast.
(Inherited from TryCastWorkerBaseTValue, TResult)
Public propertyResult Gets the result of the action of the first succeeded cast.
Protected propertyValue Gets the value to cast.
(Inherited from TryCastWorkerBaseTValue, TResult)
Top
Methods
 NameDescription
Public methodElse Executes the action and returns the result if no previous cast has succeeded.
Public methodElseThrow Throws an InvalidOperationException if none of the casts have succeeded.
(Inherited from TryCastWorkerBaseTValue, TResult)
Public methodElseThrow(String) Throws an InvalidOperationException if none of the casts have succeeded.
(Inherited from TryCastWorkerBaseTValue, TResult)
Protected methodTryExecuteTTarget Tries to cast the value and executes the action if the cast was successful.
(Inherited from TryCastWorkerBaseTValue, TResult)
Public methodWhenTTarget Tries to cast the value to TTarget; if the cast succeeds, the action is executed and the result is stored in the Result property.
Top
Extension Methods
 NameDescription
Public Extension MethodSafeCastT Performs a cast from object to T, avoiding possible null violations if T is a value type.
(Defined by ObjectExtensions)
Top
See Also