Class TypeUtility
This utility class is designed to make System.Type operations easier to work with.
Inheritance
Namespace: Cuemon
Assembly: Cuemon.Core.dll
Syntax
public static class TypeUtility
Methods
| Improve this DocContainsAttributeType(Object, Boolean, Type[])
Determines whether the specified source object contains one or more of the specified attribute target types.
Declaration
public static bool ContainsAttributeType(object source, bool inherit, params Type[] targets)
Parameters
Type | Name | Description |
---|---|---|
System.Object | source | The source object to match against. |
System.Boolean | inherit |
|
System.Type[] | targets | The attribute target types to be matched against. |
Returns
Type | Description |
---|---|
System.Boolean |
|
ContainsAttributeType(Object, Type[])
Determines whether the specified source object contains one or more of the specified attribute target types.
Declaration
public static bool ContainsAttributeType(object source, params Type[] targets)
Parameters
Type | Name | Description |
---|---|---|
System.Object | source | The source object to match against. |
System.Type[] | targets | The attribute target types to be matched against. |
Returns
Type | Description |
---|---|
System.Boolean |
|
ContainsAttributeType(MemberInfo, Boolean, Type[])
Determines whether the specified source type contains one or more of the specified attribute target types.
Declaration
public static bool ContainsAttributeType(MemberInfo source, bool inherit, params Type[] targets)
Parameters
Type | Name | Description |
---|---|---|
System.Reflection.MemberInfo | source | The member to match against. |
System.Boolean | inherit |
|
System.Type[] | targets | The attribute target types to be matched against. |
Returns
Type | Description |
---|---|
System.Boolean |
|
ContainsAttributeType(MemberInfo, Type[])
Determines whether the specified source type contains one or more of the specified attribute target types.
Declaration
public static bool ContainsAttributeType(MemberInfo source, params Type[] targets)
Parameters
Type | Name | Description |
---|---|---|
System.Reflection.MemberInfo | source | The member to match against. |
System.Type[] | targets | The attribute target types to be matched against. |
Returns
Type | Description |
---|---|
System.Boolean |
|
ContainsAttributeType(Type, Boolean, Type[])
Determines whether the specified source type contains one or more of the specified attribute target types.
Declaration
public static bool ContainsAttributeType(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 |
|
ContainsAttributeType(Type, Type[])
Determines whether the specified source type contains one or more of the specified attribute target types.
Declaration
public static bool ContainsAttributeType(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 |
|
ContainsInterface(Object, Boolean, Type[])
Determines whether the specified source contains one or more of the target types specified.
Declaration
public static bool ContainsInterface(object source, bool inherit, params Type[] targets)
Parameters
Type | Name | Description |
---|---|---|
System.Object | source | The source object 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 |
|
ContainsInterface(Object, 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 ContainsInterface(object source, params Type[] targets)
Parameters
Type | Name | Description |
---|---|---|
System.Object | source | The source object to match against. |
System.Type[] | targets | The target interface types to be matched against. |
Returns
Type | Description |
---|---|
System.Boolean |
|
ContainsInterface(Type, Boolean, Type[])
Determines whether the specified source contains one or more of the target types specified.
Declaration
public static bool ContainsInterface(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 |
|
ContainsInterface(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 ContainsInterface(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 |
|
ContainsType(Object, Boolean, Type[])
Determines whether the specified source/collection of source object(s) contains one or more of the specified target types.
Declaration
public static bool ContainsType(object source, bool treatSourceAsEnumerable, params Type[] targets)
Parameters
Type | Name | Description |
---|---|---|
System.Object | source | The source object to match against. |
System.Boolean | treatSourceAsEnumerable | if set to |
System.Type[] | targets | The target types to be matched against. |
Returns
Type | Description |
---|---|
System.Boolean |
|
ContainsType(Object, Type[])
Determines whether the specified source contains one or more of the specified target types.
Declaration
public static bool ContainsType(object source, params Type[] targets)
Parameters
Type | Name | Description |
---|---|---|
System.Object | source | The source object to match against. |
System.Type[] | targets | The target types to be matched against. |
Returns
Type | Description |
---|---|
System.Boolean |
|
ContainsType(Type, Type[])
Determines whether the specified source type contains one or more of the specified target types.
Declaration
public static bool ContainsType(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 |
|
GetAncestorAndDescendantsOrSelfTypes(Type)
Gets a sorted (base-to-derived) sequence of ancestor-and-descendant-or-self types from the source
.
Declaration
public static IEnumerable<Type> GetAncestorAndDescendantsOrSelfTypes(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 |
GetAncestorAndDescendantsOrSelfTypes(Type, Assembly[])
Gets a sorted (base-to-derived) sequence of ancestor-and-descendant-or-self types from the source
.
Declaration
public static IEnumerable<Type> GetAncestorAndDescendantsOrSelfTypes(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 |
GetAncestorOrSelf(Type, Type)
Gets the ancestor-or-self System.Type from the specified source
.
Declaration
public static Type GetAncestorOrSelf(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 |
|
GetAncestorOrSelfTypes(Type)
Gets a sequence of ancestor-or-self types from the source
.
Declaration
public static IEnumerable<Type> GetAncestorOrSelfTypes(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 |
GetDefaultValue(Type)
Gets the default value of the specified type
.
Declaration
public static object GetDefaultValue(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 |
GetDescendantOrSelfTypes(Type)
Gets a sequence of derived types from the source
an it's associated System.Reflection.Assembly.
Declaration
public static IEnumerable<Type> GetDescendantOrSelfTypes(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 |
GetDescendantOrSelfTypes(Type, Assembly[])
Gets a sequence of derived types from the source
.
Declaration
public static IEnumerable<Type> GetDescendantOrSelfTypes(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 |
Is<T>(Object)
Determines whether the specified source
is of T
.
Declaration
public static bool Is<T>(object source)
Parameters
Type | Name | Description |
---|---|---|
System.Object | source | The object to compare with |
Returns
Type | Description |
---|---|
System.Boolean |
|
Type Parameters
Name | Description |
---|---|
T | The type to compare with |
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(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(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(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 sources
, as a whole, is determined a complex System.Type.
Declaration
public static bool IsComplex(params Type[] sources)
Parameters
Type | Name | Description |
---|---|---|
System.Type[] | sources | The System.Type (or types) 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(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(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(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(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 |
|
IsNot<T>(Object)
Determines whether the specified source
is not of T
.
Declaration
public static bool IsNot<T>(object source)
Parameters
Type | Name | Description |
---|---|---|
System.Object | source | The object to compare with |
Returns
Type | Description |
---|---|
System.Boolean |
|
Type Parameters
Name | Description |
---|---|
T | The type to compare with |
IsNullable(Type)
Determines whether the specified source is a nullable System.ValueType.
Declaration
public static bool IsNullable(Type source)
Parameters
Type | Name | Description |
---|---|---|
System.Type | source | The source type to check for nullable System.ValueType. |
Returns
Type | Description |
---|---|
System.Boolean |
|
IsNullable<T>(T)
Determines whether the specified source is a nullable System.ValueType.
Declaration
public static bool IsNullable<T>(T source)
Parameters
Type | Name | Description |
---|---|---|
T | source | The source type to check for nullable System.ValueType. |
Returns
Type | Description |
---|---|
System.Boolean |
|
Type Parameters
Name | Description |
---|---|
T | The type of the |
IsNullable<T>(Nullable<T>)
Determines whether the specified source is a nullable System.ValueType.
Declaration
public static bool IsNullable<T>(T? source)
where T : struct
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<T> | source | The source type to check for nullable System.ValueType. |
Returns
Type | Description |
---|---|
System.Boolean |
|
Type Parameters
Name | Description |
---|---|
T | The type of the |
IsWithDefaultConstructor(Type)
Determines whether the specified source
has a default constructor.
Declaration
public static bool IsWithDefaultConstructor(Type source)
Parameters
Type | Name | Description |
---|---|---|
System.Type | source | The System.Type to determine is with default constructor. |
Returns
Type | Description |
---|---|
System.Boolean |
|
IsWithoutDefaultConstructor(Type)
Determines whether the specified source
does not have a default constructor.
Declaration
public static bool IsWithoutDefaultConstructor(Type source)
Parameters
Type | Name | Description |
---|---|---|
System.Type | source | The System.Type to determine is without a default constructor. |
Returns
Type | Description |
---|---|
System.Boolean |
|