Show / Hide Table of Contents

Class MemberInfoExtensions

Includes various extensions for the MemberInfo class.

Inheritance
object
MemberInfoExtensions
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: TheXDS.MCART.Types.Extensions
Assembly: MCART.dll
Syntax
public static class MemberInfoExtensions

Methods

| Edit this page View Source

GetAttribute<T>(MemberInfo)

Returns the attribute associated with the declaration of the specified object.

Declaration
public static T? GetAttribute<T>(this MemberInfo member) where T : Attribute
Parameters
Type Name Description
MemberInfo member

The member from which to extract the attribute.

Returns
Type Description
T

An attribute of the type T with the data associated in the declaration of the member; or null if the specified attribute is not found.

Type Parameters
Name Description
T

Type of attribute to return. Must inherit Attribute.

Exceptions
Type Condition
ArgumentNullException

Thrown if member is null.

| Edit this page View Source

GetAttributes<T>(MemberInfo)

Returns the attribute associated with the assembly specified.

Declaration
public static IEnumerable<T> GetAttributes<T>(this MemberInfo member) where T : Attribute
Parameters
Type Name Description
MemberInfo member

MemberInfo from which to extract the attribute.

Returns
Type Description
IEnumerable<T>

An attribute of the type T with the data associated in the declaration of the assembly; or null if the specified attribute is not found.

Type Parameters
Name Description
T

Type of attribute to return. Must inherit Attribute.

Exceptions
Type Condition
ArgumentNullException

Thrown if member is null.

| Edit this page View Source

HasAttrValue<TAttribute, TValue>(MemberInfo, out TValue)

Determines if a member has a defined attribute.

Declaration
public static bool HasAttrValue<TAttribute, TValue>(this MemberInfo member, out TValue value) where TAttribute : Attribute, IValueAttribute<TValue>
Parameters
Type Name Description
MemberInfo member

The member from which to extract the attribute.

TValue value

Output parameter. If an attribute of type TAttribute has been found, the value of the same is returned. It will be returned as default if the member does not have the specified attribute.

Returns
Type Description
bool

true if the member has the attribute, false otherwise.

Type Parameters
Name Description
TAttribute

Type of attribute to return. Must inherit from Attribute and from IValueAttribute<T>

TValue

Type of value to return.

| Edit this page View Source

HasAttribute<T>(MemberInfo)

Determines if a member has a defined attribute.

Declaration
public static bool HasAttribute<T>(this MemberInfo member) where T : Attribute
Parameters
Type Name Description
MemberInfo member

The member from which to extract the attribute.

Returns
Type Description
bool

true if the member has the attribute, false otherwise.

Type Parameters
Name Description
T

Type of attribute to return. Must inherit Attribute.

| Edit this page View Source

HasAttribute<T>(MemberInfo, out T?)

Determines if a member has a defined attribute.

Declaration
public static bool HasAttribute<T>(this MemberInfo member, out T? attribute) where T : notnull, Attribute
Parameters
Type Name Description
MemberInfo member

The member from which to extract the attribute.

T attribute

Output parameter. If an attribute of type T has been found, it is returned. It will be returned as null if the member does not have the specified attribute.

Returns
Type Description
bool

true if the member has the attribute, false otherwise.

Type Parameters
Name Description
T

Type of attribute to return. Must inherit Attribute.

| Edit this page View Source

HasAttributes<T>(MemberInfo, out IEnumerable<T>)

Determines if a member has a defined attribute.

Declaration
public static bool HasAttributes<T>(this MemberInfo member, out IEnumerable<T> attribute) where T : Attribute
Parameters
Type Name Description
MemberInfo member

The member from which to extract the attribute.

IEnumerable<T> attribute

Output parameter. If an attribute of type T has been found, it is returned. It will be returned as null if the member does not have the specified attribute.

Returns
Type Description
bool

true if the member has the attribute, false otherwise.

Type Parameters
Name Description
T

Type of attribute to return. Must inherit Attribute.

| Edit this page View Source

NameOf(MemberInfo)

Gets a friendly name for a member.

Declaration
public static string NameOf(this MemberInfo member)
Parameters
Type Name Description
MemberInfo member

The MemberInfo from which to get the name.

Returns
Type Description
string

A friendly name for member, or the name defined for member if a friendly name has not been defined using the NameAttribute attribute.

  • Edit this page
  • View Source
In this article
Back to top Generated by DocFX