Class ReflectionUtils

Collection of Reflection and type conversion related utility functions

System.Object
  Westwind.Utilities.ReflectionUtils
public static class ReflectionUtils : object

Class Members

MemberDescription

MemberAccess

Binding Flags constant to be reused for all Reflection access methods.

MemberAccessCom

CallMethod

Calls a method on an object dynamically. This version requires explicit specification of the parameter type signatures.

public static object CallMethod(object instance,     string method,     Type[] parameterTypes,     Object[] parms)

public static object CallMethod(object instance,     string method,     Object[] parms)

CallMethodCom

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

public static object CallMethodCom(object instance,     string method,     Object[] parms)

CallMethodEx

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

public static object CallMethodEx(object parent,     string method,     Object[] parms)

CallMethodExCom

Calls a method on a COM object with '.' syntax (Customer instance and Address.DoSomeThing method)

public static object CallMethodExCom(object parent,     string method,     Object[] parms)

CallStaticMethod

Invokes a static method

public static object CallStaticMethod(string typeName,     string method,     Object[] parms)

CreateComInstance

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

public static object CreateComInstance(string progId)

CreateInstanceFromString

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

public static object CreateInstanceFromString(string typeName,     Object[] args)

CreateInstanceFromType

Creates an instance from a type by calling the parameterless constructor.

public static object CreateInstanceFromType(Type typeToCreate,     Object[] args)

GetEnumList

Returns a List of KeyValuePair object

public static List<KeyValuePair`2> GetEnumList(Type enumType,     bool valueAsFieldValueNumber)

GetField

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

public static object GetField(object Object,     string Property)

GetProperty

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 object GetProperty(object instance,     string property)

GetPropertyCom

Retrieve a dynamic 'non-typelib' property

public static object GetPropertyCom(object instance,     string property)

GetPropertyEx

Returns a property or field value using a base object and sub members including . syntax. For example, you can access: 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 object GetPropertyEx(object Parent,     string Property)

GetPropertyExCom

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

public static object GetPropertyExCom(object parent,     string property)

GetPropertyInfoEx

Returns a PropertyInfo object for a given dynamically accessed property

public static PropertyInfo GetPropertyInfoEx(object Parent,     string Property)

GetPropertyInfoInternal

Returns a PropertyInfo structure from an extended Property reference

public static PropertyInfo GetPropertyInfoInternal(object Parent,     string Property)

GetStaticProperty

Retrieves a value from a static property by specifying a type full name and property

public static object GetStaticProperty(string typeName,     string property)

public static object GetStaticProperty(Type type,     string property)

GetTypeFromName

Helper routine that looks up a type name and tries to retrieve the full type reference using GetType() and if not found looking in the actively executing assemblies and optionally loading the specified assembly name.

public static Type GetTypeFromName(string typeName,     string assemblyName)

public static Type GetTypeFromName(string typeName)

InvokeEvent

Allows invoking an event from an external classes where direct access is not allowed (due to 'Can only assign to left hand side of operation')

public static void InvokeEvent(object instance,     string eventName,     Object[] parameters)

IsAnonoymousType

Determines whether a given type passed is anonymous

public static bool IsAnonoymousType(object objectOrType)

LoadAssembly

Try to load an assembly into the application's app domain. Loads by name first then checks for filename

public static Assembly LoadAssembly(string assemblyName)

SetField

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

public static void SetField(object obj,     string property,     object value)

SetProperty

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

public static void SetProperty(object obj,     string property,     object value)

SetPropertyCom

Sets the property on an object.

public static void SetPropertyCom(object inst,     string Property,     object Value)

SetPropertyEx

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

public static object SetPropertyEx(object parent,     string property,     object value)

SetPropertyExCom

Sets the value of a field or property via Reflection. This method alws for using '.' syntax to specify objects multiple levels down.

public static object SetPropertyExCom(object parent,     string property,     object value)

ShallowClone

Clones an object using a shallow cloning using private MemberwiseClone operation.

public static object ShallowClone(object source)

StringToTypedValue

Turns a string into a typed value generically. Explicitly assigns common types and falls back on using type converters for unhandled types.

public static object StringToTypedValue(string sourceString,     Type targetType,     CultureInfo culture)

StringToTypedValue

Generic version allow for automatic type conversion without the explicit type parameter

public static T StringToTypedValue(string sourceString,     CultureInfo culture)

TypedValueToString

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 string TypedValueToString(object rawValue,     CultureInfo culture,     string unsupportedReturn)

Requirements

Namespace: Westwind.Utilities
Assembly: westwind.utilities.dll

© West Wind Technologies, 1996-2024 • Updated: 06/29/24
Comment or report problem with topic