TypeExtensions

Type method extensions.

namespace Sirenix.Utilities
{
[ExtensionAttribute]
public static class TypeExtensions
}

Requirements

Namespace: Sirenix.Utilities
Assembly: Sirenix.OdinInspector
Version: 2.0.0.0

Static Fields

Return Type Definition Description
Dictionary<string, string> TypeNameAlternatives Type name alias lookup. TypeNameAlternatives["Single"] will give you "float", "UInt16" will give you "ushort", "Boolean[]" will give you "bool[]" etc..

Static Methods

Return Type Definition Description
Func<TFrom, TTo> GetCastMethodDelegate<TFrom, TTo>(bool) If a type can be casted to another type, this provides a function to manually convert the type.
ulong GetEnumBitmask(Object, Type) Gets the enum bitmask in a ulong.
Func<T, T, bool> GetEqualityComparerDelegate<T>() Gets an equality comparer delegate used to compare the equality of values of a given type. In order, this will be: 1. The == operator, if one is defined on the type. 2. A delegate that uses IEquatable`1, if the type implements that interface. 3. .NET's own Default
bool IsValidIdentifier(string) Checks whether a given string is a valid CSharp identifier name. This also checks full type names including namespaces.

Extension Methods

Return Type Definition Description
bool AreGenericConstraintsSatisfiedBy(this Type, Type[])

Checks whether an array of types satisfy the constraints of a given generic type definition.

If this method returns true, the given parameters can be safely used with Type[]) with the given generic type definition.

bool GenericArgumentsContainsTypes(this Type, Type[]) Determines whether a generic type contains the specified generic argument constraints.
bool GenericParameterIsFulfilledBy(this Type, Type, Dictionary<Type, Type>, HashSet<Type>) Before calling this method we must ALWAYS hold a lock on the GenericConstraintsSatisfaction_LOCK object, as that is an implicit assumption it works with.
IEnumerable<MemberInfo> GetAllMembers(this Type, BindingFlags) Gets all members from a given type, including members from all base types if the DeclaredOnly flag isn't set.
IEnumerable<MemberInfo> GetAllMembers(this Type, string, BindingFlags) Gets all members from a given type, including members from all base types.
IEnumerable<T> GetAllMembers<T>(this Type, BindingFlags) Gets all members of a specific type from a type, including members from all base types, if the DeclaredOnly flag isn't set.
Type[] GetArgumentsOfInheritedOpenGenericClass(this Type, Type) Gets the generic arguments of an inherited open generic class.
Type[] GetArgumentsOfInheritedOpenGenericInterface(this Type, Type) Gets the generic arguments of an inherited open generic interface.
Type[] GetArgumentsOfInheritedOpenGenericType(this Type, Type) Gets the generic arguments of an inherited open generic class or interface.
T GetAttribute<T>(this Type, bool) Gets the first attribute of type T. Returns null in the no attribute of type T was found.
IEnumerable<Type> GetBaseClasses(this Type, bool) Returns a lazy enumerable of all the base classes of this type
IEnumerable<Type> GetBaseTypes(this Type, bool) Returns a lazy enumerable of all the base types of this type including interfaces and classes
MethodInfo GetCastMethod(this Type, Type, bool) If a type can be casted to another type, this provides the method info of the method in charge of converting the type.
Func<Object, Object> GetCastMethodDelegate(this Type, Type, bool) If a type can be casted to another type, this provides a function to manually convert the type.
string GetCompilableNiceFullName(this Type) Gets the full name of the compilable nice.
string GetCompilableNiceName(this Type) Gets the name of the compilable nice.
T GetCustomAttribute<T>(this Type) Returns the first found non-inherited custom attribute of type T on this type Returns null if none was found
T GetCustomAttribute<T>(this Type, bool) Returns the first found custom attribute of type T on this type Returns null if none was found
IEnumerable<T> GetCustomAttributes<T>(this Type) Gets all attributes of type T.
IEnumerable<T> GetCustomAttributes<T>(this Type, bool) Gets all attributes of type T.
Type GetGenericBaseType(this Type, Type) Gets the generic type definition of an open generic base type.
Type GetGenericBaseType(this Type, Type, ref int) Gets the generic type definition of an open generic base type.
string GetGenericConstraintsString(this Type, bool) Not yet documented.
string GetGenericParameterConstraintsString(this Type, bool) Formats a string with the specified generic parameter constraints on any given type. Example output: where T : class
int GetInheritanceDistance(this Type, Type) Gets the number of base types between given type and baseType.
Object GetMemberValue(this MemberInfo, Object) Gets the value contained in a given MemberInfo. Currently only FieldInfo and PropertyInfo is supported.
string GetNiceFullName(this Type) Returns a nicely formatted full name of a type.
string GetNiceName(this Type) Returns a nicely formatted name of a type.
MethodInfo GetOperatorMethod(this Type, Operator) Gets the MethodInfo of a specific operator type.
MethodInfo[] GetOperatorMethods(this Type, Operator) Gets the MethodInfo of a specific operator type.
Type GetReturnType(this MemberInfo) FieldInfo will return the fieldType, propertyInfo the PropertyType, MethodInfo the return type and EventInfo will return the EventHandlerType.
bool HasParamaters(this MethodInfo, IList<Type>, bool) Determines whether a method has the specified parameter types.
bool ImplementsOpenGenericClass(this Type, Type) Determines whether a type implements an open generic class such as List<>.
bool ImplementsOpenGenericInterface(this Type, Type) Determines whether a type implements an open generic interface such as IList<>.
bool ImplementsOpenGenericType(this Type, Type) Determines whether a type implements an open generic interface or class such as IList<> or List<>.
bool ImplementsOrInherits(this Type, Type) Determines whether a type implements or inherits from another type.
bool InheritsFrom(this Type, Type) Determines whether a type inherits or implements another type. Also include support for open generic base types such as List<>.
bool InheritsFrom<TBase>(this Type) Determines whether a type inherits or implements another type. Also include support for open generic base types such as List<>.
bool IsCastableTo(this Type, Type, bool) Determines whether a type can be casted to another type.
bool IsDefined<T>(this Type) Returns true if the attribute whose type is specified by the generic argument is defined on this type
bool IsDefined<T>(this Type, bool) Returns true if the attribute whose type is specified by the generic argument is defined on this type
bool IsFullyConstructedGenericType(this Type) Determines whether a type is a fully constructed generic type.
bool IsNullableType(this Type) Determines whether a type is nullable by ensuring the type is neither a PrimitiveType, ValueType or an Enum.
void SetMemberValue(this MemberInfo, Object, Object) Sets the value of a given MemberInfo. Currently only FieldInfo and PropertyInfo is supported.
bool TryInferGenericParameters(this Type, ref Type[], Type[]) Tries to infer a set of valid generic parameters for a generic type definition, given a subset of known parameters.
string TypeNameGauntlet(this Type) Used to filter out unwanted type names. Ex "int" instead of "Int32"