C# Class Westwind.Utilities.ReflectionUtils

Collection of Reflection and type conversion related utility functions
Afficher le fichier Open project: RickStrahl/wwDotnetBridge Class Usage Examples

Méthodes publiques

Méthode 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

Méthode 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 méthode

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

CallMethodCom() public static méthode

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
Résultat object

CallMethodEx() public static méthode

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
Résultat object

CallStaticMethod() public static méthode

Invokes a static method
public static CallStaticMethod ( string typeName, string method ) : object
typeName string
method string
Résultat object

CreateComInstance() public static méthode

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

CreateInstanceFromString() public static méthode

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

CreateInstanceFromType() public static méthode

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. ///
Résultat object

GetField() public static méthode

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
Résultat object

GetProperty() public static méthode

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
Résultat object

GetPropertyCom() public static méthode

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
Résultat object

GetPropertyEx() public static méthode

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'
Résultat object

GetPropertyExCom() public static méthode

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'
Résultat object

GetTypeFromName() public static méthode

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
Résultat System.Type

SetField() public static méthode

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
Résultat void

SetProperty() public static méthode

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
Résultat void

SetPropertyCom() public static méthode

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
Résultat void

SetPropertyEx() public static méthode

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
Résultat object

SetPropertyExCom() public static méthode

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
Résultat object

StringToTypedValue() public static méthode

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
Résultat object

StringToTypedValue() public static méthode

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. ///
Résultat object

TypedValueToString() public static méthode

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
Résultat string

TypedValueToString() public static méthode

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
Résultat string