|
static Type[] | Ancestry (this Type type) |
| Enumerates the ancestry of a Type.
|
static Type[] | AncestryUntil (this Type type, Type from) |
| Enumerates the ancestry of a Type, from the given type.
|
static IEnumerable< Type > | WalkAncestry (this Type type, Type oldest) |
| Walks the type ancestry of a type, starting at that type. If you'd like the ancestry the other way around, look at Ancestry and AncestryUntil. This variant is also lazy, so bailing out stops the walk.
|
static Dictionary< string, object > | GetAllConstants (this Type type) |
| Returns a dictionary of all constant values defined on a Type.
|
static Dictionary< string, T > | GetAllConstants< T > (this Type type) |
| Returns a dictionary of all constant values of a specified Type found on a Type.
|
static IEnumerable< object > | GetAllConstantValues (this Type type) |
| Returns a collection of all the constant values defined on a Type.
|
static IEnumerable< T > | GetAllConstantValues< T > (this Type type) |
| Returns a collection of all the constant values defined on a Type, restricted to the required Type T.
|
static bool | HasDefaultConstructor (this Type type) |
| Tests if a Type has a default constructor (ie, a constructor with no parameters)
|
static bool | IsArrayOrAssignableFromArray (this Type t) |
| Tests if a type is an array or could be assigned from an array.
|
static bool | IsEnum (this Type t) |
| Provides an extension method mimicking the full framework IsEnum for a single point of code usage.
|
static Assembly | GetAssembly (this Type t) |
| Provides an extension method mimicking the full framework GetAssembly for a single point of code usage.
|
static Type | BaseType (this Type type) |
| Provides an extension method mimicking the full framework BaseType for a single point of code usage.
|
static bool | IsGenericType (this Type t) |
| Provides an extension method mimicking the full framework IsGenericType for a single point of code usage.
|
static bool | IsGenericOf (this Type t, Type genericTest) |
| Tests if a type is a generic of a given generic type (eg typeof(List<>))
|
static bool | IsAssignableFromArrayOf< T > (this Type t) |
| Tests if a type is assignable from an array of T.
|
static bool | ImplementsEnumerableGenericType (this Type t) |
| Tests if a type implements IEnumerable<>.
|
static bool | ImplementsIDictionaryGenericType (this Type type) |
| Returns true if the provided type implements IDictionary<,> anywhere in the type heirachy.
|
static bool | IsIDictionary (this Type type) |
| Returns true if a type directly implements IDictionary<,>.
|
static bool | TryGetDictionaryKeyAndValueTypes (this Type type, out Type keyType, out Type valueType) |
| Tries to get the key and value types for an object, if it implements IDictionary<TKey,TValue>. Returns true if sucessful (with the out parameters set) or false if the provided type does not implement IDictionary<,>.
|
static Type | TryGetEnumerableInterface (this Type srcType) |
| Attempts to get the implemented Generic IEnumerable interface for a type, if possible.
|
static Type | TryGetEnumerableItemType (this Type srcType) |
| Attempts to get the item type (T) for a Type which is assumed to implement IEnumerable<T>.
|
static bool | IsGenericOfIEnumerable (this Type arg) |
| Tests if a type directly implements the generic IEnumerable interface.
|
static bool | IsEnumerable (this Type arg) |
| Tests if a type is enumerable by the duck-typing that .net understands (ie, could wrap with EnumerableWrapper)
|
static bool | HasMethod (this Type t, string methodName) |
| Tests if a type has a named method, without testing return type or parameters.
|
static bool | HasVoidMethod (this Type t, string methodName, params Type[] parameters) |
| Test if a type has a method returning void, with the optional list of parameter types.
|
static bool | HasMethod (this Type t, string name, Type returnType, params Type[] parameterTypes) |
| Tests if a type has the named method with the provided return type and optional parameter types.
|
static Type | GetCollectionItemType (this Type collectionType) |
| Attempts to get the item type of a collection.
|
static Type[] | GetAllImplementedInterfaces (this Type inspectType) |
| Attempts to find all implemented interfaces (and inherited ones) for a Type.
|
static bool | IsDisposable (this Type t) |
| Tests if a type implements IDisposable.
|
static string | PrettyName (this Type type) |
| Provides a "pretty" name for a type, taking into account generics and nullable types.
|
static bool | IsCollection (this Type type) |
| Rudimentary test for if a type is a collection type, testing for IEnumerable<> interface implementation as well as some baked-in known generic types.
|
static bool | CanBeAssignedNull (this Type type) |
| Determines if an object of this type can be assigned null.
|
static bool | IsValueType (this Type type) |
| Provides single method to determine IsValueType (shimmed for NETSTANDARD)
|
static bool | IsAssignableOrUpCastableTo (this Type src, Type target) |
| Returns true if the type being operated on can be directly assigned or implicitly upcast to the target type.
|
static bool | CanImplicitlyCastTo (this Type source, Type target) |
| Returns true if the type being operated on can be implicitly upcast to the target type.
|
static bool | TryImplicitlyCastTo (this object srcValue, Type targetType, out object castValue) |
| Returns true if the type being operated on can be implicitly upcast to the target type (value types only, so far)
|
static object | DefaultValue (this Type type) |
| Returns the default value for the type being operated on.
|
static bool | IsInterface (this Type type) |
| Cross-target shim for the IsInterface property, found on Type in NetFramework and on Type.GetTypeInf() on NETSTANDARD.
|
static bool | IsNumericType (this Type type) |
| Determines whether the provided type is a known numeric type (ie int / short / byte / double / float / decimal )
|
static bool | IsAncestorOf (this Type type, Type test) |
| Determines whether the type being operated on is an ancestor of the other type ie typeof(object).IsAncestorOf(typeof(Foo)) => true.
|
static bool | Inherits (this Type type, Type test) |
| Returns true when the type being operated on inherits from the test type, ie typeof(Foo).Inherits(typeof(object)) => true.
|
static bool | Implements< T > (this Type type) |
| Tests if the type being operated on implements the provided interfaceType.
|
static bool | Implements (this Type type, Type interfaceType) |
| Tests if the type being operated on implements the provided interfaceType.
|
static bool | AllPublicInstancePropertiesAndMethodsAreVirtualOrAbstractAndNonFinal (this Type type) |
| Tests if all public instance properties and methods are virtual or abstract and non-final (ie, can be mimicked with a duck)
|
static bool | AllPublicInstancePropertiesAndMethodsAreNonFinal (this Type type) |
| Tests if all public instance properties and methods are non-final.
|
static bool | AllPublicInstanceMethodsAreNonFinal (this Type type) |
| Tests if all public instance methods are non-final.
|
static bool | AllPublicInstancePropertiesAreNonFinal (this Type type) |
| Tests if all public instance properties are non-final.
|
static bool | AllPublicInstancePropertiesAndMethodsAreVirtualOrAbstract (this Type type) |
| Returns true if all public properties and methods are either virtual or abstract\ (ie can be properly overridden)
|
static bool | AllPublicInstancePropertiesAreVirtualOrAbstract (this Type type) |
| Returns true if all instance properties on the provided type are either virtual or abstract (ie, overridable)
|
static bool | AllPublicInstanceMethodsAreVirtualOrAbstract (this Type type) |
| Returns true if all instance methods on the provided type are either virtual or abstract (ie, overridable)
|
static T | GetTopMostPropertyValue< T > (this object data, string propertyName) |
| Retrieves the value of the "top-most" property in an inheritance hierarchy which matches the given name and type.
|
static void | SetTopMostProperty< T > (this object data, string propertyName, T value) |
| Sets the "top-most" property in an ancestry, useful for setting properties marked as "new" when you have access to the object cast to an ancestor type.
|
static bool | IsVirtualOrAbstract (this MethodInfo methodInfo) |
| returns true if the given method is virtual or abstract
|
static bool | IsConcrete (this Type t) |
| returns true if the type is not an interface or an abstract type
|
static bool | IsVirtualOrAbstract (this PropertyInfo propertyInfo) |
| returns true if the given property is virtual or abstract
|
static bool | IsFinal (this PropertyInfo propertyInfo) |
| returns true if the property is marked as IsFinal
|
static bool | Implements< T > (this T obj, Type expected) |
| returns true if the provided object implements the expected interface
|
static bool | IsNullableType (this Type arg) |
| Tests if the provided type is nullable.
|
static void | SetStatic< T > (this Type t, string fieldOrPropertyName, T value) |
| Attempts to set a static property or field value.
|
static T | GetStatic< T > (this Type t, string fieldOrPropertyName) |
| Attempts to get a static property or field value.
|
static bool | IsPrimitiveOrImmutable (this Type type) |
| Tests if the provided type is a "proper" primitive or some other built-in immutable type, eg DateTime, TimeSpan, Guid, DateTimeOffset.
|
static Type | ResolveNullableUnderlyingType (this Type type) |
| Resolves to the actual type or the underlying type T if the provided type is Nullable<T>.
|
static bool | HasAttribute< TAttribute > (this Type type) |
| Tests if a provided type or base type is decorated with the expected attribute [TAttribute].
|
static bool | HasAttribute< TAttribute > (this Type type, Func< TAttribute, bool > matcher) |
| Test if the provided type is decorated with [TAttribute], applying inheritance and the provided matcher.
|
static bool | HasAttribute< TAttribute > (this Type type, bool inherit, Func< TAttribute, bool > matcher) |
| Test if the provided type is decorated with [TAttribute], applying optional inheritance and the provided matcher.
|
static bool | HasAttribute< TAttribute > (this Type type, bool inherit) |
| Tests if a provided type is decorated with the attribute of type attributeType, including base types when enabled.
|
static bool | HasAttribute (this Type type, Type attributeType, bool inherit) |
| Tests if a provided type is decorated with the attribute of type attributeType, including base types when enabled.
|
static bool | HasAttribute (this Type type, Type attributeType, bool inherit, Func< Attribute, bool > matcher) |
| Tests if a provided type is decorated with the attribute of type attributeType, including base types when enabled.
|
static bool | HasAttribute< TAttribute > (this MethodInfo methodInfo) |
| Tests if the method (or any overridden base method) is decorated with [TAttribute].
|
static bool | HasAttribute< TAttribute > (this MethodInfo methodInfo, Func< TAttribute, bool > matcher) |
| Tests if the method (or any overridden base method) is decorated with [TAttribute].
|
static bool | HasAttribute< TAttribute > (this MethodInfo methodInfo, bool inherit) |
| Tests if the method is decorated with [TAttribute], including inheritance when enabled.
|
static bool | HasAttribute< TAttribute > (this MethodInfo methodInfo, bool inherit, Func< TAttribute, bool > matcher) |
| Tests if the method is decorated with [TAttribute], including inheritance when enabled.
|
static bool | HasAttribute< TAttribute > (this ParameterInfo parameterInfo) |
| Tests if the provided ParameterInfo is decorated with [TAttribute].
|
static bool | HasAttribute< TAttribute > (this ParameterInfo parameterInfo, Func< TAttribute, bool > matcher) |
| Tests if the provided ParameterInfo is decorated with [TAttribute], validating the attribute with the provided matcher.
|
static bool | HasAttribute (this ParameterInfo parameterInfo, Type attributeType) |
| Tests if the provided ParameterInfo has been decorated with an attribute of the given type, passing the provided matcher.
|
static bool | HasAttribute (this ParameterInfo parameterInfo, Type attributeType, Func< Attribute, bool > matcher) |
| Tests if the provided ParameterInfo has been decorated with an attribute of the given type, passing the provided matcher.
|
static bool | HasAttribute (this MethodInfo methodInfo, Type attributeType, bool inherit) |
| Tests if a provided method is decorated with the attribute of type attributeType, including inheritance when enabled.
|
static bool | HasAttribute (this MethodInfo methodInfo, Type attributeType, bool inherit, Func< Attribute, bool > matcher) |
| Tests if a provided method is decorated with the attribute of type attributeType, including inheritance when enabled.
|
static bool | HasAttribute< TAttribute > (this PropertyInfo propertyInfo) |
| Tests if the property (or base property that is overridden) is decorated with [TAttribute].
|
static bool | HasAttribute< TAttribute > (this PropertyInfo propertyInfo, bool inherit) |
| Tests if the property is decorated with [TAttribute], directly specifying whether or not to inherit attributes from base members.
|
static bool | HasAttribute< TAttribute > (this PropertyInfo propertyInfo, bool inherit, Func< TAttribute, bool > matcher) |
| Tests if the property is decorated with [TAttribute], directly specifying whether or not to inherit attributes from base members.
|
static bool | HasAttribute (this PropertyInfo propertyInfo, Type attributeType, bool inherit) |
| Tests if the property is decorated with [TAttribute].
|
static bool | HasAttribute (this PropertyInfo propertyInfo, Type attributeType, bool inherit, Func< Attribute, bool > matcher) |
| Tests if the property is decorated with [TAttribute].
|
static bool | IsCompilerGenerated (this Type type) |
| Returns true if the type is compiler-generated This is always the case with anonymous types, but may also be the case with other types. Other heuristics for determining an anonymous type rely on naming (unreliable) and it being sealed.
|
static bool | LooksAnonymous (this Type type) |
| Takes a guess that the type is anonymous based on some rules:
|
static bool | HasOnlyParameterlessConstructor (this Type type) |
| Determine if a type has a single constructor and that constructor is parameterless.
|
static bool | HasParameterlessConstructor (this Type type) |
| Returns true if the type has a parameterless constructor Note that the type may have other constructors too.
|
static IEnumerable< AttributeWalkStep > | WalkAttributes (this Type type) |
| Walks the attributes per-type on the ancestry of the provided type.
|