C# Class ImageProcessor.Web.Extensions.TypeInferenceExtensions

Extensions methods for T:System.Type for inferring type properties. Most of this code was adapted from the Entity Framework
Exibir arquivo Open project: JimBobSquarePants/ImageProcessor

Public Methods

Method Description
GetBaseTypes ( this type ) : IEnumerable

Gets the base types that the given type inherits from

GetEnumerableType ( this type ) : Type

Gets the type of the enumerable object

GetGenericTypeImplementations ( this type, Type interfaceOrBaseType ) : IEnumerable

Determine if the given type implements the given generic interface or derives from the given generic type, and if so return the concrete types implemented.

IsCastableEnumerableType ( this type ) : bool

Determines whether the specified type is an enumerable type that is safe to cast following processing via a type converter. This should exclude T:string, T:Dictionary{,}

IsCollectionType ( this type ) : bool

Determines whether the specified type is a collection type.

IsEnumerableOfKeyValueType ( this type ) : bool

Determines whether the specified type is an enumerable type containing a key value pair as the generic type parameter. M:Enumerable.FirstOrDefault will throw an error when passed an T:IEnumerable{KeyValuePair{,}} this includes T:Dictionary{,}.

IsEnumerableOfType ( this type, Type typeArgument ) : bool

Determines whether the specified type is an enumerable of the given argument type.

IsEnumerableType ( this type ) : bool

Determines whether the specified type is an enumerable type.

TryGetElementType ( this type, Type interfaceOrBaseType ) : Type

Determine if the given type implements the given generic interface or derives from the given generic type, and if so return the element type of the collection. If the type implements the generic interface several times null will be returned.

Method Details

GetBaseTypes() public static method

Gets the base types that the given type inherits from
public static GetBaseTypes ( this type ) : IEnumerable
type this The to get the base types from.
return IEnumerable

GetEnumerableType() public static method

Gets the type of the enumerable object
public static GetEnumerableType ( this type ) : Type
type this The to check.
return System.Type

GetGenericTypeImplementations() public static method

Determine if the given type implements the given generic interface or derives from the given generic type, and if so return the concrete types implemented.
public static GetGenericTypeImplementations ( this type, Type interfaceOrBaseType ) : IEnumerable
type this The type to examine.
interfaceOrBaseType System.Type The generic type to be queried for.
return IEnumerable

IsCastableEnumerableType() public static method

Determines whether the specified type is an enumerable type that is safe to cast following processing via a type converter. This should exclude T:string, T:Dictionary{,}
public static IsCastableEnumerableType ( this type ) : bool
type this The type.
return bool

IsCollectionType() public static method

Determines whether the specified type is a collection type.
public static IsCollectionType ( this type ) : bool
type this The type.
return bool

IsEnumerableOfKeyValueType() public static method

Determines whether the specified type is an enumerable type containing a key value pair as the generic type parameter. M:Enumerable.FirstOrDefault will throw an error when passed an T:IEnumerable{KeyValuePair{,}} this includes T:Dictionary{,}.
public static IsEnumerableOfKeyValueType ( this type ) : bool
type this The type.
return bool

IsEnumerableOfType() public static method

Determines whether the specified type is an enumerable of the given argument type.
public static IsEnumerableOfType ( this type, Type typeArgument ) : bool
type this The type.
typeArgument System.Type The generic type argument.
return bool

IsEnumerableType() public static method

Determines whether the specified type is an enumerable type.
public static IsEnumerableType ( this type ) : bool
type this The type.
return bool

TryGetElementType() public static method

Determine if the given type implements the given generic interface or derives from the given generic type, and if so return the element type of the collection. If the type implements the generic interface several times null will be returned.
public static TryGetElementType ( this type, Type interfaceOrBaseType ) : Type
type this The type to examine.
interfaceOrBaseType System.Type The generic type to be queried for.
return System.Type