C# Class Westwind.Utilities.ReflectionUtils

Collection of Reflection and type conversion related utility functions
Mostra file Open project: RickStrahl/wwDotnetBridge Class Usage Examples

Public Methods

Method Description
CallMethod ( object instance, string method ) : object

Calls a method on an object dynamically.

CallMethodCom ( object instance, string method ) : object

Wrapper method to call a 'dynamic' (non-typelib) method on a COM object

CallMethodEx ( object parent, string method ) : object

Calls a method on an object with extended . syntax (object: this Method: Entity.CalculateOrderTotal)

CallStaticMethod ( string typeName, string method ) : object

Invokes a static method

CreateComInstance ( string progId ) : object

Creates a COM instance from a ProgID. Loads either Exe or DLL servers.

CreateInstanceFromString ( string typeName ) : object

Creates an instance of a type based on a string. Assumes that the type's

CreateInstanceFromType ( Type typeToCreate ) : object

Creates an instance from a type by calling the parameterless constructor. Note this will not work with COM objects - continue to use the Activator.CreateInstance for COM objects. Class wwUtils

GetField ( object Object, string Property ) : object

Retrieve a field dynamically from an object. This is a simple implementation that's straight Reflection and doesn't support indexers.

GetProperty ( object instance, string property ) : object

Retrieve a property value from an object dynamically. This is a simple version that uses Reflection calls directly. It doesn't support indexers.

GetPropertyCom ( object instance, string property ) : object

Retrieve a dynamic 'non-typelib' property

GetPropertyEx ( object Parent, string Property ) : object

Returns a property or field value using a base object and sub members including . syntax. For example, you can access: this.oCustomer.oData.Company with (this,"oCustomer.oData.Company") This method also supports indexers in the Property value such as: Customer.DataSet.Tables["Customers"].Rows[0]

GetPropertyExCom ( object parent, string property ) : object

Returns a property or field value using a base object and sub members including . syntax. For example, you can access: this.oCustomer.oData.Company with (this,"oCustomer.oData.Company")

GetTypeFromName ( string typeName ) : Type

Helper routine that looks up a type name and tries to retrieve the full type reference in the actively executing assemblies.

SetField ( object Object, string Property, object Value ) : void

Sets the field on an object. This is a simple method that uses straight Reflection and doesn't support indexers.

SetProperty ( object Object, string Property, object Value ) : void

Sets the property on an object. This is a simple method that uses straight Reflection and doesn't support indexers.

SetPropertyCom ( object Object, string Property, object Value ) : void

Sets the property on an object.

SetPropertyEx ( object parent, string property, object value ) : object

Sets a value on an object. Supports . syntax for named properties (ie. Customer.Entity.Company) as well as indexers.

SetPropertyExCom ( object parent, string property, object value ) : object

Sets the value of a field or property via Reflection. This method alws for using '.' syntax to specify objects multiple levels down. ReflectionUtils.SetPropertyEx(this,"Invoice.LineItemsCount",10) which would be equivalent of: this.Invoice.LineItemsCount = 10;

StringToTypedValue ( string sourceString, Type targetType ) : object

Turns a string into a typed value. Useful for auto-conversion routines like form variable or XML parsers.

StringToTypedValue ( string sourceString, Type targetType, CultureInfo culture ) : object

Turns a string into a typed value. Useful for auto-conversion routines like form variable or XML parsers. Class wwUtils

TypedValueToString ( object rawValue ) : string

Converts a type to string if possible. This method uses the current culture for numeric and DateTime values. It calls the ToString() method on common types and uses a type converter on all other objects if available.

TypedValueToString ( object rawValue, CultureInfo culture ) : string

Converts a type to string if possible. This method supports an optional culture generically on any value. It calls the ToString() method on common types and uses a type converter on all other objects if available

Private Methods

Method Description
GetPropertyInternal ( object Parent, string Property ) : object

Parses Properties and Fields including Array and Collection references. Used internally for the 'Ex' Reflection methods.

SetPropertyInternal ( object Parent, string Property, object Value ) : object

Parses Properties and Fields including Array and Collection references.

Method Details

CallMethod() public static method

Calls a method on an object dynamically.
public static CallMethod ( object instance, string method ) : object
instance object
method string
return object

CallMethodCom() public static method

Wrapper method to call a 'dynamic' (non-typelib) method on a COM object
public static CallMethodCom ( object instance, string method ) : object
instance object
method string
return object

CallMethodEx() public static method

Calls a method on an object with extended . syntax (object: this Method: Entity.CalculateOrderTotal)
public static CallMethodEx ( object parent, string method ) : object
parent object
method string
return object

CallStaticMethod() public static method

Invokes a static method
public static CallStaticMethod ( string typeName, string method ) : object
typeName string
method string
return object

CreateComInstance() public static method

Creates a COM instance from a ProgID. Loads either Exe or DLL servers.
public static CreateComInstance ( string progId ) : object
progId string
return object

