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

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

Static Public Member Functions

static object GetValue (object obj)
 Gets a real object value. If object is a wrapper, it unwraps the value behind it. Otherwise it returns the same object value. More...
 
static bool HasProperty (object obj, string name)
 Checks if object has a property with specified 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. More...
 
static object GetProperty (object obj, string name)
 Gets 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. More...
 
static List< string > GetPropertyNames (object obj)
 Gets names of all properties implemented in specified object. More...
 
static Dictionary< string, object > GetProperties (object obj)
 Get values of all properties in specified object and returns them as a map. The object can be a user defined object, map or array.Returned properties correspondently are object properties, map key-pairs or array elements with their indexes. More...
 

Detailed Description

Helper class to perform property introspection and dynamic reading.

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

var myObj = new MyObject();
var properties = ObjectReader.GetPropertyNames();
ObjectReader.HasProperty(myObj, "myProperty");
var value = PropertyReflector.GetProperty(myObj, "myProperty");
var myMap = new Dictionary<string, object>(){
{"key1", 123},
{"key2", "ABC"};
};
ObjectReader.HasProperty(myMap, "key1");
var value = ObjectReader.getProperty(myMap, "key1");
int[] myArray = new int[] { 1, 2, 3 };
ObjectReader.HasProperty(myArrat, "0");
var value = ObjectReader.GetProperty(myArray, "0");

See PropertyReflector

Member Function Documentation

◆ GetProperties()

static Dictionary<string, object> PipServices3.Commons.Reflect.ObjectReader.GetProperties ( object  obj)
static

Get values of all properties in specified object and returns them as a map. The object can be a user defined object, map or array.Returned properties correspondently are object properties, map key-pairs or array elements with their indexes.

Parameters
objan object to get properties from.
Returns
a map, containing the names of the object's properties and their values.

◆ GetProperty()

static object PipServices3.Commons.Reflect.ObjectReader.GetProperty ( object  obj,
string  name 
)
static

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

Parameters
objan object to read property from.
namea name of the property to get.
Returns
the property value or null if property doesn't exist or introspection failed.

◆ GetPropertyNames()

static List<string> PipServices3.Commons.Reflect.ObjectReader.GetPropertyNames ( object  obj)
static

Gets names of all properties implemented in specified object.

The object can be a user defined object, map or array.Returned property name correspondently are object properties, map keys or array indexes.

Parameters
objan objec to introspect.
Returns
a list with property names.

◆ GetValue()

static object PipServices3.Commons.Reflect.ObjectReader.GetValue ( object  obj)
static

Gets a real object value. If object is a wrapper, it unwraps the value behind it. Otherwise it returns the same object value.

Parameters
objan object to unwrap.
Returns
an actual (unwrapped) object value.

◆ HasProperty()

static bool PipServices3.Commons.Reflect.ObjectReader.HasProperty ( object  obj,
string  name 
)
static

Checks if object has a property with specified 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.

Parameters
objan object to introspect.
namea name of the property to check.
Returns
true if the object has the property and false if it doesn't.

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