Options
All
  • Public
  • Public/Protected
  • All
Menu

Class PropertyReflector

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

let myObj = new MyObject();

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

Hierarchy

  • PropertyReflector

Index

Methods

Static getProperties

  • getProperties(obj: any): any
  • Get values of all properties in specified object and returns them as a map.

    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.

    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.

    Parameters

    • obj: any

      an objec to introspect.

    Returns string[]

    a list with property names.

Static hasProperty

  • hasProperty(obj: any, name: string): boolean
  • Checks if object has a property with specified name..

    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.

Static setProperties

  • setProperties(obj: any, values: any): void
  • 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.

    see

    setProperty

    Parameters

    • obj: any

      an object to write properties to.

    • values: any

      a map, containing property names and their values.

    Returns void

Static setProperty

  • setProperty(obj: any, name: string, value: any): void
  • Sets value 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: any

      an object to write property to.

    • name: string

      a name of the property to set.

    • value: any

      a new value for the property to set.

    Returns void

Generated using TypeDoc