1 | /**
|
2 | * Helper class to perform property introspection and dynamic reading.
|
3 | *
|
4 | * In contrast to [[PropertyReflector]] which only introspects regular objects,
|
5 | * this ObjectReader is also able to handle maps and arrays.
|
6 | * For maps properties are key-pairs identified by string keys,
|
7 | * For arrays properties are elements identified by integer index.
|
8 | *
|
9 | * This class has symmetric implementation across all languages supported
|
10 | * by Pip.Services toolkit and used to support dynamic data processing.
|
11 | *
|
12 | * Because all languages have different casing and case sensitivity rules,
|
13 | * this ObjectReader treats all property names as case insensitive.
|
14 | *
|
15 | * @see [[PropertyReflector]]
|
16 | *
|
17 | * ### Example ###
|
18 | *
|
19 | * let myObj = new MyObject();
|
20 | *
|
21 | * let properties = ObjectReader.getPropertyNames();
|
22 | * ObjectReader.hasProperty(myObj, "myProperty");
|
23 | * let value = PropertyReflector.getProperty(myObj, "myProperty");
|
24 | *
|
25 | * let myMap = { key1: 123, key2: "ABC" };
|
26 | * ObjectReader.hasProperty(myMap, "key1");
|
27 | * let value = ObjectReader.getProperty(myMap, "key1");
|
28 | *
|
29 | * let myArray = [1, 2, 3]
|
30 | * ObjectReader.hasProperty(myArrat, "0");
|
31 | * let value = ObjectReader.getProperty(myArray, "0");
|
32 | */
|
33 | export declare class ObjectReader {
|
34 | /**
|
35 | * Gets a real object value.
|
36 | * If object is a wrapper, it unwraps the value behind it.
|
37 | * Otherwise it returns the same object value.
|
38 | *
|
39 | * @param obj an object to unwrap..
|
40 | * @returns an actual (unwrapped) object value.
|
41 | */
|
42 | static getValue(obj: any): any;
|
43 | /**
|
44 | * Checks if object has a property with specified name.
|
45 | *
|
46 | * The object can be a user defined object, map or array.
|
47 | * The property name correspondently must be object property,
|
48 | * map key or array index.
|
49 | *
|
50 | * @param obj an object to introspect.
|
51 | * @param name a name of the property to check.
|
52 | * @returns true if the object has the property and false if it doesn't.
|
53 | */
|
54 | static hasProperty(obj: any, name: string): boolean;
|
55 | /**
|
56 | * Gets value of object property specified by its name.
|
57 | *
|
58 | * The object can be a user defined object, map or array.
|
59 | * The property name correspondently must be object property,
|
60 | * map key or array index.
|
61 | *
|
62 | * @param obj an object to read property from.
|
63 | * @param name a name of the property to get.
|
64 | * @returns the property value or null if property doesn't exist or introspection failed.
|
65 | */
|
66 | static getProperty(obj: any, name: string): any;
|
67 | /**
|
68 | * Gets names of all properties implemented in specified object.
|
69 | *
|
70 | * The object can be a user defined object, map or array.
|
71 | * Returned property name correspondently are object properties,
|
72 | * map keys or array indexes.
|
73 | *
|
74 | * @param obj an objec to introspect.
|
75 | * @returns a list with property names.
|
76 | */
|
77 | static getPropertyNames(obj: any): string[];
|
78 | /**
|
79 | * Get values of all properties in specified object
|
80 | * and returns them as a map.
|
81 | *
|
82 | * The object can be a user defined object, map or array.
|
83 | * Returned properties correspondently are object properties,
|
84 | * map key-pairs or array elements with their indexes.
|
85 | *
|
86 | * @param obj an object to get properties from.
|
87 | * @returns a map, containing the names of the object's properties and their values.
|
88 | */
|
89 | static getProperties(obj: any): any;
|
90 | }
|