Class DynamicCast
- Namespace
- LfrlAnvil
- Assembly
- LfrlAnvil.Core.dll
Contains methods for type casting.
public static class DynamicCast
- Inheritance
-
DynamicCast
- Inherited Members
Methods
To<T>(object?)
Casts the provided value to the desired reference type.
[Pure]
public static T? To<T>(object? value) where T : class
Parameters
valueobjectValue to cast.
Returns
- T
Provided
valueas the desired reference type.
Type Parameters
TDesired type.
Exceptions
- InvalidCastException
When the provided
valueis not of desired type.
TryTo<T>(object?)
Attempts to cast the provided value to the desired reference type.
[Pure]
public static T? TryTo<T>(object? value) where T : class
Parameters
valueobjectValue to cast.
Returns
- T
Provided
valueas the desired reference type or null when it is not of that type.
Type Parameters
TDesired type.
TryUnbox<T>(object?)
Attempts to cast the provided boxed value to the desired value type.
[Pure]
public static T? TryUnbox<T>(object? value) where T : struct
Parameters
valueobjectValue to cast.
Returns
- T?
Provided
valueunboxed as the desired value type or null when it is not of that type.
Type Parameters
TDesired type.
Unbox<T>(object?)
Casts the provided boxed value to the desired value type.
[Pure]
public static T Unbox<T>(object? value) where T : struct
Parameters
valueobjectValue to cast.
Returns
- T
Provided
valueunboxed as the desired value type.
Type Parameters
TDesired type.
Exceptions
- InvalidCastException
When the provided
valueis not of desired type.