CreateInstanceFromString() public static method

Creates an instance of a type based on a string. Assumes that the type's
public static CreateInstanceFromString ( string typeName ) : object
typeName string
return object

CreateInstanceFromType() public static method

Creates an instance from a type by calling the parameterless constructor. Note this will not work with COM objects - continue to use the Activator.CreateInstance for COM objects. Class wwUtils
public static CreateInstanceFromType ( Type typeToCreate ) : object
typeToCreate System.Type /// The type from which to create an instance. ///
return object

GetField() public static method

Retrieve a field dynamically from an object. This is a simple implementation that's straight Reflection and doesn't support indexers.
public static GetField ( object Object, string Property ) : object
Object object Object to retreve Field from
Property string name of the field to retrieve
return object

GetProperty() public static method

Retrieve a property value from an object dynamically. This is a simple version that uses Reflection calls directly. It doesn't support indexers.
public static GetProperty ( object instance, string property ) : object
instance object Object to make the call on
property string Property to retrieve
return object

GetPropertyCom() public static method

Retrieve a dynamic 'non-typelib' property
public static GetPropertyCom ( object instance, string property ) : object
instance object Object to make the call on
property string Property to retrieve
return object

GetPropertyEx() public static method

Returns a property or field value using a base object and sub members including . syntax. For example, you can access: this.oCustomer.oData.Company with (this,"oCustomer.oData.Company") This method also supports indexers in the Property value such as: Customer.DataSet.Tables["Customers"].Rows[0]
public static GetPropertyEx ( object Parent, string Property ) : object
Parent object Parent object to 'start' parsing from. Typically this will be the Page.
Property string The property to retrieve. Example: 'Customer.Entity.Company'
return object

GetPropertyExCom() public static method

Returns a property or field value using a base object and sub members including . syntax. For example, you can access: this.oCustomer.oData.Company with (this,"oCustomer.oData.Company")
public static GetPropertyExCom ( object parent, string property ) : object
parent object Parent object to 'start' parsing from.
property string The property to retrieve. Example: 'oBus.oData.Company'
return object

GetTypeFromName() public static method

Helper routine that looks up a type name and tries to retrieve the full type reference in the actively executing assemblies.
public static GetTypeFromName ( string typeName ) : Type
typeName string
return System.Type

SetField() public static method

Sets the field on an object. This is a simple method that uses straight Reflection and doesn't support indexers.
public static SetField ( object Object, string Property, object Value ) : void
Object object Object to set property on
Property string Name of the field to set
Value object value to set it to
return void

SetProperty() public static method

Sets the property on an object. This is a simple method that uses straight Reflection and doesn't support indexers.
public static SetProperty ( object Object, string Property, object Value ) : void
Object object Object to set property on
Property string Name of the property to set
Value object value to set it to
return void

SetPropertyCom() public static method

Sets the property on an object.
public static SetPropertyCom ( object Object, string Property, object Value ) : void
Object object Object to set property on
Property string Name of the property to set
Value object value to set it to
return void

SetPropertyEx() public static method

Sets a value on an object. Supports . syntax for named properties (ie. Customer.Entity.Company) as well as indexers.
public static SetPropertyEx ( object parent, string property, object value ) : object
parent object
property string
value object
return object

SetPropertyExCom() public static method

Sets the value of a field or property via Reflection. This method alws for using '.' syntax to specify objects multiple levels down. ReflectionUtils.SetPropertyEx(this,"Invoice.LineItemsCount",10) which would be equivalent of: this.Invoice.LineItemsCount = 10;
public static SetPropertyExCom ( object parent, string property, object value ) : object
parent object
property string
value object
return object

StringToTypedValue() public static method

Turns a string into a typed value. Useful for auto-conversion routines like form variable or XML parsers.
public static StringToTypedValue ( string sourceString, Type targetType ) : object
sourceString string The input string to convert
targetType System.Type The Type to convert it to
return object

StringToTypedValue() public static method

Turns a string into a typed value. Useful for auto-conversion routines like form variable or XML parsers. Class wwUtils
public static StringToTypedValue ( string sourceString, Type targetType, CultureInfo culture ) : object
sourceString string /// The string to convert from ///
targetType System.Type /// The type to convert to ///
culture System.Globalization.CultureInfo /// Culture used for numeric and datetime values. ///
return object

TypedValueToString() public static method

Converts a type to string if possible. This method uses the current culture for numeric and DateTime values. It calls the ToString() method on common types and uses a type converter on all other objects if available.
public static TypedValueToString ( object rawValue ) : string
rawValue object The Value or Object to convert to a string
return string

TypedValueToString() public static method

Converts a type to string if possible. This method supports an optional culture generically on any value. It calls the ToString() method on common types and uses a type converter on all other objects if available
public static TypedValueToString ( object rawValue, CultureInfo culture ) : string
rawValue object The Value or Object to convert to a string
culture System.Globalization.CultureInfo Culture for numeric and DateTime values
return string