pip_services3_commons.reflect.TypeReflector module

pip_services3_commons.reflect.TypeReflector

Type reflector implementation

copyright

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

license

MIT, see LICENSE for more details.

class pip_services3_commons.reflect.TypeReflector.TypeReflector

Bases: object

Helper class to perform object type introspection and object instantiation.

This class has symmetric implementation across all languages supported by Pip.Services toolkit and used to support dynamic data processing.

Because all languages have different casing and case sensitivity __rules, this TypeReflector treats all type names as case insensitive.

Example:

descriptor = TypeDescriptor("MyObject", "mylibrary")
Typeeflector.get_type_by_descriptor(descriptor)
myObj = TypeReflector.create_instance_by_descriptor(descriptor)
TypeDescriptor.is_primitive(myObject)           # Result: false
TypeDescriptor.is_primitive(123)                # Result: true
static create_instance(name: str, library: str, *args: Any) → Any

Creates an instance of an object type specified by its name and library where it is defined.

Parameters
  • name – an object type (factory function) to create.

  • library – a library (module) where object type is defined.

  • args – arguments for the object constructor.

Returns

the created object instance.

static create_instance_by_descriptor(descriptor: pip_services3_commons.reflect.TypeDescriptor.TypeDescriptor, *args: Any) → Any

Creates an instance of an object type specified by type descriptor.

Parameters
  • descriptor – a type descriptor that points to an object type

  • args – arguments for the object constructor.

Returns

the created object instance.

static create_instance_by_type(obj_type: Any, *args: Any) → Any

Creates an instance of an object type.

Parameters
  • obj_type – an object type (factory function) to create.

  • args – arguments for the object constructor.

Returns

the created object instance.

static get_type(name: str, library: str) → Any

Gets object type by its name and library where it is defined.

Parameters
  • name – an object type name.

  • library – a library where the type is defined

Returns

the object type or null is the type wasn’t found.

static get_type_by_descriptor(descriptor: pip_services3_commons.reflect.TypeDescriptor.TypeDescriptor) → Any

Gets object type by type descriptor.

Parameters

descriptor – a type descriptor that points to an object type

Returns

the object type or null is the type wasn’t found.

static is_primitive(value: Any)bool

Checks if args has primitive type.

Primitive types are: numbers, strings, booleans, date and time. Complex (non-primitive types are): objects, maps and arrays

Parameters

value – a args to check

Returns

true if the args has primitive type and false if args type is complex.