Extended conversion utilities to convert any type to any other type provided the conversion is valid.
More...
◆ CanConvert()
static bool Pathfinder.Util.ConvertAny.CanConvert |
( |
Type |
fromType, |
|
|
Type |
toType |
|
) |
| |
|
static |
- Parameters
-
fromType | From type. |
toType | To type. |
- Returns
true
if the conversion is valid; otherwise, false
.
This method checks 4 types of conversions:
- If they are the same type, returns true.
- If they are both IConvertible types, return true.
- If the toType is part of the inheritance chain of fromType.
- Direct casting, only returns true if both types have default constructors.
◆ CanConvert< ToType >()
- Template Parameters
-
ToType | The type of to type. |
- Parameters
-
- Returns
true
if this instance can convert the specified from value; otherwise, false
.
◆ Convert< ToType >()
static ToType Pathfinder.Util.ConvertAny.Convert< ToType > |
( |
object |
fromValue | ) |
|
|
static |
- Template Parameters
-
ToType | The type to convert to. |
- Parameters
-
fromValue | The value to convert. |
- Returns
- Converted value.
- Exceptions
-
InvalidCastException | Raised when the value cannot be converted to the specified type. |
◆ ConvertByType()
static object Pathfinder.Util.ConvertAny.ConvertByType |
( |
object |
fromValue, |
|
|
Type |
toType |
|
) |
| |
|
static |
- Parameters
-
fromValue | The value to convert. |
toType | The type to convert to. |
- Returns
- Object that represents the converted type.
◆ Default< T >()
static T Pathfinder.Util.ConvertAny.Default< T > |
( |
| ) |
|
|
static |
- Template Parameters
-
T | Type to create a default instance of. |
- Returns
- Default instance of T .
For primitive types this will create a value of 0 with the specified type. For objects, if the object has a default constructor it will return a default instance of the type. If the object does not have a default constructor, it will return null.
◆ DefaultByType()
static object Pathfinder.Util.ConvertAny.DefaultByType |
( |
Type |
type | ) |
|
|
static |
- Parameters
-
- Returns
- Instance of the specified type.
This method uses the generic Default method to create an instance of the type.
◆ TryConvert< ToType >()
static bool Pathfinder.Util.ConvertAny.TryConvert< ToType > |
( |
object |
value, |
|
|
out ToType |
toValue |
|
) |
| |
|
static |
- Template Parameters
-
ToType | The type to convert to. |
- Parameters
-
value | Value to convert. |
toValue | Converted value. |
- Returns
true
if conversion succeeds, false
otherwise.
If the conversion fails, the value of toValue is the default of that particular type.
The documentation for this class was generated from the following file: