Class TypeExtensions
Extension methods for the System.Type.
Inheritance
Namespace: Cuemon
Assembly: Cuemon.Core.dll
Syntax
public static class TypeExtensions
Methods
| Improve this DocGetAncestorsAndDescendantsAndSelf(Type)
Gets a sorted (base-to-derived) sequence of ancestor-and-descendant-or-self types from the source
.
Declaration
public static IEnumerable<Type> GetAncestorsAndDescendantsAndSelf(this Type source)
Parameters
Type | Name | Description |
---|---|---|
System.Type | source | The source type to locate ancestor-and-descendant-or-self types from. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.Type> | An System.Collections.Generic.IEnumerable<T> holding the ancestor-and-descendant-or-self types from the |
GetAncestorsAndDescendantsAndSelf(Type, Assembly[])
Gets a sorted (base-to-derived) sequence of ancestor-and-descendant-or-self types from the source
.
Declaration
public static IEnumerable<Type> GetAncestorsAndDescendantsAndSelf(this Type source, params Assembly[] assemblies)
Parameters
Type | Name | Description |
---|---|---|
System.Type | source | The source type to locate ancestor-and-descendant-or-self types from. |
System.Reflection.Assembly[] | assemblies | The assemblies to search for the |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.Type> | An System.Collections.Generic.IEnumerable<T> holding the ancestor-and-descendant-or-self types from the |
GetAncestorsAndSelf(Type)
Gets a sequence of ancestor-or-self types from the source
.
Declaration
public static IEnumerable<Type> GetAncestorsAndSelf(this Type source)
Parameters
Type | Name | Description |
---|---|---|
System.Type | source | The source type to locate ancestor-or-self types from. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.Type> | An System.Collections.Generic.IEnumerable<T> holding the ancestor-or-self types from the |
GetAncestorsAndSelf(Type, Type)
Gets the ancestor-or-self System.Type from the specified source
.
Declaration
public static Type GetAncestorsAndSelf(this Type source, Type sourceBaseLimit)
Parameters
Type | Name | Description |
---|---|---|
System.Type | source | The source type to traverse. |
System.Type | sourceBaseLimit | The base limit of |
Returns
Type | Description |
---|---|
System.Type | The ancestor-or-self type from the specified |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
GetDefaultValue(Type)
Gets the default value of the specified type
.
Declaration
public static object GetDefaultValue(this Type type)
Parameters
Type | Name | Description |
---|---|---|
System.Type | type | The System.Type to retrieve its default value from. |
Returns
Type | Description |
---|---|
System.Object | The default value of |
GetDescendantsAndSelf(Type)
Gets a sequence of derived types from the source
an it's associated System.Reflection.Assembly.
Declaration
public static IEnumerable<Type> GetDescendantsAndSelf(this Type source)
Parameters
Type | Name | Description |
---|---|---|
System.Type | source | The source type to locate derived types from. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.Type> | An System.Collections.Generic.IEnumerable<T> holding the derived types from the |
GetDescendantsAndSelf(Type, Assembly[])
Gets a sequence of derived types from the source
.
Declaration
public static IEnumerable<Type> GetDescendantsAndSelf(this Type source, params Assembly[] assemblies)
Parameters
Type | Name | Description |
---|---|---|
System.Type | source | The source type to locate derived types from. |
System.Reflection.Assembly[] | assemblies | The assemblies to search for the |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.Type> | An System.Collections.Generic.IEnumerable<T> holding the derived types from the |
GetRuntimePropertiesExceptOf<T>(Type)
Retrieves a collection that represents all the properties defined on a specified type
except those defined on T
.
Declaration
public static IEnumerable<PropertyInfo> GetRuntimePropertiesExceptOf<T>(this Type type)
Parameters
Type | Name | Description |
---|---|---|
System.Type | type | The type that contains the properties to include except those defined on |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.Reflection.PropertyInfo> | A collection of properties for the specified |
Type Parameters
Name | Description |
---|---|
T | The type to exclude properties on |
HasAttributes(Type, Boolean, Type[])
Determines whether the specified source type contains one or more of the specified attribute target types.
Declaration
public static bool HasAttributes(this Type source, bool inherit, params Type[] targets)
Parameters
Type | Name | Description |
---|---|---|
System.Type | source | The source type to match against. |
System.Boolean | inherit |
|
System.Type[] | targets | The attribute target types to be matched against. |
Returns
Type | Description |
---|---|
System.Boolean |
|
HasAttributes(Type, Type[])
Determines whether the specified source type contains one or more of the specified attribute target types.
Declaration
public static bool HasAttributes(this Type source, params Type[] targets)
Parameters
Type | Name | Description |
---|---|---|
System.Type | source | The source type to match against. |
System.Type[] | targets | The attribute target types to be matched against. |
Returns
Type | Description |
---|---|
System.Boolean |
|
HasInterfaces(Type, Boolean, Type[])
Determines whether the specified source contains one or more of the target types specified.
Declaration
public static bool HasInterfaces(this Type source, bool inherit, params Type[] targets)
Parameters
Type | Name | Description |
---|---|---|
System.Type | source | The source type to match against. |
System.Boolean | inherit | Specifies whether to search this member's inheritance chain to find the interfaces. |
System.Type[] | targets | The target interface types to be matched against. |
Returns
Type | Description |
---|---|
System.Boolean |
|
HasInterfaces(Type, Type[])
Determines whether the specified source contains one or more of the target types specified throughout this member's inheritance chain.
Declaration
public static bool HasInterfaces(this Type source, params Type[] targets)
Parameters
Type | Name | Description |
---|---|---|
System.Type | source | The source type to match against. |
System.Type[] | targets | The target interface types to be matched against. |
Returns
Type | Description |
---|---|
System.Boolean |
|
HasTypes(Type, Type[])
Determines whether the specified source type contains one or more of the specified target types.
Declaration
public static bool HasTypes(this Type source, params Type[] targets)
Parameters
Type | Name | Description |
---|---|---|
System.Type | source | The source type to match against. |
System.Type[] | targets | The target types to be matched against. |
Returns
Type | Description |
---|---|
System.Boolean |
|
IsAnonymousMethod(Type)
Determines whether the specified source
is an anonymous method (be that in a form of a delegate or lambda expression).
Declaration
public static bool IsAnonymousMethod(this Type source)
Parameters
Type | Name | Description |
---|---|---|
System.Type | source | The System.Type to determine is an anonymous method. |
Returns
Type | Description |
---|---|
System.Boolean |
|
IsComparable(Type)
Determines whether the specified source
implements either System.IComparable or System.IComparable<T>.
Declaration
public static bool IsComparable(this Type source)
Parameters
Type | Name | Description |
---|---|---|
System.Type | source | The source type to check for implements of either System.IComparable or System.IComparable<T>. |
Returns
Type | Description |
---|---|
System.Boolean |
|
IsComparer(Type)
Determines whether the specified source
implements either System.Collections.IComparer or System.Collections.Generic.IComparer<T>.
Declaration
public static bool IsComparer(this Type source)
Parameters
Type | Name | Description |
---|---|---|
System.Type | source | The source type to check for implements of either System.Collections.IComparer or System.Collections.Generic.IComparer<T>. |
Returns
Type | Description |
---|---|
System.Boolean |
|
IsComplex(Type)
Determines whether the specified source
is a complex System.Type.
Declaration
public static bool IsComplex(this Type source)
Parameters
Type | Name | Description |
---|---|---|
System.Type | source | The System.Type to determine complexity for. |
Returns
Type | Description |
---|---|
System.Boolean |
|
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
IsDictionary(Type)
Determines whether the specified source
implements either System.Collections.IDictionary, System.Collections.Generic.IDictionary<TKey, TValue> or System.Collections.Generic.IReadOnlyDictionary<TKey, TValue>.
Declaration
public static bool IsDictionary(this Type source)
Parameters
Type | Name | Description |
---|---|---|
System.Type | source | The source type to check for implements of either System.Collections.IDictionary, System.Collections.Generic.IDictionary<TKey, TValue> or System.Collections.Generic.IReadOnlyDictionary<TKey, TValue> |
Returns
Type | Description |
---|---|
System.Boolean |
|
IsEnumerable(Type)
Determines whether the specified source
implements either System.Collections.IEnumerable or System.Collections.Generic.IEnumerable<T>.
Declaration
public static bool IsEnumerable(this Type source)
Parameters
Type | Name | Description |
---|---|---|
System.Type | source | The source type to check for implements of either System.Collections.IEnumerable or System.Collections.Generic.IEnumerable<T>. |
Returns
Type | Description |
---|---|
System.Boolean |
|
IsEqualityComparer(Type)
Determines whether the specified source
implements either System.Collections.IEqualityComparer or System.Collections.Generic.IEqualityComparer<T>.
Declaration
public static bool IsEqualityComparer(this Type source)
Parameters
Type | Name | Description |
---|---|---|
System.Type | source | The source type to check for implements of either System.Collections.IEqualityComparer or System.Collections.Generic.IEqualityComparer<T>. |
Returns
Type | Description |
---|---|
System.Boolean |
|
IsKeyValuePair(Type)
Determines whether the specified source
implements either System.Collections.DictionaryEntry or System.Collections.Generic.KeyValuePair<TKey,TValue>.
Declaration
public static bool IsKeyValuePair(this Type source)
Parameters
Type | Name | Description |
---|---|---|
System.Type | source | The source type to check for implements of either System.Collections.DictionaryEntry or System.Collections.Generic.KeyValuePair<TKey,TValue>. |
Returns
Type | Description |
---|---|
System.Boolean |
|
IsNullable(Type)
Determines whether the specified source is a nullable System.ValueType.
Declaration
public static bool IsNullable(this Type source)
Parameters
Type | Name | Description |
---|---|---|
System.Type | source | The source type to check for nullable System.ValueType. |
Returns
Type | Description |
---|---|
System.Boolean |
|
IsSimple(Type)
Determines whether the specified source
is a simple System.Type.
Declaration
public static bool IsSimple(this Type source)
Parameters
Type | Name | Description |
---|---|---|
System.Type | source | The System.Type to determine complexity for. |
Returns
Type | Description |
---|---|
System.Boolean |
|
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
ToFullNameIncludingAssemblyName(Type)
Converts the System.Type to its equivalent string representation.
Declaration
public static string ToFullNameIncludingAssemblyName(this Type type)
Parameters
Type | Name | Description |
---|---|---|
System.Type | type | The System.Type to extend. |
Returns
Type | Description |
---|---|
System.String | A string that contains the fully qualified name of the type, including its namespace, comma delimited with the simple name of the assembly. |