C# Class Spring.Util.ObjectUtils

Helper methods with regard to objects, types, properties, etc.

Not intended to be used directly by applications.

ファイルを表示 Open project: spring-projects/spring-net Class Usage Examples

Public Properties

Property Type Description
EmptyObjects object[]

Public Methods

Method Description
EnumerateElementAtIndex ( IEnumerable enumerable, int index ) : object

Returns the element at the specified index using the supplied enumerable.

EnumerateElementAtIndex ( IEnumerator enumerator, int index ) : object

Returns the element at the specified index using the supplied enumerator.

EnumerateFirstElement ( IEnumerable enumerable ) : object

Returns the first element in the supplied enumerable.

EnumerateFirstElement ( IEnumerator enumerator ) : object

Returns the first element in the supplied enumerator.

GetIdentityHexString ( object obj ) : string

Gets a hex String form of an object's identity hash code.

GetQualifiedMethodName ( MethodInfo method ) : string

Gets the qualified name of the given method, consisting of fully qualified interface/class name + "." method name.

GetZeroArgConstructorInfo ( Type type ) : ConstructorInfo

Gets the zero arg ConstructorInfo object, if the type offers such functionality.

IdentityToString ( object obj ) : object

Return a String representation of an object's overall identity.

InstantiateType ( Assembly assembly, string typeName ) : object

Instantiates the type using the assembly specified to load the type.

This is a convenience in the case of needing to instantiate a type but not wanting to specify in the string the version, culture and public key token.

InstantiateType ( ConstructorInfo constructor, object arguments ) : object

Convenience method to instantiate a System.Type using the given constructor.

As this method doesn't try to instantiate System.Types by name, it should avoid System.Type loading issues.

InstantiateType ( Type type ) : object

Convenience method to instantiate a System.Type using its no-arg constructor.

As this method doesn't try to instantiate System.Types by name, it should avoid System.Type loading issues.

IsAssignable ( Type type, object obj ) : bool

Determine if the given System.Type is assignable from the given value, assuming setting by reflection and taking care of transparent proxies.

Considers primitive wrapper classes as assignable to the corresponding primitive types.

For example used in an object factory's constructor resolution.

IsAssignableAndNotTransparentProxy ( Type type, object instance ) : bool

Checks whether the supplied instance is not a transparent proxy and is assignable to the supplied type.

Neccessary when dealing with server-activated remote objects, because the object is of the type TransparentProxy and regular is testing for assignable types does not work.

