Options
All
  • Public
  • Public/Protected
  • All
Menu

Class ObjectReader

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.

see

PropertyReflector

Example

let myObj = new MyObject();

let properties = ObjectReader.getPropertyNames();
ObjectReader.hasProperty(myObj, "myProperty");
let value = PropertyReflector.getProperty(myObj, "myProperty");

let myMap = { key1: 123, key2: "ABC" };
ObjectReader.hasProperty(myMap, "key1");
let value = ObjectReader.getProperty(myMap, "key1");

let myArray = [1, 2, 3]
ObjectReader.hasProperty(myArrat, "0");
let value = ObjectReader.getProperty(myArray, "0");

Hierarchy

  • ObjectReader

Index

Methods

Static getProperties

  • getProperties(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: any

      an object to get properties from.

    Returns any

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

Static getProperty

  • getProperty(obj: any, name: string): any
  • Gets value 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: any

      an object to read property from.

    • name: string

      a name of the property to get.

    Returns any

    the property value or null if property doesn't exist or introspection failed.

Static getPropertyNames

  • getPropertyNames(obj: any): string[]
  • 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: any

      an objec to introspect.

    Returns string[]

    a list with property names.

Static getValue

  • getValue(obj: any): any
  • Gets a real object value. If object is a wrapper, it unwraps the value behind it. Otherwise it returns the same object value.

    Parameters

    • obj: any

      an object to unwrap..

    Returns any

    an actual (unwrapped) object value.

Static hasProperty

  • hasProperty(obj: any, name: string): boolean
  • 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: any

      an object to introspect.

    • name: string

      a name of the property to check.

    Returns boolean

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

Generated using TypeDoc