Version 3.0.0.2

TypeExtensions class

Namespace: Sirenix.Utilities
Assembly: Sirenix.Utilities
public static class TypeExtensions
Inheritance
  • System.Object
  • TypeExtensions

Fields

TypeNameAlternatives
public static readonly Dictionary<string, string> TypeNameAlternatives

Methods

AreGenericConstraintsSatisfiedBy(MethodBase, Type[])
public static bool AreGenericConstraintsSatisfiedBy(this MethodBase genericMethod, params Type[] parameters)
Parameters
System.Reflection.MethodBase genericMethod

System.Type[] parameters

Returns
System.Boolean

AreGenericConstraintsSatisfiedBy(Type, Type[])
public static bool AreGenericConstraintsSatisfiedBy(this Type genericType, params Type[] parameters)
Parameters
System.Type genericType

System.Type[] parameters

Returns
System.Boolean

AreGenericConstraintsSatisfiedBy(Type[], Type[])
public static bool AreGenericConstraintsSatisfiedBy(Type[] definitions, Type[] parameters)
Parameters
System.Type[] definitions

System.Type[] parameters

Returns
System.Boolean

GenericArgumentsContainsTypes(Type, Type[])
public static bool GenericArgumentsContainsTypes(this Type type, params Type[] types)
Parameters
System.Type type

System.Type[] types

Returns
System.Boolean

GenericParameterIsFulfilledBy(Type, Type)
public static bool GenericParameterIsFulfilledBy(this Type genericParameterDefinition, Type parameterType)
Parameters
System.Type genericParameterDefinition

System.Type parameterType

Returns
System.Boolean

GetAllMembers(Type, BindingFlags)
public static IEnumerable<MemberInfo> GetAllMembers(this Type type, BindingFlags flags = BindingFlags.Default)
Parameters
System.Type type

System.Reflection.BindingFlags flags

Returns
System.Collections.Generic.IEnumerable<System.Reflection.MemberInfo>

GetAllMembers(Type, String, BindingFlags)
public static IEnumerable<MemberInfo> GetAllMembers(this Type type, string name, BindingFlags flags = BindingFlags.Default)
Parameters
System.Type type

System.String name

System.Reflection.BindingFlags flags

Returns
System.Collections.Generic.IEnumerable<System.Reflection.MemberInfo>

GetAllMembers<T>(Type, BindingFlags)
public static IEnumerable<T> GetAllMembers<T>(this Type type, BindingFlags flags = BindingFlags.Default)
    where T : MemberInfo
Parameters
System.Type type

System.Reflection.BindingFlags flags

Returns
System.Collections.Generic.IEnumerable<T>

Type Parameters
T

GetArgumentsOfInheritedOpenGenericClass(Type, Type)
public static Type[] GetArgumentsOfInheritedOpenGenericClass(this Type candidateType, Type openGenericType)
Parameters
System.Type candidateType

System.Type openGenericType

Returns
System.Type[]

GetArgumentsOfInheritedOpenGenericInterface(Type, Type)
public static Type[] GetArgumentsOfInheritedOpenGenericInterface(this Type candidateType, Type openGenericInterfaceType)
Parameters
System.Type candidateType

System.Type openGenericInterfaceType

Returns
System.Type[]

GetArgumentsOfInheritedOpenGenericType(Type, Type)
public static Type[] GetArgumentsOfInheritedOpenGenericType(this Type candidateType, Type openGenericType)
Parameters
System.Type candidateType

System.Type openGenericType

Returns
System.Type[]

GetAttribute<T>(Type, Boolean)
public static T GetAttribute<T>(this Type type, bool inherit)
    where T : Attribute
Parameters
System.Type type

System.Boolean inherit

Returns
T

Type Parameters
T

GetBaseClasses(Type, Boolean)
public static IEnumerable<Type> GetBaseClasses(this Type type, bool includeSelf = false)
Parameters
System.Type type

System.Boolean includeSelf

Returns
System.Collections.Generic.IEnumerable<System.Type>

GetBaseTypes(Type, Boolean)
public static IEnumerable<Type> GetBaseTypes(this Type type, bool includeSelf = false)
Parameters
System.Type type

System.Boolean includeSelf

Returns
System.Collections.Generic.IEnumerable<System.Type>

GetCastMethod(Type, Type, Boolean)
public static MethodInfo GetCastMethod(this Type from, Type to, bool requireImplicitCast = false)
Parameters
System.Type from

System.Type to

