C# Класс OpenSlx.Lib.Utility.ReflectionHelper

Collection of small useful utility methods for dealing with common reflection problems.
Показать файл Открыть проект

Открытые методы

Метод Описание
BuildObjectValue ( object value, Type destinationType, string paramName ) : object

Convert the specified value to destinationType.

FindPropertyOnEntity ( Type entityType, String propertyName, ICacheService cacheProvider ) : PropertyInfo

Locate a property (will throw error if prop not available!) Cache the property info. Does not handle recursive path (Account.Address.City...) - use the higher level GetPropertyValue / SetPropertyValue for that.

FindPropertyOnEntity ( Type entityType, String propertyName, ICacheService cacheProvider, bool ignoreCase ) : PropertyInfo

Locate a property (will throw error if prop not available!) Cache the property info. Does not handle recursive path (Account.Address.City...)

GetFieldValue ( object instance, String fieldName, ICacheService cache ) : object

Convenience function to retrieve the value of a field. An exception will be thrown if it cannot be located.

GetPropertyValue ( object instance, String propertyPathString, ICacheService cacheProvider ) : object

Retrieve a property value.

SetPropertyValue ( object instance, String propertyPathString, object value, ICacheService cacheProvider ) : void

Set a value on the specified object. If the specified property is not found then this call will be ignored.

Приватные методы

Метод Описание
ConvertType ( object value, Type type ) : object

Attempt to automatically convert a string to a specified type.

FindField ( Type t, String fieldName ) : FieldInfo

Attempt to locate a field on the specified type. Unlike Type.GetField, this will crawl up the hierarchy to try and locate a private field on a base class, if needed. For this reason this method can be resource intensive and the result should be cached.

GetPropertyPath ( Type t, String propertyPathString, ICacheService cacheProvider ) : IPropertyPath

Retrieve property path info. Throw error if unavailable. This only examines public instance properties.

GetStaticType ( Type t ) : Type

If t is a dynamic type, this will return the first static ancestor. If t is already a static type, this will return t.

Описание методов

BuildObjectValue() публичный статический Метод

Convert the specified value to destinationType.
public static BuildObjectValue ( object value, Type destinationType, string paramName ) : object
value object
destinationType System.Type
paramName string Name used for reporting
Результат object

FindPropertyOnEntity() публичный статический Метод

Locate a property (will throw error if prop not available!) Cache the property info. Does not handle recursive path (Account.Address.City...) - use the higher level GetPropertyValue / SetPropertyValue for that.
Property can't be found
public static FindPropertyOnEntity ( Type entityType, String propertyName, ICacheService cacheProvider ) : PropertyInfo
entityType System.Type
propertyName String
cacheProvider ICacheService If not null, it will be used to cache the reflection info
Результат System.Reflection.PropertyInfo

FindPropertyOnEntity() публичный статический Метод

Locate a property (will throw error if prop not available!) Cache the property info. Does not handle recursive path (Account.Address.City...)
Property can't be found
public static FindPropertyOnEntity ( Type entityType, String propertyName, ICacheService cacheProvider, bool ignoreCase ) : PropertyInfo
entityType System.Type
propertyName String
cacheProvider ICacheService If not null, it will be used to cache the reflection info
ignoreCase bool
Результат System.Reflection.PropertyInfo

GetFieldValue() публичный статический Метод

Convenience function to retrieve the value of a field. An exception will be thrown if it cannot be located.
public static GetFieldValue ( object instance, String fieldName, ICacheService cache ) : object
instance object
fieldName String Name of the field on the instance (the field must be on the instance itself - not a subproperty)
cache ICacheService
Результат object

GetPropertyValue() публичный статический Метод

Retrieve a property value.
Property can't be found
public static GetPropertyValue ( object instance, String propertyPathString, ICacheService cacheProvider ) : object
instance object
propertyPathString String Path to property to set, separated by periods if setting a subproperty (Account.Address.City)
cacheProvider ICacheService Used to cache the propertyinfo information. May be null to skip cache.
Результат object

SetPropertyValue() публичный статический Метод

Set a value on the specified object. If the specified property is not found then this call will be ignored.
public static SetPropertyValue ( object instance, String propertyPathString, object value, ICacheService cacheProvider ) : void
instance object Instance the value will be set on
propertyPathString String Path to property. Subproperties may be separated by periods (Account.Address.City).
value object Value to be set
cacheProvider ICacheService Used to cache the propertyinfo information. May be null to skip cache.
Результат void