Table of Contents

Class MemberInfoExtensions

Namespace
LfrlAnvil.Extensions
Assembly
LfrlAnvil.Core.dll

Contains MemberInfo extension methods.

public static class MemberInfoExtensions
Inheritance
MemberInfoExtensions
Inherited Members

Methods

GetAttribute(MemberInfo, Type, bool)

Attempts to retrieve an attribute of the specified type from the given member.

[Pure]
public static Attribute? GetAttribute(this MemberInfo member, Type attributeType, bool inherit = true)

Parameters

member MemberInfo

Member to retrieve an attribute from.

attributeType Type

Type of an Attribute to search for.

inherit bool

Specifies whether or not to include member's ancestors in the search. Equal to true by default.

Returns

Attribute

Found attribute's instance or null, if it does not exist.

Remarks

GetAttributeRange(MemberInfo, Type, bool)

Attempts to retrieve all attributes of the specified type from the given member.

[Pure]
public static Attribute[] GetAttributeRange(this MemberInfo member, Type attributeType, bool inherit = true)

Parameters

member MemberInfo

Member to retrieve attributes from.

attributeType Type

Type of an Attribute to search for.

inherit bool

Specifies whether or not to include member's ancestors in the search. Equal to true by default.

Returns

Attribute[]

All found attribute's instances or an empty array, if it does not exist.

Remarks

GetAttributeRange<T>(MemberInfo, bool)

Attempts to retrieve all attributes of the specified type from the given member.

[Pure]
public static IEnumerable<T> GetAttributeRange<T>(this MemberInfo member, bool inherit = true) where T : Attribute

Parameters

member MemberInfo

Member to retrieve attributes from.

inherit bool

Specifies whether or not to include member's ancestors in the search. Equal to true by default.

Returns

IEnumerable<T>

All found attribute's instances or an empty array, if it does not exist.

Type Parameters

T

Type of an Attribute to search for.

Remarks

GetAttribute<T>(MemberInfo, bool)

Attempts to retrieve an attribute of the specified type from the given member.

[Pure]
public static T? GetAttribute<T>(this MemberInfo member, bool inherit = true) where T : Attribute

Parameters

member MemberInfo

Member to retrieve an attribute from.

inherit bool

Specifies whether or not to include member's ancestors in the search. Equal to true by default.

Returns

T

Found attribute's instance or null, if it does not exist.

Type Parameters

T

Type of an Attribute to search for.

Remarks

HasAttribute(MemberInfo, Type, bool)

Checks if an attribute of the specified type exists for the given member.

[Pure]
public static bool HasAttribute(this MemberInfo member, Type attributeType, bool inherit = true)

Parameters

member MemberInfo

Member to check.

attributeType Type

Type of an Attribute to search for.

inherit bool

Specifies whether or not to include member's ancestors in the search. Equal to true by default.

Returns

bool

true when an attribute of the specified type exists for the given member, otherwise false.

Remarks

See IsDefined(MemberInfo, Type, bool) for more information.

HasAttribute<T>(MemberInfo, bool)

Checks if an attribute of the specified type exists for the given member.

[Pure]
public static bool HasAttribute<T>(this MemberInfo member, bool inherit = true) where T : Attribute

Parameters

member MemberInfo

Member to check.

inherit bool

Specifies whether or not to include member's ancestors in the search. Equal to true by default.

Returns

bool

true when an attribute of the specified type exists for the given member, otherwise false.

Type Parameters

T

Type of an Attribute to search for.

Remarks

See IsDefined(MemberInfo, Type, bool) for more information.

TryAsConstructor(MemberInfo)

Attempts to cast the given member to ConstructorInfo type.

[Pure]
public static ConstructorInfo? TryAsConstructor(this MemberInfo member)

Parameters

member MemberInfo

Member to cast.

Returns

ConstructorInfo

Member cast to ConstructorInfo or null, if it is not an instance of that type.

TryAsEvent(MemberInfo)

Attempts to cast the given member to EventInfo type.

[Pure]
public static EventInfo? TryAsEvent(this MemberInfo member)

Parameters

member MemberInfo

Member to cast.

Returns

EventInfo

Member cast to EventInfo or null, if it is not an instance of that type.

TryAsField(MemberInfo)

Attempts to cast the given member to FieldInfo type.

[Pure]
public static FieldInfo? TryAsField(this MemberInfo member)

Parameters

member MemberInfo

Member to cast.

Returns

FieldInfo

Member cast to FieldInfo or null, if it is not an instance of that type.

TryAsMethod(MemberInfo)

Attempts to cast the given member to MethodInfo type.

[Pure]
public static MethodInfo? TryAsMethod(this MemberInfo member)

Parameters

member MemberInfo

Member to cast.

Returns

MethodInfo

Member cast to MethodInfo or null, if it is not an instance of that type.

TryAsProperty(MemberInfo)

Attempts to cast the given member to PropertyInfo type.

[Pure]
public static PropertyInfo? TryAsProperty(this MemberInfo member)

Parameters

member MemberInfo

Member to cast.

Returns

PropertyInfo

Member cast to PropertyInfo or null, if it is not an instance of that type.

TryAsType(MemberInfo)

Attempts to cast the given member to Type type.

[Pure]
public static Type? TryAsType(this MemberInfo member)

Parameters

member MemberInfo

Member to cast.

Returns

Type

Member cast to Type or null, if it is not an instance of that type.