System.Boolean requireImplicitCast

Returns
System.Reflection.MethodInfo

GetCastMethodDelegate(Type, Type, Boolean)
public static Func<object, object> GetCastMethodDelegate(this Type from, Type to, bool requireImplicitCast = false)
Parameters
System.Type from

System.Type to

System.Boolean requireImplicitCast

Returns
System.Func<System.Object, System.Object>

GetCastMethodDelegate<TFrom, TTo>(Boolean)
public static Func<TFrom, TTo> GetCastMethodDelegate<TFrom, TTo>(bool requireImplicitCast = false)
Parameters
System.Boolean requireImplicitCast

Returns
System.Func<TFrom, TTo>

Type Parameters
TFrom

TTo

GetCompilableNiceFullName(Type)
public static string GetCompilableNiceFullName(this Type type)
Parameters
System.Type type

Returns
System.String

GetCompilableNiceName(Type)
public static string GetCompilableNiceName(this Type type)
Parameters
System.Type type

Returns
System.String

GetCustomAttribute<T>(Type)
public static T GetCustomAttribute<T>(this Type type)
    where T : Attribute
Parameters
System.Type type

Returns
T

Type Parameters
T

GetCustomAttribute<T>(Type, Boolean)
public static T GetCustomAttribute<T>(this Type type, bool inherit)
    where T : Attribute
Parameters
System.Type type

System.Boolean inherit

Returns
T

Type Parameters
T

GetCustomAttributes<T>(Type)
public static IEnumerable<T> GetCustomAttributes<T>(this Type type)
    where T : Attribute
Parameters
System.Type type

Returns
System.Collections.Generic.IEnumerable<T>

Type Parameters
T

GetCustomAttributes<T>(Type, Boolean)
public static IEnumerable<T> GetCustomAttributes<T>(this Type type, bool inherit)
    where T : Attribute
Parameters
System.Type type

System.Boolean inherit

Returns
System.Collections.Generic.IEnumerable<T>

Type Parameters
T

GetEnumBitmask(Object, Type)
public static ulong GetEnumBitmask(object value, Type enumType)
Parameters
System.Object value

System.Type enumType

Returns
System.UInt64

GetEqualityComparerDelegate<T>()
public static Func<T, T, bool> GetEqualityComparerDelegate<T>()
Returns
System.Func<T, T, System.Boolean>

Type Parameters
T

GetGenericBaseType(Type, Type)
public static Type GetGenericBaseType(this Type type, Type baseType)
Parameters
System.Type type

System.Type baseType

Returns
System.Type

GetGenericBaseType(Type, Type, out Int32)
public static Type GetGenericBaseType(this Type type, Type baseType, out int depthCount)
Parameters
System.Type type

System.Type baseType

System.Int32 depthCount

Returns
System.Type

GetGenericConstraintsString(Type, Boolean)
public static string GetGenericConstraintsString(this Type type, bool useFullTypeNames = false)
Parameters
System.Type type

System.Boolean useFullTypeNames

Returns
System.String

GetGenericParameterConstraintsString(Type, Boolean)
public static string GetGenericParameterConstraintsString(this Type type, bool useFullTypeNames = false)
Parameters
System.Type type

System.Boolean useFullTypeNames

Returns
System.String

GetInheritanceDistance(Type, Type)
public static int GetInheritanceDistance(this Type type, Type baseType)
Parameters
System.Type type

System.Type baseType

Returns
System.Int32

GetMemberValue(MemberInfo, Object)
public static object GetMemberValue(this MemberInfo member, object obj)
Parameters
System.Reflection.MemberInfo member

System.Object obj

Returns
System.Object

GetNiceFullName(Type)
public static string GetNiceFullName(this Type type)
Parameters
System.Type type

Returns
System.String

GetNiceName(Type)
public static string GetNiceName(this Type type)
Parameters
System.Type type

Returns
System.String

GetOperatorMethod(Type, Operator)
public static MethodInfo GetOperatorMethod(this Type type, Operator op)
Parameters
System.Type type

Operator op

Returns
System.Reflection.MethodInfo

GetOperatorMethod(Type, Operator, Type, Type)
public static MethodInfo GetOperatorMethod(this Type type, Operator op, Type leftOperand, Type rightOperand)
Parameters
System.Type type

Operator op

System.Type leftOperand

System.Type rightOperand

Returns
System.Reflection.MethodInfo

