Pip-Services-Commons-Dotnet
Static Public Member Functions | List of all members
PipServices3.Commons.Reflect.ObjectWriter Class Reference

Helper class to perform property introspection and dynamic writing. More...

Static Public Member Functions

static void SetProperty (object obj, string name, object value)
 Sets value of object property specified by its name. More...
 
static void SetProperties (object obj, IDictionary< string, object > values)
 Sets values of some (all) object properties. More...
 

Detailed Description

Helper class to perform property introspection and dynamic writing.

In contrast to PropertyReflector which only introspects regular objects, this ObjectWriter 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 ObjectWriter treats all property names as case insensitive.

var myObj = new MyObject();
ObjectWriter.SetProperty(myObj, "myProperty", 123);
var myMap = new Dictionary<string, object>(){
{"key1", 123},
{"key2", "ABC"}
};
ObjectWriter.SetProperty(myMap, "key1", "XYZ");
var myArray = new int[] { 1, 2, 3 };
ObjectWriter.SetProperty(myArray, "0", 123);

See PropertyReflector

Member Function Documentation

◆ SetProperties()

static void PipServices3.Commons.Reflect.ObjectWriter.SetProperties ( object  obj,
IDictionary< string, object >  values 
)
static

Sets values of some (all) object properties.

The object can be a user defined object, map or array.Property values correspondently are object properties, map key-pairs or array elements with their indexes.

If some properties do not exist or introspection fails they are just silently skipped and no errors thrown.

Parameters
objan object to write properties to.
valuesa map, containing property names and their values.

See SetProperty(object, string, object)

◆ SetProperty()

static void PipServices3.Commons.Reflect.ObjectWriter.SetProperty ( object  obj,
string  name,
object  value 
)
static

Sets 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.

If the property does not exist or introspection fails this method doesn't do anything and doesn't any throw errors.

Parameters
objan object to write property to.
namea name of the property to set.
valuea new value for the property to set.

The documentation for this class was generated from the following file: