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
value
objectValue to cast.
Returns
- T
Provided
value
as the desired reference type.
Type Parameters
T
Desired type.
Exceptions
- InvalidCastException
When the provided
value
is 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
value
objectValue to cast.
Returns
- T
Provided
value
as the desired reference type or null when it is not of that type.
Type Parameters
T
Desired 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
value
objectValue to cast.
Returns
- T?
Provided
value
unboxed as the desired value type or null when it is not of that type.
Type Parameters
T
Desired 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
value
objectValue to cast.
Returns
- T
Provided
value
unboxed as the desired value type.
Type Parameters
T
Desired type.
Exceptions
- InvalidCastException
When the provided
value
is not of desired type.