pip_services3_commons.reflect.PropertyReflector module

pip_services3_commons.reflect.PropertyReflector

Property 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.PropertyReflector.PropertyReflector

Bases: object

Helper class to perform property introspection and dynamic reading and writing.

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 PropertyReflector treats all property names as case insensitive.

Example:

myObj = MyObject()

properties = PropertyReflector.get_property_names()
PropertyReflector.has_property(myObj, "myProperty")

args = PropertyReflector.get_property(myObj, "myProperty")
PropertyReflector.set_property(myObj, "myProperty", 123)
static get_properties(obj: Any) → Any

Get values of all properties in specified object and returns them as a map.

Parameters

obj – an object to get properties from.

Returns

a map, containing the names of the object’s properties and their values.

static get_property(obj: Any, name: str) → Any

Gets args of object property specified by its name.

Parameters
  • obj – an object to read property from.

  • name – a name of the property to get.

Returns

the property args or null if property doesn’t exist or introspection failed.

static get_property_names(obj: Any) → List[str]

Gets names of all properties implemented in specified object.

Parameters

obj – an objec to introspect.

Returns

a list with property names.

static has_property(obj: Any, name: str)bool

Checks if object has a property with specified name.

Parameters
  • obj – an object to introspect.

  • name – a name of the property to check.

Returns

true if the object has the property and false if it doesn’t.

static set_properties(obj: Any, values: Any)

Sets values of some (all) object properties.

If some properties do not exist or introspection fails they are just silently skipped and no errors thrown.

Parameters
  • obj – an object to write properties to.

  • values – a map, containing property names and their values.

static set_property(obj: Any, name: str, value: Any)

Sets args of object property specified by its name.

If the property does not exist or introspection fails this method doesn’t do anything and doesn’t any throw errors.

Parameters
  • obj – an object to write property to.

  • name – a name of the property to set.

  • value – a new args for the property to set.