Options
All
  • Public
  • Public/Protected
  • All
Menu

Class TypeReflector

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.

see

TypeDescriptor

Example

let descriptor = new TypeDescriptor("MyObject", "mylibrary");
Typeeflector.getTypeByDescriptor(descriptor);
let myObj = TypeReflector.createInstanceByDescriptor(descriptor);

TypeDescriptor.isPrimitive(myObject);         // Result: false
TypeDescriptor.isPrimitive(123);                // Result: true

Hierarchy

  • TypeReflector

Index

Methods

Static createInstance

  • createInstance(name: string, library: string, ...args: any[]): any
  • Creates an instance of an object type specified by its name and library where it is defined.

    see

    getType

    see

    createInstanceByType

    Parameters

    • name: string

      an object type name.

    • library: string

      a library (module) where object type is defined.

    • Rest ...args: any[]

      arguments for the object constructor.

    Returns any

    the created object instance.

Static createInstanceByDescriptor

  • createInstanceByDescriptor(descriptor: TypeDescriptor, ...args: any[]): any
  • Creates an instance of an object type specified by type descriptor.

    see

    createInstance

    see

    TypeDescriptor

    Parameters

    • descriptor: TypeDescriptor

      a type descriptor that points to an object type

    • Rest ...args: any[]

      arguments for the object constructor.

    Returns any

    the created object instance.

Static createInstanceByType

  • createInstanceByType(type: any, ...args: any[]): any
  • Creates an instance of an object type.

    Parameters

    • type: any

      an object type (factory function) to create.

    • Rest ...args: any[]

      arguments for the object constructor.

    Returns any

    the created object instance.

Static getType

  • getType(name: string, library: string): any
  • Gets object type by its name and library where it is defined.

    Parameters

    • name: string

      an object type name.

    • library: string

      a library where the type is defined

    Returns any

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

Static getTypeByDescriptor

  • Gets object type by type descriptor.

    see

    getType

    see

    TypeDescriptor

    Parameters

    • descriptor: TypeDescriptor

      a type descriptor that points to an object type

    Returns any

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

Static isPrimitive

  • isPrimitive(value: any): boolean
  • Checks if value has primitive type.

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

    see

    TypeConverter.toTypeCode

    see

    TypeCode

    Parameters

    • value: any

      a value to check

    Returns boolean

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

Generated using TypeDoc