C# Class Rolcore.Reflection.ObjectExtensions

Extensions for Object.
显示文件 Open project: Rollins/Rolcore

Public Methods

Method Description
ChangeType ( this obj, Type toType ) : object

Use this instead of Convert.ChangeType to support Nullable<> types. Returns an Object with the specified Type of which the value is equivalent to the specified object.

CopyMatchingObjectPropertiesTo ( this source, object dest, bool shallow = false ) : void

Copies value type properties with matching names and compatible types from the current instance to the specified destination, even if the source and destination are not in the same inheritance family. Incompatible and missing properties are ignored. If both the source and the destination have a complex property, the method will recurse if shallow is false.

GetPropertiesWithAttribute ( this obj, Type attributeType, bool inherit ) : System.Reflection.PropertyInfo[]
GetPropertyValue ( this obj, string propertyName ) : object

Gets the value of a property of a given object.

IsNullableType ( this obj ) : bool

Determines if the given object is Nullable<>.

SetPropertyValue ( this obj, string propertyName, object propertyValue ) : void

Sets value of a property of a given object.

SetPropertyValues ( this obj, NameValueCollection propertyValues ) : void

Sets value of multiple properties of a given object.

Private Methods

Method Description
GetMethodsWithAttribute ( this obj, Type attributeType, bool inherit ) : System.Reflection.MethodInfo[]

Method Details

ChangeType() public static method

Use this instead of Convert.ChangeType to support Nullable<> types. Returns an Object with the specified Type of which the value is equivalent to the specified object.
public static ChangeType ( this obj, Type toType ) : object
obj this Specifies the object for which the type should change.
toType System.Type Specifies the type to change the specified object to.
return object

CopyMatchingObjectPropertiesTo() public static method

Copies value type properties with matching names and compatible types from the current instance to the specified destination, even if the source and destination are not in the same inheritance family. Incompatible and missing properties are ignored. If both the source and the destination have a complex property, the method will recurse if shallow is false.
public static CopyMatchingObjectPropertiesTo ( this source, object dest, bool shallow = false ) : void
source this Specifies the source object to copy from.
dest object Specifies the destination object to copy to.
shallow bool Specifies if the copy should be shallow.
return void

GetPropertiesWithAttribute() public static method

public static GetPropertiesWithAttribute ( this obj, Type attributeType, bool inherit ) : System.Reflection.PropertyInfo[]
obj this
attributeType System.Type
inherit bool
return System.Reflection.PropertyInfo[]

GetPropertyValue() public static method

Gets the value of a property of a given object.
public static GetPropertyValue ( this obj, string propertyName ) : object
obj this Specifies the object from which to retrieve the property value.
propertyName string Specifies the name of the property to be returned. This /// value can be specified using "dot syntax", e.g. "FirstProperty.SecondProperty".
return object

IsNullableType() public static method

Determines if the given object is Nullable<>.
public static IsNullableType ( this obj ) : bool
obj this Specifies the object instance.
return bool

SetPropertyValue() public static method

Sets value of a property of a given object.
public static SetPropertyValue ( this obj, string propertyName, object propertyValue ) : void
obj this Specifies the object on which to act.
propertyName string Specifies the name of the property to be changed. This value /// can be specified using "dot syntax", e.g. "FirstProperty.SecondProperty".
propertyValue object Specifies the new value of the property.
return void

SetPropertyValues() public static method

Sets value of multiple properties of a given object.
public static SetPropertyValues ( this obj, NameValueCollection propertyValues ) : void
obj this Specifies the object on which to act.
propertyValues System.Collections.Specialized.NameValueCollection Specifies the names and values of the properties to set.
return void