C# Class Decision.Utility.PropertyReflector

Helps to get and set property values on objects through reflection. Properties of underlying objects can be accessed directly by separating the levels in the hierarchy by dots. To get/set the name of an Ancestor, for objects that have a Parent property, you could use "Parent.Parent.Parent.Name".
ファイルを表示 Open project: rabbal/Decision

Public Methods

Method Description
GetType ( Type targetType, string propertyName ) : Type

Gets the Type of the given property of the given targetType. The targetType and propertyName parameters can't be null.

GetValue ( object target, string propertyName ) : object

Gets the value of the given property of the given target. If objects within the property hierarchy are null references, null will be returned. The target and propertyName parameters can't be null.

SetValue ( object target, string propertyName, object value ) : void

Private Methods

Method Description
CalculateDistance ( Type targetObjectType, Type baseType ) : int

Calculates the hierarchy levels between two classes. If the targetObjectType is the same as the baseType, the returned distance will be 0. If the two types do not belong to the same hierarchy, -1 will be returned.

Construct ( Type type ) : object

Creates a new object of the given type, provided that the type has a default (parameterless) constructor. If it does not have such a constructor, an exception will be thrown.

GetBestMatchingProperty ( string propertyName, Type type ) : PropertyInfo

Gets the best matching property info for the given name on the given type if the same property is defined on multiple levels in the object hierarchy.

GetPropertyInfo ( Type type, string propertyName ) : PropertyInfo

Obtains the PropertyInfo for the given propertyName of the given type from the cache. If it is not already in the cache, the PropertyInfo will be looked up and added to the cache.

GetPropertyInfoCache ( Type type ) : PropertyInfoCache

Returns the PropertyInfoCache for the given type. If there isn't one available already, a new one will be created.

GetPropertyNameString ( string propertyList, int level ) : string

Returns a string containing the properties in the propertyList up to the given level, separated by dots. For the propertyList { "Zero", "One", "Two" } and level 1, the string "Zero.One" will be returned.

GetTypeImpl ( Type targetType, string propertyName ) : Type

Returns the type of the given property on the target instance. The type and propertyName parameters can't be null.

GetValueImpl ( object target, string propertyName ) : object

Returns the value of the given property on the target instance. The target instance and propertyName parameters can't be null.

SetValueImpl ( object target, string propertyName, object value ) : void

Sets the given property of the target instance to the given value. Type mismatches in the parameters of these methods will result in an exception. Also, the target instance and propertyName parameters can't be null.

Method Details

GetType() public method

Gets the Type of the given property of the given targetType. The targetType and propertyName parameters can't be null.
public GetType ( Type targetType, string propertyName ) : Type
targetType System.Type the target type which contains the property
propertyName string the property to get, can be a property on a nested object (eg. "Child.Name")
return System.Type

GetValue() public method

Gets the value of the given property of the given target. If objects within the property hierarchy are null references, null will be returned. The target and propertyName parameters can't be null.
public GetValue ( object target, string propertyName ) : object
target object the target object to get the value from
propertyName string the property to get, can be a property on a nested object (eg. "Child.Name")
return object

SetValue() public method

public SetValue ( object target, string propertyName, object value ) : void
target object
propertyName string
value object the new value of the property
return void