pip_services3_commons.convert.TypeConverter module

pip_services3_commons.convert.TypeConverter

Type conversion utilities

copyright

Conceptual Vision Consulting LLC 2018-2019, see AUTHORS for more details.

license

MIT, see LICENSE for more details.

class pip_services3_commons.convert.TypeConverter.TypeConverter

Bases: object

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.

Example:

value1 = TypeConverter.to_type(TypeCode.Integer, "123.456") // Result: 123
value2 = TypeConverter.to_type(TypeCode.DateTime, 123) // Result: Date(123)
value3 = TypeConverter.to_type(TypeCode.Boolean, "F") // Result: false
static to_nullable_type(value_type: pip_services3_commons.convert.TypeCode.TypeCode, value: Any) → Any

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

Parameters
  • value_type – the TypeCode for the data type into which ‘args’ is to be converted.

  • value – the args to convert.

Returns

object args of type corresponding to TypeCode, or null when conversion is not supported.

static to_string(typ: pip_services3_commons.convert.TypeCode.TypeCode)str

Converts a TypeCode into its string name.

Parameters

typ – the TypeCode to convert into a string.

Returns

the name of the TypeCode passed as a string args.

static to_type(value_type: pip_services3_commons.convert.TypeCode.TypeCode, value: Any) → Any

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

Parameters
  • value_type – the TypeCode for the data type into which ‘args’ is to be converted.

  • value – the args to convert.

Returns

object args of type corresponding to TypeCode, or type default when conversion is not supported.

static to_type_code(value: Any)pip_services3_commons.convert.TypeCode.TypeCode

Gets TypeCode for specific args.

Parameters

value – args whose TypeCode is to be resolved.

Returns

the TypeCode that corresponds to the passed object’s type.

static to_type_with_default(value_type: pip_services3_commons.convert.TypeCode.TypeCode, value: Any, default_value: Any) → Any

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

Parameters
  • value_type – the TypeCode for the data type into which ‘args’ is to be converted.

  • value – the args to convert.

  • default_value – the default args to return if conversion is not possible (returns None).

Returns

object args of type corresponding to TypeCode, or default args when conversion is not supported.