1 | /**
|
2 | * Helper class to perform property introspection and dynamic writing.
|
3 | *
|
4 | * In contrast to [[PropertyReflector]] which only introspects regular objects,
|
5 | * this ObjectWriter 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 ObjectWriter treats all property names as case insensitive.
|
14 | *
|
15 | * @see [[PropertyReflector]]
|
16 | *
|
17 | * ### Example ###
|
18 | *
|
19 | * let myObj = new MyObject();
|
20 | *
|
21 | * ObjectWriter.setProperty(myObj, "myProperty", 123);
|
22 | *
|
23 | * let myMap = { key1: 123, key2: "ABC" };
|
24 | * ObjectWriter.setProperty(myMap, "key1", "XYZ");
|
25 | *
|
26 | * let myArray = [1, 2, 3]
|
27 | * ObjectWriter.setProperty(myArray, "0", 123);
|
28 | */
|
29 | export declare class ObjectWriter {
|
30 | /**
|
31 | * Sets value of object property specified by its name.
|
32 | *
|
33 | * The object can be a user defined object, map or array.
|
34 | * The property name correspondently must be object property,
|
35 | * map key or array index.
|
36 | *
|
37 | * If the property does not exist or introspection fails
|
38 | * this method doesn't do anything and doesn't any throw errors.
|
39 | *
|
40 | * @param obj an object to write property to.
|
41 | * @param name a name of the property to set.
|
42 | * @param value a new value for the property to set.
|
43 | */
|
44 | static setProperty(obj: any, name: string, value: any): void;
|
45 | /**
|
46 | * Sets values of some (all) object properties.
|
47 | *
|
48 | * The object can be a user defined object, map or array.
|
49 | * Property values correspondently are object properties,
|
50 | * map key-pairs or array elements with their indexes.
|
51 | *
|
52 | * If some properties do not exist or introspection fails
|
53 | * they are just silently skipped and no errors thrown.
|
54 | *
|
55 | * @param obj an object to write properties to.
|
56 | * @param values a map, containing property names and their values.
|
57 | *
|
58 | * @see [[setProperty]]
|
59 | */
|
60 | static setProperties(obj: any, values: any): void;
|
61 | }
|