Transparent proxy instances always return when tested with the 'is' operator (C#). This method only checks if the object is assignable to the type if it is not a transparent proxy.

IsEmpty ( object array ) : bool

Determines whether the specified array is null or empty.

IsInstantiable ( Type type ) : void

Determines whether the specified type is instantiable, i.e. not an interface, abstract class or contains open generic type parameters.

IsPrimitiveArray ( Type type ) : bool

Check if the given class represents a primitive array, i.e. boolean, byte, char, short, int, long, float, or double.

IsSimpleProperty ( Type type ) : bool

Check if the given System.Type represents a "simple" property, i.e. a primitive, a System.String, a System.Type, or a corresponding array.

Used to determine properties to check for a "simple" dependency-check.

NullSafeEquals ( object o1, object o2 ) : bool

Determine if the given objects are equal, returning if both are respectively if only one is .

NullSafeHashCode ( object o1 ) : int

Return as hash code for the given object; typically the value of {@link Object#hashCode()}. If the object is an array, this method will delegate to any of the nullSafeHashCode methods for arrays in this class. If the object is null, this method returns 0.

Private Methods

Method Description
ObjectUtils ( ) : System

Method Details

EnumerateElementAtIndex() public static method

Returns the element at the specified index using the supplied enumerable.
/// If the supplied was less than zero, or the /// supplied did not contain enough elements /// to be able to reach the supplied . /// /// If the supplied is . ///
public static EnumerateElementAtIndex ( IEnumerable enumerable, int index ) : object
enumerable IEnumerable /// The to use to enumerate /// elements until the supplied is reached. ///
index int /// The index of the element in the enumeration to return. ///
return object

EnumerateElementAtIndex() public static method

Returns the element at the specified index using the supplied enumerator.
/// If the supplied was less than zero, or the /// supplied did not contain enough elements /// to be able to reach the supplied . ///
public static EnumerateElementAtIndex ( IEnumerator enumerator, int index ) : object
enumerator IEnumerator /// The to use to enumerate /// elements until the supplied is reached. ///
index int /// The index of the element in the enumeration to return. ///
return object

EnumerateFirstElement() public static method

Returns the first element in the supplied enumerable.
/// If the supplied did not have any elements. /// /// If the supplied is . ///
public static EnumerateFirstElement ( IEnumerable enumerable ) : object
enumerable IEnumerable /// The to use to enumerate /// elements. ///
return object

EnumerateFirstElement() public static method

Returns the first element in the supplied enumerator.
/// If the supplied did not have any elements. ///
public static EnumerateFirstElement ( IEnumerator enumerator ) : object
enumerator IEnumerator /// The to use to enumerate /// elements. ///
return object

GetIdentityHexString() public static method

Gets a hex String form of an object's identity hash code.
public static GetIdentityHexString ( object obj ) : string
obj object The obj.
return string

GetQualifiedMethodName() public static method

Gets the qualified name of the given method, consisting of fully qualified interface/class name + "." method name.
public static GetQualifiedMethodName ( MethodInfo method ) : string
method MethodInfo The method.
return string

GetZeroArgConstructorInfo() public static method

Gets the zero arg ConstructorInfo object, if the type offers such functionality.
/// If the type is an interface, abstract, open generic type, or does not have a zero-arg constructor. ///
public static GetZeroArgConstructorInfo ( Type type ) : ConstructorInfo
type System.Type The type.
return System.Reflection.ConstructorInfo

IdentityToString() public static method

Return a String representation of an object's overall identity.
public static IdentityToString ( object obj ) : object
obj object The object (may be null).
return object

InstantiateType() public static method

Instantiates the type using the assembly specified to load the type.
This is a convenience in the case of needing to instantiate a type but not wanting to specify in the string the version, culture and public key token.
/// If the or is /// /// If cannot load the type from the assembly or the call to InstantiateType(Type) fails. ///
public static InstantiateType ( Assembly assembly, string typeName ) : object
assembly System.Reflection.Assembly The assembly.
typeName string Name of the type.
return object

InstantiateType() public static method

Convenience method to instantiate a System.Type using the given constructor.

As this method doesn't try to instantiate System.Types by name, it should avoid System.Type loading issues.

/// If the is /// /// If the 's declaring type is an abstract class, /// an interface, an open generic type or does not have a public no-argument constructor. ///
public static InstantiateType ( ConstructorInfo constructor, object arguments ) : object
constructor System.Reflection.ConstructorInfo /// The constructor to use for the instantiation. ///
arguments object /// The arguments to be passed to the constructor. ///
return object

InstantiateType() public static method

Convenience method to instantiate a System.Type using its no-arg constructor.

As this method doesn't try to instantiate System.Types by name, it should avoid System.Type loading issues.

/// If the is /// /// If the is an abstract class, an interface, /// an open generic type or does not have a public no-argument constructor. ///
public static InstantiateType ( Type type ) : object
type System.Type /// The to instantiate* ///
return object

IsAssignable() public static method

Determine if the given System.Type is assignable from the given value, assuming setting by reflection and taking care of transparent proxies.

Considers primitive wrapper classes as assignable to the corresponding primitive types.

For example used in an object factory's constructor resolution.

public static IsAssignable ( Type type, object obj ) : bool
type System.Type The target .
obj object The value that should be assigned to the type.
return bool

IsAssignableAndNotTransparentProxy() public static method

Checks whether the supplied instance is not a transparent proxy and is assignable to the supplied type.

Neccessary when dealing with server-activated remote objects, because the object is of the type TransparentProxy and regular is testing for assignable types does not work.

Transparent proxy instances always return when tested with the 'is' operator (C#). This method only checks if the object is assignable to the type if it is not a transparent proxy.

public static IsAssignableAndNotTransparentProxy ( Type type, object instance ) : bool
type System.Type The target to be checked.
instance object The value that should be assigned to the type.
return bool

IsEmpty() public static method

Determines whether the specified array is null or empty.
public static IsEmpty ( object array ) : bool
array object The array to check.
return bool

IsInstantiable() public static method

Determines whether the specified type is instantiable, i.e. not an interface, abstract class or contains open generic type parameters.
public static IsInstantiable ( Type type ) : void
type System.Type The type.
return void

IsPrimitiveArray() public static method

Check if the given class represents a primitive array, i.e. boolean, byte, char, short, int, long, float, or double.
public static IsPrimitiveArray ( Type type ) : bool
type System.Type
return bool

IsSimpleProperty() public static method

Check if the given System.Type represents a "simple" property, i.e. a primitive, a System.String, a System.Type, or a corresponding array.

Used to determine properties to check for a "simple" dependency-check.

public static IsSimpleProperty ( Type type ) : bool
type System.Type /// The to check. ///
return bool

NullSafeEquals() public static method

Determine if the given objects are equal, returning if both are respectively if only one is .
public static NullSafeEquals ( object o1, object o2 ) : bool
o1 object The first object to compare.
o2 object The second object to compare.
return bool

NullSafeHashCode() public static method

Return as hash code for the given object; typically the value of {@link Object#hashCode()}. If the object is an array, this method will delegate to any of the nullSafeHashCode methods for arrays in this class. If the object is null, this method returns 0.
public static NullSafeHashCode ( object o1 ) : int
o1 object
return int

Property Details

EmptyObjects public_oe static_oe property

An empty object array.
public static object[] EmptyObjects
return object[]