C# Class WebApplications.Utilities.Reflect.ExtendedType

Mostrar archivo Open project: webappsuk/CoreLibraries Class Usage Examples

Private Properties

Property Type Description
Get ExtendedType
Get ExtendedType
GetCastFromMethod CastMethod
GetCastToMethod CastMethod
LoadMembers void

Public Methods

Method Description
CanConvertTo ( Type type ) : bool

Determines whether this instance can be converted to the specified type. Unlike the built in cast system, this returns true if a cast is possible AND if IConvertible can be used.

CloseType ( ) : ExtendedType

Closes the type if it is generic and has generic parameters, or creates equivalent type.

DescendsFrom ( [ baseType ) : bool

Checks to see if a type descends from another type.

ExtendedType ( [ type ) : System

Initializes a new instance of the ExtendedType class.

FindType ( [ typeName, bool throwOnError = false, bool ignoreCase = false ) : Type

Finds the type with the specified typeName.

This is more robust than using Type.GetType(string,bool,bool) as it supports partial assembly names.

GetConstructor ( ) : Constructor

Gets the constructor.

GetConstructor ( [ constructorInfo, bool includeBase = true ) : Constructor

Gets the Constructor matching the ConstructorInfo (if any).

GetConstructor ( bool includeBase ) : Constructor

Gets the constructor.

GetConstructor ( bool &castsRequired, bool includeBase ) : Constructor

Gets the constructor.

GetEvent ( [ name, bool includeBase = true ) : Event

Gets the event.

GetField ( [ name, bool includeBase = true ) : Field

Gets the field.

GetIndexer ( ) : Indexer

Gets the indexer from the type (or base types).

GetIndexer ( [ propertyInfo, bool includeBase = true ) : Indexer

Gets the Indexer matching the PropertyInfo (if any).

GetIndexer ( bool &castsRequired ) : Indexer

Gets the indexer from the type (or base types).

GetIndexer ( bool includeBase, bool &castsRequired ) : Indexer

Gets the indexer.

GetMethod ( [ name ) : Method

Gets the method.

GetMethod ( [ methodInfo, bool includeBase = true ) : Method

Gets the Method matching the MethodInfo (if any).

GetMethod ( [ name, int genericArguments ) : Method

Gets the method.

GetMethod ( [ name, int genericArguments, bool includeBase ) : Method

Gets the method.

GetMethod ( [ name, int genericArguments, bool allowClosure, bool allowCasts ) : Method

Gets the method.

GetMethod ( [ name, int genericArguments, bool allowClosure, bool allowCasts, bool includeBase ) : Method

Gets the method.

GetMethod ( [ name, int genericArguments, bool allowClosure, bool allowCasts, bool &castsRequired, bool includeBase ) : Method

Gets the method.

GetMethods ( [ name, bool includeBase = true ) : IEnumerable

Gets the methods.

GetProperty ( [ name, bool includeBase = true ) : System.Property

Gets the property.

Implements ( [ interfaceType ) : bool

Checks to see if this type implements a particular interface.

ImplementsCastFrom ( [ fromType, bool implicitOnly = true ) : bool

Whether this type implements a cast from the specified type.

ImplementsCastTo ( [ toType, bool implicitOnly = true ) : bool

Whether this type implements a cast to the specified type.

TryConvert ( [ expression, [ outputExpression ) : bool

Converts the specified expression to the output type.

This version is more powerful than the Expression.Convert CLR method in that it supports ToString() conversion, IConvertible and TypeConverters. It also prevents exceptions being thrown.

Private Methods

Method Description
Get ( [ type ) : ExtendedType
Get ( [ typeName, bool ignoreCase = false ) : ExtendedType
GetCastFromMethod ( [ fromType ) : CastMethod
GetCastToMethod ( [ toType ) : CastMethod
LoadMembers ( ) : void

Loads all the members in one go.

Method Details

CanConvertTo() public method

Determines whether this instance can be converted to the specified type. Unlike the built in cast system, this returns true if a cast is possible AND if IConvertible can be used.
public CanConvertTo ( Type type ) : bool
type System.Type The type.
return bool

CloseType() public method

Closes the type if it is generic and has generic parameters, or creates equivalent type.
public CloseType ( ) : ExtendedType
return ExtendedType

DescendsFrom() public method

Checks to see if a type descends from another type.
public DescendsFrom ( [ baseType ) : bool
baseType [ Type of the base.
return bool

ExtendedType() public method

Initializes a new instance of the ExtendedType class.
public ExtendedType ( [ type ) : System
type [ The type.
return System

FindType() public static method

Finds the type with the specified typeName.
This is more robust than using Type.GetType(string,bool,bool) as it supports partial assembly names.
public static FindType ( [ typeName, bool throwOnError = false, bool ignoreCase = false ) : Type
typeName [ Name of the type.
throwOnError bool Throws an error if and not found.
ignoreCase bool Ignores the case if .
return System.Type

GetConstructor() public method

Gets the constructor.
public GetConstructor ( ) : Constructor
return Constructor

GetConstructor() public method

Gets the Constructor matching the ConstructorInfo (if any).
public GetConstructor ( [ constructorInfo, bool includeBase = true ) : Constructor
constructorInfo [ The constructor info.
includeBase bool if set to includes constructors from the base type.
return Constructor

GetConstructor() public method

Gets the constructor.
public GetConstructor ( bool includeBase ) : Constructor
includeBase bool if set to includes constructors from the base type.
return Constructor

GetConstructor() public method

Gets the constructor.
public GetConstructor ( bool &castsRequired, bool includeBase ) : Constructor
castsRequired bool Any array indicating which parameters require a cast (the last element is for the return type).
includeBase bool if set to includes constructors from the base type.
return Constructor

GetEvent() public method

Gets the event.
public GetEvent ( [ name, bool includeBase = true ) : Event
name [ The name.
includeBase bool if set to includes events from the base type.
return Event

GetField() public method

Gets the field.
public GetField ( [ name, bool includeBase = true ) : Field
name [ The name.
includeBase bool if set to includes fields from the base type.
return Field

GetIndexer() public method

Gets the indexer from the type (or base types).
public GetIndexer ( ) : Indexer
return Indexer

GetIndexer() public method

Gets the Indexer matching the PropertyInfo (if any).
public GetIndexer ( [ propertyInfo, bool includeBase = true ) : Indexer
propertyInfo [ The property info.
includeBase bool if set to includes indexers from the base type.
return Indexer

GetIndexer() public method

Gets the indexer from the type (or base types).
public GetIndexer ( bool &castsRequired ) : Indexer
castsRequired bool Any array indicating which parameters require a cast (the last element is for the return type).
return Indexer

GetIndexer() public method

Gets the indexer.
public GetIndexer ( bool includeBase, bool &castsRequired ) : Indexer
includeBase bool if set to includes indexers from the base type.
castsRequired bool Any array indicating which parameters require a cast (the last element is for the return type).
return Indexer

GetMethod() public method

Gets the method.
public GetMethod ( [ name ) : Method
name [ The name.
return Method

GetMethod() public method

Gets the Method matching the MethodInfo (if any).
public GetMethod ( [ methodInfo, bool includeBase = true ) : Method
methodInfo [ The method info.
includeBase bool if set to includes methods from the base type.
return Method

GetMethod() public method

Gets the method.
public GetMethod ( [ name, int genericArguments ) : Method
name [ The name.
genericArguments int The number of generic arguments.
return Method

GetMethod() public method

Gets the method.
public GetMethod ( [ name, int genericArguments, bool includeBase ) : Method
name [ The name.
genericArguments int The number of generic arguments.
includeBase bool if set to includes methods from the base type.
return Method

GetMethod() public method

Gets the method.
public GetMethod ( [ name, int genericArguments, bool allowClosure, bool allowCasts ) : Method
name [ The name.
genericArguments int The number of generic arguments.
allowClosure bool if set to will automatically close the signatures generic types if possible.
allowCasts bool if set to then types will match if they can be cast to the required type.
return Method

GetMethod() public method

Gets the method.
public GetMethod ( [ name, int genericArguments, bool allowClosure, bool allowCasts, bool includeBase ) : Method
name [ The name.
genericArguments int The number of generic arguments.
allowClosure bool if set to will automatically close the signatures generic types if possible.
allowCasts bool if set to then types will match if they can be cast to the required type.
includeBase bool if set to includes methods from the base type.
return Method

GetMethod() public method

Gets the method.
public GetMethod ( [ name, int genericArguments, bool allowClosure, bool allowCasts, bool &castsRequired, bool includeBase ) : Method
name [ The name.
genericArguments int The number of generic arguments.
allowClosure bool if set to will automatically close the signatures generic types if possible.
allowCasts bool if set to then types will match if they can be cast to the required type.
castsRequired bool Any array indicating which parameters require a cast (the last element is for the return type).
includeBase bool if set to includes methods from the base type.
return Method

GetMethods() public method

Gets the methods.
public GetMethods ( [ name, bool includeBase = true ) : IEnumerable
name [ The name.
includeBase bool if set to includes methods from the base type.
return IEnumerable

GetProperty() public method

Gets the property.
public GetProperty ( [ name, bool includeBase = true ) : System.Property
name [ The name.
includeBase bool if set to includes properties from the base type.
return System.Property

Implements() public method

Checks to see if this type implements a particular interface.
public Implements ( [ interfaceType ) : bool
interfaceType [ Type of the interface.
return bool

ImplementsCastFrom() public method

Whether this type implements a cast from the specified type.
public ImplementsCastFrom ( [ fromType, bool implicitOnly = true ) : bool
fromType [ The type to cast from.
implicitOnly bool If set to only allows implicit casts.
return bool

ImplementsCastTo() public method

Whether this type implements a cast to the specified type.
public ImplementsCastTo ( [ toType, bool implicitOnly = true ) : bool
toType [ The type to cast to.
implicitOnly bool If set to only allows implicit casts.
return bool

TryConvert() public method

Converts the specified expression to the output type.
This version is more powerful than the Expression.Convert CLR method in that it supports ToString() conversion, IConvertible and TypeConverters. It also prevents exceptions being thrown.
public TryConvert ( [ expression, [ outputExpression ) : bool
expression [ The expression.
outputExpression [ The output expression.
return bool