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

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

Static Public Member Functions

static bool HasProperty (object obj, string name)
 Checks if object has a property with specified name. More...
 
static object GetProperty (object obj, string name)
 Gets value of object property specified by its name. 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. More...
 
static void SetProperty (object obj, string name, object value)
 Sets value of object property specified by its name. If the property does not exist or introspection fails this method doesn't do anything and doesn't any throw errors. More...
 
static void SetProperties (object obj, Dictionary< string, object > values)
 Sets values of some (all) object properties. If some properties do not exist or introspection fails they are just silently skipped and no errors thrown. More...
 

Static Private Member Functions

static bool MatchField (FieldInfo field, string name)
 
static bool MatchPropertyGetter (PropertyInfo property, string name)
 
static bool MatchPropertySetter (PropertyInfo property, string name)
 

Detailed Description

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

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 PropertyReflector treats all property names as case insensitive.

var myObj = new MyObject();
var properties = PropertyReflector.GetPropertyNames();
PropertyReflector.HasProperty(myObj, "myProperty");
var value = PropertyReflector.GetProperty(myObj, "myProperty");
PropertyReflector.SetProperty(myObj, "myProperty", 123);

Member Function Documentation

◆ GetProperties()

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

Get values of all properties in specified object and returns them as a map.

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.PropertyReflector.GetProperty ( object  obj,
string  name 
)
static

Gets value of object property specified by its name.

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.PropertyReflector.GetPropertyNames ( object  obj)
static

Gets names of all properties implemented in specified object.

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

◆ HasProperty()

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

Checks if object has a property with specified name.

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.

◆ SetProperties()

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

Sets values of some (all) object properties. 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.PropertyReflector.SetProperty ( object  obj,
string  name,
object  value 
)
static

Sets value of object property specified by its name. 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: