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
MemberInfoMember to retrieve an attribute from.
attributeType
TypeType of an Attribute to search for.
inherit
boolSpecifies 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
See GetCustomAttribute(MemberInfo, Type, bool) for more information.
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
MemberInfoMember to retrieve attributes from.
attributeType
TypeType of an Attribute to search for.
inherit
boolSpecifies 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
See GetCustomAttributes(MemberInfo, Type, bool) for more information.
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
MemberInfoMember to retrieve attributes from.
inherit
boolSpecifies 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
See GetCustomAttributes(MemberInfo, Type, bool) for more information.
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
MemberInfoMember to retrieve an attribute from.
inherit
boolSpecifies 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
See GetCustomAttribute(MemberInfo, Type, bool) for more information.
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
MemberInfoMember to check.
attributeType
TypeType of an Attribute to search for.
inherit
boolSpecifies 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
MemberInfoMember to check.
inherit
boolSpecifies 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
MemberInfoMember 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
MemberInfoMember to cast.
Returns
TryAsField(MemberInfo)
Attempts to cast the given member
to FieldInfo type.
[Pure]
public static FieldInfo? TryAsField(this MemberInfo member)
Parameters
member
MemberInfoMember to cast.
Returns
TryAsMethod(MemberInfo)
Attempts to cast the given member
to MethodInfo type.
[Pure]
public static MethodInfo? TryAsMethod(this MemberInfo member)
Parameters
member
MemberInfoMember 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
MemberInfoMember 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
MemberInfoMember to cast.