Table of Contents

Class TypeExtensions

Namespace
DotEx.Reflections
Assembly
DotEx.dll

Extensions for Type.

public static class TypeExtensions
Inheritance
TypeExtensions
Inherited Members

Methods

GetFieldsAndAttributes(Type, Type, BindingFlags?)

Returns all fields and their respective attributes in the type annotated with the given attribute.

public static IEnumerable<(FieldInfo FieldInfo, Attribute[] Attributes)> GetFieldsAndAttributes(this Type type, Type attrType, BindingFlags? flags = null)

Parameters

type Type

Type to search.

attrType Type

Attribute to match.

flags BindingFlags?

Binding flags to match.

Returns

IEnumerable<(FieldInfo FieldInfo, Attribute[] Attributes)>

Fields with the given attribute defined, together with the respective attributes..

GetFieldsAndAttributes<T>(Type, BindingFlags?)

Returns all fields and their respective attributes in the type annotated with the given attribute.

public static IEnumerable<(FieldInfo FieldInfo, T[] Attributes)> GetFieldsAndAttributes<T>(this Type type, BindingFlags? flags = null) where T : Attribute

Parameters

type Type

Attribute to match.

flags BindingFlags?

Binding flags to match.

Returns

IEnumerable<(FieldInfo FieldInfo, T[] Attributes)>

Fields with the given attribute defined, together with the respective attributes..

Type Parameters

T

Type to search.

GetFieldsWithAttribute(Type, Type, BindingFlags?)

Returns all fields in the type annotated with the given attribute.

public static IEnumerable<FieldInfo> GetFieldsWithAttribute(this Type type, Type attrType, BindingFlags? flags = null)

Parameters

type Type

Type to search.

attrType Type

Attribute to match.

flags BindingFlags?

Binding flags to match.

Returns

IEnumerable<FieldInfo>

Fields with the given attribute defined.

GetFieldsWithAttribute<T>(Type, BindingFlags?)

Returns all fields in the type annotated with the given attribute.

public static IEnumerable<FieldInfo> GetFieldsWithAttribute<T>(this Type type, BindingFlags? flags = null) where T : Attribute

Parameters

type Type

Attribute to match.

flags BindingFlags?

Binding flags to match.

Returns

IEnumerable<FieldInfo>

Fields with the given attribute defined.

Type Parameters

T

Type to search.

GetGenericInterfaceType(Type, Type)

Gets the interface type from genericInterfaceType.

public static Type GetGenericInterfaceType(this Type type, Type genericInterfaceType)

Parameters

type Type

Type to inspect.

genericInterfaceType Type

Generic interface type to match.

Returns

Type

Exceptions

ArgumentException

type does not implement genericInterfaceType

GetMembersAndAttributes(Type, Type, BindingFlags?)

Returns all members and their respective attributes in the type annotated with the given attribute.

public static IEnumerable<(MemberInfo MemberInfo, Attribute[] Attributes)> GetMembersAndAttributes(this Type type, Type attrType, BindingFlags? flags = null)

Parameters

type Type

Type to search.

attrType Type

Attribute to match.

flags BindingFlags?

Binding flags to match.

Returns

IEnumerable<(MemberInfo MemberInfo, Attribute[] Attributes)>

Members with the given attribute defined, together with the respective attributes..

GetMembersAndAttributes<T>(Type, BindingFlags?)

Returns all members and their respective attributes in the type annotated with the given attribute.

public static IEnumerable<(MemberInfo MemberInfo, T[] Attributes)> GetMembersAndAttributes<T>(this Type type, BindingFlags? flags = null) where T : Attribute

Parameters

type Type

Attribute to match.

flags BindingFlags?

Binding flags to match.

Returns

IEnumerable<(MemberInfo MemberInfo, T[] Attributes)>

Members with the given attribute defined, together with the respective attributes..

Type Parameters

T

Type to search.

GetMembersWithAttribute(Type, Type, BindingFlags?)

Returns all members in the type annotated with the given attribute.

public static IEnumerable<MemberInfo> GetMembersWithAttribute(this Type type, Type attrType, BindingFlags? flags = null)

Parameters

type Type

Type to search.

attrType Type

Attribute to match.

flags BindingFlags?

Binding flags to match.

Returns

IEnumerable<MemberInfo>

Members with the given attribute defined.

GetMembersWithAttribute<T>(Type, BindingFlags?)

Returns all members in the type annotated with the given attribute.

public static IEnumerable<MemberInfo> GetMembersWithAttribute<T>(this Type type, BindingFlags? flags = null) where T : Attribute

Parameters

type Type

Attribute to match.

flags BindingFlags?

Binding flags to match.

Returns

IEnumerable<MemberInfo>

Members with the given attribute defined.

Type Parameters

T

Type to search.

GetMethodsAndAttributes(Type, Type, BindingFlags?)

Returns all methods and their respective attributes in the type annotated with the given attribute.

public static IEnumerable<(MethodInfo MethodInfo, Attribute[] Attributes)> GetMethodsAndAttributes(this Type type, Type attrType, BindingFlags? flags = null)

Parameters

type Type

Type to search.

attrType Type

Attribute to match.

flags BindingFlags?

Binding flags to match.

Returns

IEnumerable<(MethodInfo MethodInfo, Attribute[] Attributes)>

Methods with the given attribute defined, together with the respective attributes..

GetMethodsAndAttributes<T>(Type, BindingFlags?)

Returns all methods and their respective attributes in the type annotated with the given attribute.

public static IEnumerable<(MethodInfo MethodInfo, T[] Attributes)> GetMethodsAndAttributes<T>(this Type type, BindingFlags? flags = null) where T : Attribute

Parameters

type Type

Attribute to match.

flags BindingFlags?

Binding flags to match.

Returns

IEnumerable<(MethodInfo MethodInfo, T[] Attributes)>

Methods with the given attribute defined, together with the respective attributes..

Type Parameters

T

Type to search.

GetMethodsWithAttribute(Type, Type, BindingFlags?)

Returns all methods in the type annotated with the given attribute.

public static IEnumerable<MethodInfo> GetMethodsWithAttribute(this Type type, Type attrType, BindingFlags? flags = null)

Parameters

type Type

Type to search.

attrType Type

Attribute to match.

flags BindingFlags?

Binding flags to match.

Returns

IEnumerable<MethodInfo>

Methods with the given attribute defined.

GetMethodsWithAttribute<T>(Type, BindingFlags?)

Returns all methods in the type annotated with the given attribute.

public static IEnumerable<MethodInfo> GetMethodsWithAttribute<T>(this Type type, BindingFlags? flags = null) where T : Attribute

Parameters

type Type

Attribute to match.

flags BindingFlags?

Binding flags to match.

Returns

IEnumerable<MethodInfo>

Methods with the given attribute defined.

Type Parameters

T

Type to search.

GetPropertiesAndAttributes(Type, Type, BindingFlags?)

Returns all properties and their respective attributes in the type annotated with the given attribute.

public static IEnumerable<(PropertyInfo PropertyInfo, Attribute[] Attributes)> GetPropertiesAndAttributes(this Type type, Type attrType, BindingFlags? flags = null)

Parameters

type Type

Type to search.

attrType Type

Attribute to match.

flags BindingFlags?

Binding flags to match.

Returns

IEnumerable<(PropertyInfo PropertyInfo, Attribute[] Attributes)>

Properties with the given attribute defined, together with the respective attributes..

GetPropertiesAndAttributes<T>(Type, BindingFlags?)

Returns all properties and their respective attributes in the type annotated with the given attribute.

public static IEnumerable<(PropertyInfo PropertyInfo, T[] Attributes)> GetPropertiesAndAttributes<T>(this Type type, BindingFlags? flags = null) where T : Attribute

Parameters

type Type

Attribute to match.

flags BindingFlags?

Binding flags to match.

Returns

IEnumerable<(PropertyInfo PropertyInfo, T[] Attributes)>

Properties with the given attribute defined, together with the respective attributes..

Type Parameters

T

Type to search.

GetPropertiesWithAttribute(Type, Type, BindingFlags?)

Returns all properties in the type annotated with the given attribute.

public static IEnumerable<PropertyInfo> GetPropertiesWithAttribute(this Type type, Type attrType, BindingFlags? flags = null)

Parameters

type Type

Type to search.

attrType Type

Attribute to match.

flags BindingFlags?

Binding flags to match.

Returns

IEnumerable<PropertyInfo>

Properties with the given attribute defined.

GetPropertiesWithAttribute<T>(Type, BindingFlags?)

Returns all properties in the type annotated with the given attribute.

public static IEnumerable<PropertyInfo> GetPropertiesWithAttribute<T>(this Type type, BindingFlags? flags = null) where T : Attribute

Parameters

type Type

Attribute to match.

flags BindingFlags?

Binding flags to match.

Returns

IEnumerable<PropertyInfo>

Properties with the given attribute defined.

Type Parameters

T

Type to search.

TryGetGenericInterfaceType(Type, Type, out Type?)

Checks if type implements genericInterfaceType.

public static bool TryGetGenericInterfaceType(this Type type, Type genericInterfaceType, out Type? interfaceType)

Parameters

type Type

Type to inspect.

genericInterfaceType Type

Generic interface type to match.

interfaceType Type

Interface type if successfully matched, otherwise null.

Returns

bool

True if interface type successfully matched, otherwise false.

Exceptions

ArgumentException

genericInterfaceType is not a generic interface type.