GetOperatorMethods(Type, Operator)
public static MethodInfo[] GetOperatorMethods(this Type type, Operator op)
Parameters
System.Type type

Operator op

Returns
System.Reflection.MethodInfo[]

GetReturnType(MemberInfo)
public static Type GetReturnType(this MemberInfo memberInfo)
Parameters
System.Reflection.MemberInfo memberInfo

Returns
System.Type

HasParamaters(MethodInfo, IList<Type>, Boolean)
public static bool HasParamaters(this MethodInfo methodInfo, IList<Type> paramTypes, bool inherit = true)
Parameters
System.Reflection.MethodInfo methodInfo

System.Collections.Generic.IList<System.Type> paramTypes

System.Boolean inherit

Returns
System.Boolean

ImplementsOpenGenericClass(Type, Type)
public static bool ImplementsOpenGenericClass(this Type candidateType, Type openGenericType)
Parameters
System.Type candidateType

System.Type openGenericType

Returns
System.Boolean

ImplementsOpenGenericInterface(Type, Type)
public static bool ImplementsOpenGenericInterface(this Type candidateType, Type openGenericInterfaceType)
Parameters
System.Type candidateType

System.Type openGenericInterfaceType

Returns
System.Boolean

ImplementsOpenGenericType(Type, Type)
public static bool ImplementsOpenGenericType(this Type candidateType, Type openGenericType)
Parameters
System.Type candidateType

System.Type openGenericType

Returns
System.Boolean

ImplementsOrInherits(Type, Type)
public static bool ImplementsOrInherits(this Type type, Type to)
Parameters
System.Type type

System.Type to

Returns
System.Boolean

InheritsFrom(Type, Type)
public static bool InheritsFrom(this Type type, Type baseType)
Parameters
System.Type type

System.Type baseType

Returns
System.Boolean

InheritsFrom<TBase>(Type)
public static bool InheritsFrom<TBase>(this Type type)
Parameters
System.Type type

Returns
System.Boolean

Type Parameters
TBase

IsCastableTo(Type, Type, Boolean)
public static bool IsCastableTo(this Type from, Type to, bool requireImplicitCast = false)
Parameters
System.Type from

System.Type to

System.Boolean requireImplicitCast

Returns
System.Boolean

IsCSharpKeyword(String)
public static bool IsCSharpKeyword(string identifier)
Parameters
System.String identifier

Returns
System.Boolean

IsDefined<T>(Type)
public static bool IsDefined<T>(this Type type)
    where T : Attribute
Parameters
System.Type type

Returns
System.Boolean

Type Parameters
T

IsDefined<T>(Type, Boolean)
public static bool IsDefined<T>(this Type type, bool inherit)
    where T : Attribute
Parameters
System.Type type

System.Boolean inherit

Returns
System.Boolean

Type Parameters
T

IsFullyConstructedGenericType(Type)
public static bool IsFullyConstructedGenericType(this Type type)
Parameters
System.Type type

Returns
System.Boolean

IsNullableType(Type)
public static bool IsNullableType(this Type type)
Parameters
System.Type type

Returns
System.Boolean

IsValidIdentifier(String)
public static bool IsValidIdentifier(string identifier)
Parameters
System.String identifier

Returns
System.Boolean

SafeGetCustomAttributes(Assembly, Type, Boolean)
public static object[] SafeGetCustomAttributes(this Assembly assembly, Type type, bool inherit)
Parameters
System.Reflection.Assembly assembly

System.Type type

System.Boolean inherit

Returns
System.Object[]

SafeGetTypes(Assembly)
public static Type[] SafeGetTypes(this Assembly assembly)
Parameters
System.Reflection.Assembly assembly

Returns
System.Type[]

SafeIsDefined(Assembly, Type, Boolean)
public static bool SafeIsDefined(this Assembly assembly, Type attribute, bool inherit)
Parameters
System.Reflection.Assembly assembly

System.Type attribute

System.Boolean inherit

Returns
System.Boolean

SetMemberValue(MemberInfo, Object, Object)
public static void SetMemberValue(this MemberInfo member, object obj, object value)
Parameters
System.Reflection.MemberInfo member

System.Object obj

System.Object value

TryInferGenericParameters(Type, out Type[], Type[])
public static bool TryInferGenericParameters(this Type genericTypeDefinition, out Type[] inferredParams, params Type[] knownParameters)
Parameters
System.Type genericTypeDefinition

System.Type[] inferredParams

System.Type[] knownParameters

Returns
System.Boolean