Pip-Services-Commons-Dotnet
Static Public Member Functions | List of all members
PipServices3.Commons.Convert.TypeConverter Class Reference

Converts arbitrary values into objects specific by TypeCodes. For each TypeCode this class calls corresponding converter which applies extended conversion rules to convert the values. More...

Static Public Member Functions

static bool IsPrimitiveType (object obj)
 
static bool IsPrimitiveType (Type type)
 
static TypeCode ToTypeCode (Type type)
 Gets TypeCode for specific type. More...
 
static TypeCode ToTypeCode (object value)
 Gets TypeCode for specific value. More...
 
static T ToNullableType< T > (object value)
 Converts value into an object type specified by Type Code or returns null when conversion is not possible. More...
 
static T ToType< T > (object value)
 Converts value into an object type specified by Type Code or returns type default when conversion is not possible. More...
 
static T ToTypeWithDefault< T > (object value, T defaultValue)
 Converts value into an object type specified by Type Code or returns default value when conversion is not possible. More...
 
static String ToString (TypeCode type)
 Converts a TypeCode into its string name. More...
 

Detailed Description

Converts arbitrary values into objects specific by TypeCodes. For each TypeCode this class calls corresponding converter which applies extended conversion rules to convert the values.

var value1 = TypeConverter.toType(TypeCode.Integer, "123.456"); // Result: 123
var value2 = TypeConverter.toType(TypeCode.DateTime, 123); // Result: DateTime(123)
var value3 = TypeConverter.toType(TypeCode.Boolean, "F"); // Result: false

Member Function Documentation

◆ ToNullableType< T >()

static T PipServices3.Commons.Convert.TypeConverter.ToNullableType< T > ( object  value)
static

Converts value into an object type specified by Type Code or returns null when conversion is not possible.

Template Parameters
Tthe Class type for the data type.
Parameters
valuethe value to convert.
Returns
object value of type corresponding to TypeCode, or null when conversion is not supported.

See TypeConverter.ToTypeCode(Type)

Type Constraints
T :struct 

◆ ToString()

static String PipServices3.Commons.Convert.TypeConverter.ToString ( TypeCode  type)
static

Converts a TypeCode into its string name.

Parameters
typethe TypeCode to convert into a string.
Returns
the name of the TypeCode passed as a string value.

◆ ToType< T >()

static T PipServices3.Commons.Convert.TypeConverter.ToType< T > ( object  value)
static

Converts value into an object type specified by Type Code or returns type default when conversion is not possible.

Template Parameters
Tthe Class type for the data type into which 'value' is to be converted.
Parameters
valuethe value to convert
Returns
object value of type corresponding to TypeCode, or type default when conversion is not supported.

See ToTypeWithDefault<T>(object, T)

◆ ToTypeCode() [1/2]

static TypeCode PipServices3.Commons.Convert.TypeConverter.ToTypeCode ( Type  type)
static

Gets TypeCode for specific type.

Parameters
typethe Class type for the data type.
Returns
the TypeCode that corresponds to the passed object's type.

◆ ToTypeCode() [2/2]

static TypeCode PipServices3.Commons.Convert.TypeConverter.ToTypeCode ( object  value)
static

Gets TypeCode for specific value.

Parameters
valuevalue whose TypeCode is to be resolved.
Returns
the TypeCode that corresponds to the passed object's type.

◆ ToTypeWithDefault< T >()

static T PipServices3.Commons.Convert.TypeConverter.ToTypeWithDefault< T > ( object  value,
defaultValue 
)
static

Converts value into an object type specified by Type Code or returns default value when conversion is not possible.

Template Parameters
Tthe Class type for the data type into which 'value' is to be converted.
Parameters
valuethe value to convert.
defaultValuethe default value to return if conversion is not possible (returns null).
Returns
object value of type corresponding to TypeCode, or default value when conversion is not supported

The documentation for this class was generated from the following file: