Table of Contents

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

value object

The value.

conversionType Type

The type to which to convert the value.

culture CultureInfo

A CultureInfo. If null is passed, the current culture is assumed.

Returns

object

The converted value.

Remarks

  1. If value is null and conversionType is a reference type or Nullable<T>, then null is returned.
  2. If value is a string and conversionType is a Nullable<T>:
    1. If value is an empty string, then null is returned.
    2. Otherwise, conversionType's underlying Nullable<T> type is used in place of conversionType for the target type for the rest of the steps below.
  3. If value is already the same type as conversionType, then the original value is returned.
  4. If value is assignable to a conversionType, then the original value is returned.
  5. If the type converter for value's type can convert the value to conversionType, then it is used to perform the conversion.
  6. If the type converter for conversionType can convert the value from value's type, then it is used to perform the conversion.
  7. If value implements IConvertible, then it is used to attempt the conversion.

Exceptions

ArgumentNullException

conversionType is null.

InvalidOperationException

Cannot convert null to conversionType.

InvalidOperationException

Cannot convert from value's type to conversionType.

FormatException

value is not in a format recognized by conversionType.

OverflowException

value represents a number that is out of the range of conversionType.

ConvertValueToInvariantString(object?)

public static string? ConvertValueToInvariantString(object? value)

Parameters

value object

Returns

string

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

value object

The value

culture CultureInfo

A CultureInfo. If null is passed, the current culture is assumed.

Returns

T

The converted value.

Type Parameters

T

The 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 to T.

FormatException

value is not in a format recognized by T.

OverflowException

value represents a number that is out of the range of T.

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

value object

The value

conversionType Type

The type to which to convert the value.

Returns

object

The converted value.

Remarks

See the remarks for Convert(object?, Type, CultureInfo?) for more information.

Exceptions

ArgumentNullException

conversionType is null.

InvalidOperationException

Cannot convert null to conversionType.

InvalidOperationException

Cannot convert from value's type to conversionType.

FormatException

value is not in a format recognized by conversionType.

OverflowException

value represents a number that is out of the range of conversionType.

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

value object

The value

Returns

T

The converted value.

Type Parameters

T

The 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

type object

The object specifying a type, which must either by a Type or a string.

Returns

Type

The actual type resolved from type.

Remarks

The following are supported for type:

  • A type is 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

type is 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 type when it is a string.