Table of Contents

Class TypeExtensions

Namespace
Cuemon.Extensions
Assembly
Cuemon.Extensions.Core.dll

Extension methods for the System.Type class.

public static class TypeExtensions
Inheritance
Object
TypeExtensions

Methods

GetDefaultValue(Type)

Gets the default value of the specified type.

public static object GetDefaultValue(this Type type)

Parameters

type Type

The System.Type to extend.

Returns

Object

The default value of type.

HasAnonymousCharacteristics(Type)

Determines whether the specified type suggest an anonymous implementation (be that in a form of a type, delegate or lambda expression).

public static bool HasAnonymousCharacteristics(this Type type)

Parameters

type Type

The System.Type to extend.

Returns

Boolean

true if the specified type suggest an anonymous implementation; otherwise, false.

Remarks

If you can avoid it, don't use this method. It is - to say the least - fragile.

Exceptions

System.ArgumentNullException

type cannot be null.

HasAttributes(Type, Type[])

Determines whether the specified type contains one or more of the specified attributeTypes.

public static bool HasAttributes(this Type type, params Type[] attributeTypes)

Parameters

type Type

The System.Type to extend.

attributeTypes Type[]

The attribute target types to be matched against.

Returns

Boolean

true if the specified type contains one or more of the specified attributeTypes; otherwise, false.

Exceptions

System.ArgumentNullException

type cannot be null -or- attributeTypes cannot be null.

HasComparableImplementation(Type)

Determines whether the specified type implements either System.IComparable or System.IComparable`1.

public static bool HasComparableImplementation(this Type type)

Parameters

type Type

The System.Type to extend.

Returns

Boolean

true if the specified type implements either System.IComparable or System.IComparable`1; otherwise, false.

Exceptions

System.ArgumentNullException

type cannot be null.

HasComparerImplementation(Type)

Determines whether the specified type implements either System.Collections.IComparer or System.Collections.Generic.IComparer<T>.

public static bool HasComparerImplementation(this Type type)

Parameters

type Type

The System.Type to extend.

Returns

Boolean

true if the specified type implements either System.Collections.IComparer or System.Collections.Generic.IComparer<T>; otherwise, false.

Exceptions

System.ArgumentNullException

type cannot be null.

HasDictionaryImplementation(Type)

Determines whether the specified type implements either System.Collections.IDictionary, System.Collections.Generic.IDictionary<TKey, TValue> or System.Collections.Generic.IReadOnlyDictionary<TKey, TValue>.

public static bool HasDictionaryImplementation(this Type type)

Parameters

type Type

The System.Type to extend.

Returns

Boolean

true if the specified type implements either System.Collections.IDictionary, System.Collections.Generic.IDictionary<TKey, TValue> or System.Collections.Generic.IReadOnlyDictionary<TKey, TValue>; otherwise, false.

Exceptions

System.ArgumentNullException

type cannot be null.

HasEnumerableImplementation(Type)

Determines whether the specified type implements either System.Collections.IEnumerable or System.Collections.Generic.IEnumerable<T>.

public static bool HasEnumerableImplementation(this Type type)

Parameters

type Type

The System.Type to extend.

Returns

Boolean

true if the specified type implements either System.Collections.IEnumerable or System.Collections.Generic.IEnumerable<T>; otherwise, false.

Exceptions

System.ArgumentNullException

type cannot be null.

HasEqualityComparerImplementation(Type)

Determines whether the specified type implements either System.Collections.IEqualityComparer or System.Collections.Generic.IEqualityComparer<T>.

public static bool HasEqualityComparerImplementation(this Type type)

Parameters

type Type

The System.Type to extend.

Returns

Boolean

true if the specified type implements either System.Collections.IEqualityComparer or System.Collections.Generic.IEqualityComparer<T>; otherwise, false.

Exceptions

System.ArgumentNullException

type cannot be null.

HasInterfaces(Type, Type[])

Determines whether the specified type contains one or more of the target interfaces specified throughout this member's inheritance chain.

public static bool HasInterfaces(this Type type, params Type[] interfaceTypes)

Parameters

type Type

The System.Type to extend.

interfaceTypes Type[]

The target interface types to be matched against.

Returns

Boolean

true if the specified type contains one or more of the target types specified throughout this member's inheritance chain; otherwise, false.

Exceptions

System.ArgumentNullException

type cannot be null -or- interfaceTypes cannot be null.

HasKeyValuePairImplementation(Type)

Determines whether the specified type implements either System.Collections.DictionaryEntry or System.Collections.Generic.KeyValuePair`2.

public static bool HasKeyValuePairImplementation(this Type type)

Parameters

type Type

The System.Type to extend.

Returns

Boolean

true if the specified type implements either System.Collections.DictionaryEntry or System.Collections.Generic.KeyValuePair`2.; otherwise, false.

Exceptions

System.ArgumentNullException

type cannot be null.

HasTypes(Type, Type[])

Determines whether the specified type type contains one or more of the specified target types.

public static bool HasTypes(this Type type, params Type[] targets)

Parameters

type Type

The System.Type to extend.

targets Type[]

The target types to be matched against.

Returns

Boolean

true if the type contains one or more of the specified target types; otherwise, false.

Exceptions

System.ArgumentNullException

type cannot be null -or- targets cannot be null.

IsComplex(Type)

Determines whether the specified type is a complex System.Type.

public static bool IsComplex(this Type type)

Parameters

type Type

The System.Type to extend.

Returns

Boolean

true if specified type is a complex System.Type; otherwise, false.

Exceptions

System.ArgumentNullException

type is null.

IsNullable(Type)

Determines whether the specified type is a nullable System.ValueType.

public static bool IsNullable(this Type type)

Parameters

type Type

The System.Type to extend.

Returns

Boolean

true if the specified type is nullable; otherwise, false.

Exceptions

System.ArgumentNullException

type cannot be null.

IsSimple(Type)

Determines whether the specified type is a simple System.Type.

public static bool IsSimple(this Type type)

Parameters

type Type

The System.Type to extend.

Returns

Boolean

true if specified type is a simple System.Type; otherwise, false.

Exceptions

System.ArgumentNullException

type is null.

ToFriendlyName(Type, Action<TypeNameOptions>)

Converts the name of the type with the intend to be understood by humans.

public static string ToFriendlyName(this Type type, Action<TypeNameOptions> setup = null)

Parameters

type Type

The System.Type to extend.

setup Action<TypeNameOptions>

The TypeNameOptions which may be configured.

Returns

String

A sanitized System.String that represents the type.

Exceptions

System.ArgumentNullException

type cannot be null.

ToTypeCode(Type)

Gets the underlying type code of the specified type.

public static TypeCode ToTypeCode(this Type type)

Parameters

type Type

The System.Type to extend.

Returns

TypeCode

The code of the underlying type, or Empty if type is null.