Class TypeConverterHelper
- Namespace
- Acuit.Pinpoint.Workflows.ComponentModel
- Assembly
- Acuit.Pinpoint.Workflows.dll
public static class TypeConverterHelper
- Inheritance
-
TypeConverterHelper
- Inherited Members
Methods
Convert(object?, Type, CultureInfo?)
Converts a value to another type using any conversion method available.
public static object? Convert(object? value, Type conversionType, CultureInfo? culture)
Parameters
valueobjectThe value.
conversionTypeTypeThe type to which to convert the value.
cultureCultureInfoA CultureInfo. If null is passed, the current culture is assumed.
Returns
- object
The converted value.
Remarks
- If
valueis null andconversionTypeis a reference type or Nullable<T>, then null is returned. - If
valueis a string andconversionTypeis a Nullable<T>:- If
valueis an empty string, then null is returned. - Otherwise,
conversionType's underlying Nullable<T> type is used in place ofconversionTypefor the target type for the rest of the steps below.
- If
- If
valueis already the same type asconversionType, then the originalvalueis returned. - If
valueis assignable to aconversionType, then the originalvalueis returned. - If the type converter for
value's type can convert the value toconversionType, then it is used to perform the conversion. - If the type converter for
conversionTypecan convert the value fromvalue's type, then it is used to perform the conversion. - If
valueimplements IConvertible, then it is used to attempt the conversion.
Exceptions
- ArgumentNullException
conversionTypeis null.- InvalidOperationException
Cannot convert null to
conversionType.- InvalidOperationException
Cannot convert from
value's type toconversionType.- FormatException
valueis not in a format recognized byconversionType.- OverflowException
valuerepresents a number that is out of the range ofconversionType.
ConvertValueToInvariantString(object?)
public static string? ConvertValueToInvariantString(object? value)
Parameters
valueobject
Returns
Convert<T>(object?, CultureInfo?)
Converts a value to another type using any conversion method available.
public static T? Convert<T>(object? value, CultureInfo? culture)
Parameters
valueobjectThe value
cultureCultureInfoA CultureInfo. If null is passed, the current culture is assumed.
Returns
- T
The converted value.
Type Parameters
TThe type to which to convert the value.
Remarks
See the remarks for Convert(object?, Type, CultureInfo?) for more information.
Exceptions
- InvalidOperationException
Cannot convert null to
T.- InvalidOperationException
Cannot convert from
value's type toT.- FormatException
valueis not in a format recognized byT.- OverflowException
valuerepresents a number that is out of the range ofT.
InvariantConvert(object?, Type)
Converts a value to another type using any conversion method available, using the invariant culture.
public static object? InvariantConvert(object? value, Type conversionType)
Parameters
Returns
- object
The converted value.
Remarks
See the remarks for Convert(object?, Type, CultureInfo?) for more information.
Exceptions
- ArgumentNullException
conversionTypeis null.- InvalidOperationException
Cannot convert null to
conversionType.- InvalidOperationException
Cannot convert from
value's type toconversionType.- FormatException
valueis not in a format recognized byconversionType.- OverflowException
valuerepresents a number that is out of the range ofconversionType.
InvariantConvert<T>(object?)
Converts a value to another type using any conversion method available, using the invariant culture.
public static T InvariantConvert<T>(object? value)
Parameters
valueobjectThe value
Returns
- T
The converted value.
Type Parameters
TThe type to which to convert the value.
Remarks
See the remarks for Convert(object?, Type, CultureInfo?) for more information.
ResolveType(object)
Resolves an actual type from an object specifying a type.
public static Type ResolveType(object type)
Parameters
Returns
- Type
The actual type resolved from
type.
Remarks
The following are supported for type:
- A
typeis returned as-is. - C# built-in types are supported by name (case-insensitive).
- Full type names of any type in this assembly or mscorlib (case-insensitive).
- Type names of any type in mscorlib in the "System" namespace (case-insensitive).
- Full type names of any type in any loaded assembly or mscorlib (case-sensitive; the first one found is used when the same type name exists in multiple assembies).
- A string that ends with "[]" is resolved as an array type.
- A string that ends with "?" is resolved as a nullable type.
Exceptions
- ArgumentNullException
typeis null.- InvalidOperationException
A type cannot be resolved from an object of the type of
type.- InvalidOperationException
A type cannot be resolved from the value of
typewhen it is a string.