Class TypeDecoratorExtensions
- Namespace
- Cuemon
- Assembly
- Cuemon.Core.dll
Extension methods for the System.Type class hidden behind the IDecorator<T> interface.
public static class TypeDecoratorExtensions
- Inheritance
-
ObjectTypeDecoratorExtensions
Methods
GetAllEvents(IDecorator<Type>, Action<MemberReflectionOptions>)
Retrieves a collection that represents all events defined on the enclosed System.Type of the specified decorator
and its inheritance chain.
public static IEnumerable<EventInfo> GetAllEvents(this IDecorator<Type> decorator, Action<MemberReflectionOptions> setup = null)
Parameters
decorator
IDecorator<Type>The System.Type to extend.
setup
Action<MemberReflectionOptions>The MemberReflectionOptions which may be configured.
Returns
- IEnumerable<EventInfo>
An System.Collections.Generic.IEnumerable<T> that contains all System.Reflection.EventInfo objects on the enclosed System.Type of the specified
decorator
and its inheritance chain.
- See Also
-
IDecorator<T>Decorator<T>
GetAllFields(IDecorator<Type>, Action<MemberReflectionOptions>)
Retrieves a collection that represents all fields defined on the enclosed System.Type of the specified decorator
and its inheritance chain.
public static IEnumerable<FieldInfo> GetAllFields(this IDecorator<Type> decorator, Action<MemberReflectionOptions> setup = null)
Parameters
decorator
IDecorator<Type>The System.Type to extend.
setup
Action<MemberReflectionOptions>The MemberReflectionOptions which may be configured.
Returns
- IEnumerable<FieldInfo>
An System.Collections.Generic.IEnumerable<T> that contains all System.Reflection.FieldInfo objects on the enclosed System.Type of the specified
decorator
and its inheritance chain.
- See Also
-
IDecorator<T>Decorator<T>
GetAllMethods(IDecorator<Type>, Action<MemberReflectionOptions>)
Retrieves a collection that represents all methods defined on the enclosed System.Type of the specified decorator
and its inheritance chain.
public static IEnumerable<MethodInfo> GetAllMethods(this IDecorator<Type> decorator, Action<MemberReflectionOptions> setup = null)
Parameters
decorator
IDecorator<Type>The System.Type to extend.
setup
Action<MemberReflectionOptions>The MemberReflectionOptions which may be configured.
Returns
- IEnumerable<MethodInfo>
An System.Collections.Generic.IEnumerable<T> that contains all System.Reflection.MethodInfo objects on the enclosed System.Type of the specified
decorator
and its inheritance chain.
- See Also
-
IDecorator<T>Decorator<T>
GetAllProperties(IDecorator<Type>, Action<MemberReflectionOptions>)
Retrieves a collection that represents all properties defined on the enclosed System.Type of the specified decorator
and its inheritance chain.
public static IEnumerable<PropertyInfo> GetAllProperties(this IDecorator<Type> decorator, Action<MemberReflectionOptions> setup = null)
Parameters
decorator
IDecorator<Type>The System.Type to extend.
setup
Action<MemberReflectionOptions>The MemberReflectionOptions which may be configured.
Returns
- IEnumerable<PropertyInfo>
An System.Collections.Generic.IEnumerable<T> that contains all System.Reflection.PropertyInfo objects on the enclosed System.Type of the specified
decorator
and its inheritance chain.
- See Also
-
IDecorator<T>Decorator<T>
GetDefaultValue(IDecorator<Type>)
Gets the default value from the underlying System.Type of the decorator
.
public static object GetDefaultValue(this IDecorator<Type> decorator)
Parameters
decorator
IDecorator<Type>
Returns
- Object
The default value from the underlying System.Type of the
decorator
.
Remarks
Usage is primarily intended for struct
.
Exceptions
- System.ArgumentNullException
decorator
cannot be null.
- See Also
-
IDecorator<T>Decorator<T>
GetDerivedTypes(IDecorator<Type>, Assembly[])
Gets a collection (self-to-derived) of derived / descendant types from the underlying System.Type of the decorator
.
public static IEnumerable<Type> GetDerivedTypes(this IDecorator<Type> decorator, params Assembly[] assemblies)
Parameters
decorator
IDecorator<Type>The IDecorator<T> to extend.
assemblies
Assembly[]The assemblies to include in the search of derived types.
Returns
- IEnumerable<Type>
An System.Collections.Generic.IEnumerable<T> that contains the derived types from the underlying System.Type of the
decorator
.
Exceptions
- System.ArgumentNullException
decorator
cannot be null.
- See Also
-
IDecorator<T>Decorator<T>
GetHierarchyTypes(IDecorator<Type>, Assembly[])
Gets a collection (inherited-to-self-to-derived) of inherited / ancestor and derived / descendant types from the underlying System.Type of the decorator
.
public static IEnumerable<Type> GetHierarchyTypes(this IDecorator<Type> decorator, params Assembly[] assemblies)
Parameters
decorator
IDecorator<Type>The IDecorator<T> to extend.
assemblies
Assembly[]The assemblies to include in the search of derived types.
Returns
- IEnumerable<Type>
An System.Collections.Generic.IEnumerable<T> that contains a sorted (base-to-derived) collection of inherited and derived types from the underlying System.Type of the
decorator
.
Exceptions
- System.ArgumentNullException
decorator
cannot be null.
- See Also
-
IDecorator<T>Decorator<T>
GetInheritedTypes(IDecorator<Type>)
Gets a collection (inherited-to-self) of inherited / ancestor types from the underlying System.Type of the decorator
.
public static IEnumerable<Type> GetInheritedTypes(this IDecorator<Type> decorator)
Parameters
decorator
IDecorator<Type>The IDecorator<T> to extend.
Returns
- IEnumerable<Type>
An System.Collections.Generic.IEnumerable<T> that contains the inherited types from the underlying System.Type of the
decorator
.
Exceptions
- System.ArgumentNullException
decorator
cannot be null.
- See Also
-
IDecorator<T>Decorator<T>
GetRuntimePropertiesExceptOf<T>(IDecorator<Type>)
Retrieves a collection that represents all the properties defined on the enclosed System.Type of the decorator
except those defined on T
.
public static IEnumerable<PropertyInfo> GetRuntimePropertiesExceptOf<T>(this IDecorator<Type> decorator)
Parameters
decorator
IDecorator<Type>The IDecorator<T> to extend.
Returns
- IEnumerable<PropertyInfo>
A collection of properties for the enclosed System.Type of the
decorator
except those defined onT
.
Type Parameters
T
The type to exclude properties on the enclosed System.Type of the
decorator
.
Exceptions
- System.ArgumentNullException
decorator
cannot be null.
- See Also
-
IDecorator<T>Decorator<T>
HasAnonymousCharacteristics(IDecorator<Type>)
Determines whether the underlying System.Type of the decorator
suggest an anonymous implementation (be that in a form of a type, delegate or lambda expression).
public static bool HasAnonymousCharacteristics(this IDecorator<Type> decorator)
Parameters
decorator
IDecorator<Type>The IDecorator<T> to extend.
Returns
- Boolean
true
if the underlying System.Type of thedecorator
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
decorator
cannot be null.
- See Also
-
IDecorator<T>Decorator<T>
HasAttribute(IDecorator<Type>, Type[])
Determines whether the underlying System.Type of the decorator
implements one or more of the specified attributeTypes
.
public static bool HasAttribute(this IDecorator<Type> decorator, params Type[] attributeTypes)
Parameters
decorator
IDecorator<Type>The IDecorator<T> to extend.
attributeTypes
Type[]The attribute types to be matched against.
Returns
- Boolean
true
if the underlying System.Type of thedecorator
implements one or more of the specifiedattributeTypes
; otherwise,false
.
Exceptions
- System.ArgumentNullException
decorator
cannot be null -or-attributeTypes
cannot be null.
- See Also
-
IDecorator<T>Decorator<T>
HasCircularReference(IDecorator<Type>, Object, Int32, Func<Object, PropertyInfo, Object>)
Determines whether the specified source
(which type must be the same as the underlying System.Type of the decorator
) has a circular reference.
public static bool HasCircularReference(this IDecorator<Type> decorator, object source, int maxDepth = 2, Func<object, PropertyInfo, object> valueResolver = null)
Parameters
decorator
IDecorator<Type>The IDecorator<T> to extend.
source
ObjectThe source to check for circular reference.
maxDepth
Int32The maximum depth to traverse of
source
.valueResolver
Func<Object, PropertyInfo, Object>The function delegate that is invoked when a property can be read and is of same type as the underlying System.Type of the
decorator
.
Returns
- Boolean
true
if the specifiedsource
has a circular reference; otherwise,false
.
Exceptions
- System.ArgumentNullException
decorator
cannot be null.- System.InvalidOperationException
source
has a different type than the underlying type ofdecorator
.
- See Also
-
IDecorator<T>Decorator<T>
HasComparableImplementation(IDecorator<Type>)
Determines whether the underlying System.Type of the decorator
implements either System.IComparable or System.IComparable`1.
public static bool HasComparableImplementation(this IDecorator<Type> decorator)
Parameters
decorator
IDecorator<Type>The IDecorator<T> to extend.
Returns
- Boolean
true
if the underlying System.Type of thedecorator
implements either System.IComparable or System.IComparable`1; otherwise,false
.
Exceptions
- System.ArgumentNullException
decorator
cannot be null.
- See Also
-
IDecorator<T>Decorator<T>
HasComparerImplementation(IDecorator<Type>)
Determines whether the underlying System.Type of the decorator
implements either System.Collections.IComparer or System.Collections.Generic.IComparer<T>.
public static bool HasComparerImplementation(this IDecorator<Type> decorator)
Parameters
decorator
IDecorator<Type>The IDecorator<T> to extend.
Returns
- Boolean
true
if the underlying System.Type of thedecorator
implements either System.Collections.IComparer or System.Collections.Generic.IComparer<T>; otherwise,false
.
Exceptions
- System.ArgumentNullException
decorator
cannot be null.
- See Also
-
IDecorator<T>Decorator<T>
HasDefaultConstructor(IDecorator<Type>)
Determines whether the underlying System.Type of the decorator
has a default constructor.
public static bool HasDefaultConstructor(this IDecorator<Type> decorator)
Parameters
decorator
IDecorator<Type>
Returns
- Boolean
true
if the underlying System.Type of thedecorator
has a default constructor; otherwise,false
.
Exceptions
- System.ArgumentNullException
decorator
cannot be null.
- See Also
-
IDecorator<T>Decorator<T>
HasDictionaryImplementation(IDecorator<Type>)
Determines whether the underlying System.Type of the decorator
implements either System.Collections.IDictionary, System.Collections.Generic.IDictionary<TKey, TValue> or System.Collections.Generic.IReadOnlyDictionary<TKey, TValue>.
public static bool HasDictionaryImplementation(this IDecorator<Type> decorator)
Parameters
decorator
IDecorator<Type>The IDecorator<T> to extend.
Returns
- Boolean
true
if the underlying System.Type of thedecorator
implements either System.Collections.IDictionary, System.Collections.Generic.IDictionary<TKey, TValue> or System.Collections.Generic.IReadOnlyDictionary<TKey, TValue>; otherwise,false
.
Exceptions
- System.ArgumentNullException
decorator
cannot be null.
- See Also
-
IDecorator<T>Decorator<T>
HasEnumerableImplementation(IDecorator<Type>)
Determines whether the underlying System.Type of the decorator
implements either System.Collections.IEnumerable or System.Collections.Generic.IEnumerable<T>.
public static bool HasEnumerableImplementation(this IDecorator<Type> decorator)
Parameters
decorator
IDecorator<Type>The IDecorator<T> to extend.
Returns
- Boolean
true
if the underlying System.Type of thedecorator
implements either System.Collections.IEnumerable or System.Collections.Generic.IEnumerable<T>; otherwise,false
.
Exceptions
- System.ArgumentNullException
decorator
cannot be null.
- See Also
-
IDecorator<T>Decorator<T>
HasEqualityComparerImplementation(IDecorator<Type>)
Determines whether the underlying System.Type of the decorator
implements either System.Collections.IEqualityComparer or System.Collections.Generic.IEqualityComparer<T>.
public static bool HasEqualityComparerImplementation(this IDecorator<Type> decorator)
Parameters
decorator
IDecorator<Type>The IDecorator<T> to extend.
Returns
- Boolean
true
if the underlying System.Type of thedecorator
implements either System.Collections.IEqualityComparer or System.Collections.Generic.IEqualityComparer<T>; otherwise,false
.
Exceptions
- System.ArgumentNullException
decorator
cannot be null.
- See Also
-
IDecorator<T>Decorator<T>
HasInterface(IDecorator<Type>, Type[])
Determines whether the underlying System.Type of the decorator
implements one or more of the specified interfaceTypes
.
public static bool HasInterface(this IDecorator<Type> decorator, params Type[] interfaceTypes)
Parameters
decorator
IDecorator<Type>The IDecorator<T> to extend.
interfaceTypes
Type[]The interface types to be matched against.
Returns
- Boolean
true
if the underlying System.Type of thedecorator
implements one or more of the specifiedinterfaceTypes
; otherwise,false
.
Exceptions
- System.ArgumentNullException
decorator
cannot be null -or-interfaceTypes
cannot be null.
- See Also
-
IDecorator<T>Decorator<T>
HasKeyValuePairImplementation(IDecorator<Type>)
Determines whether the underlying System.Type of the decorator
implements either System.Collections.DictionaryEntry or System.Collections.Generic.KeyValuePair`2.
public static bool HasKeyValuePairImplementation(this IDecorator<Type> decorator)
Parameters
decorator
IDecorator<Type>The IDecorator<T> to extend.
Returns
- Boolean
true
if the underlying System.Type of thedecorator
implements either System.Collections.DictionaryEntry or System.Collections.Generic.KeyValuePair`2.; otherwise,false
.
Exceptions
- System.ArgumentNullException
decorator
cannot be null.
- See Also
-
IDecorator<T>Decorator<T>
HasTypes(IDecorator<Type>, Type[])
Determines whether the enclosed System.Type of the decorator
contains one or more of the specified types
.
public static bool HasTypes(this IDecorator<Type> decorator, params Type[] types)
Parameters
decorator
IDecorator<Type>The IDecorator<T> to extend.
types
Type[]The types to be matched against.
Returns
- Boolean
true
if the enclosed System.Type of thedecorator
contains one or more of the specifiedtypes
; otherwise,false
.
Exceptions
- System.ArgumentNullException
decorator
cannot be null -or-types
cannot be null.
- See Also
-
IDecorator<T>Decorator<T>
IsComplex(IDecorator<Type>)
Determines whether the underlying System.Type of the decorator
is considered complex in its nature.
public static bool IsComplex(this IDecorator<Type> decorator)
Parameters
decorator
IDecorator<Type>The IDecorator<T> to extend.
Returns
- Boolean
true
if the underlying System.Type of thedecorator
is considered complex in its nature; otherwise,false
.
Exceptions
- System.ArgumentNullException
decorator
cannot be null.
- See Also
-
IDecorator<T>Decorator<T>
IsNullable(IDecorator<Type>)
Determines whether the underlying System.Type of the decorator
is a nullable System.ValueType.
public static bool IsNullable(this IDecorator<Type> decorator)
Parameters
decorator
IDecorator<Type>The IDecorator<T> to extend.
Returns
- Boolean
true
if the underlying System.Type of thedecorator
is nullable; otherwise,false
.
Exceptions
- System.ArgumentNullException
decorator
cannot be null.
- See Also
-
IDecorator<T>Decorator<T>
MatchMember(IDecorator<Type>, String, Action<MethodBaseOptions>)
Conduct a search for memberName
using the specified setup
on the underlying System.Type of the decorator
.
public static MethodBase MatchMember(this IDecorator<Type> decorator, string memberName, Action<MethodBaseOptions> setup = null)
Parameters
decorator
IDecorator<Type>The IDecorator<T> to extend.
memberName
StringThe name of the member on the underlying System.Type of the
decorator
.setup
Action<MethodBaseOptions>The MethodBaseOptions which may be configured.
Returns
- MethodBase
A System.Reflection.MethodBase object representing the method that matches the specified requirements, if found on the underlying System.Type of the
decorator
; otherwise,null
.
Exceptions
- System.ArgumentNullException
decorator
cannot be null -or-memberName
cannot be null.- ArgumentException
memberName
cannot be empty or consist only of white-space characters.
- See Also
-
IDecorator<T>Decorator<T>
ToFriendlyName(IDecorator<Type>, Action<TypeNameOptions>)
Returns a human-readable System.String that represents the underlying System.Type of the decorator
.
public static string ToFriendlyName(this IDecorator<Type> decorator, Action<TypeNameOptions> setup = null)
Parameters
decorator
IDecorator<Type>The IDecorator<T> to extend.
setup
Action<TypeNameOptions>The TypeNameOptions which may be configured.
Returns
- String
A human readable System.String that represents the underlying System.Type of the
decorator
.
Exceptions
- System.ArgumentNullException
decorator
cannot be null.
- See Also
-
IDecorator<T>Decorator<T>