pip_services3_commons.reflect.ObjectReader module
pip_services3_commons.reflect.ObjectReader
Object reader 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.ObjectReader.
ObjectReader
Bases:
object
Helper class to perform property introspection and dynamic reading.
In contrast to
PropertyReflector
which only introspects regular objects, this ObjectReader is also able to handle maps and arrays.For maps properties are key-pairs identified by string keys, For arrays properties are elements identified by integer index.
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 ObjectReader treats all property names as case insensitive.
Example:
myObj = MyObject() properties = ObjectReader.get_property_names() ObjectReader.has_property(myObj, "myProperty") args = PropertyReflector.get_property(myObj, "myProperty") myMap = { key1: 123, key2: "ABC" } ObjectReader.has_property(myMap, "key1") args = ObjectReader.get_property(myMap, "key1") myArray = [1, 2, 3] ObjectReader.has_property(myArrat, "0") args = ObjectReader.get_property(myArray, "0")
-
static
get_properties
(obj: Any) → Any Get values of all properties in specified object and returns them as a map.
The object can be a user defined object, map or array. Returned properties correspondently are object properties, map key-pairs or array elements with their indexes.
- 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.
The object can be a user defined object, map or array. The property name correspondently must be object property, map key or array index.
- 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.
The object can be a user defined object, map or array. Returned property name correspondently are object properties, map keys or array indexes.
- Parameters
obj – an object to introspect.
- Returns
a list with property names.
-
static
get_value
(obj: Any) → Any Gets a real object args. If object is a wrapper, it unwraps the args behind it. Otherwise it returns the same object args.
- Parameters
obj – an object to unwrap.
- Returns
an actual (unwrapped) object args.
-
static
has_property
(obj: Any, name: str) → bool Checks if object has a property with specified name.
The object can be a user defined object, map or array. The property name correspondently must be object property, map key or array index.
- 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