MemberInfo

MemberInfo Class

Represents a member of a type (field, method, property, event, or constructor) and provides methods for determining its attributes and obtaining information about it.

Namespace: System.Reflection

Assembly: System.Runtime

Inheritance: ObjectMemberInfo

Overview
Members
Syntax

Overview

The MemberInfo class is an abstract base class for all type members in the .NET Framework. It provides a unified way to access common information about members, such as their name, attributes, and declaring type.

You typically do not instantiate MemberInfo directly. Instead, you obtain instances of derived classes such as MethodInfo, PropertyInfo, FieldInfo, and EventInfo through reflection methods on a Type object.

Key properties and methods available through MemberInfo include:

MemberInfo is fundamental to dynamic code analysis and manipulation in .NET.

Public Properties

DeclaringType
Type? DeclaringType { get; }
Gets the class that declares the member.
Name
string Name { get; }
Gets the name of the member.
ReflectedType
Type? ReflectedType { get; }
Gets the class that is viewed in this reflection-only view and that contains the member represented by the descriptor.
MemberType
MemberTypes MemberType { get; }
Gets a MemberTypes value that indicates the type of member.

Public Methods

GetCustomAttributes
object[] GetCustomAttributes(bool inherit)
Gets a collection of custom attributes applied to this member, and optionally filters them.
GetCustomAttributes
object[] GetCustomAttributes(Type attributeType, bool inherit)
Gets a collection of custom attributes applied to this member, filtered by type, and optionally filters them.
IsDefined
bool IsDefined(Type attributeType, bool inherit)
Determines whether the specified custom attribute is applied to this member.

Protected Methods

ToString
string ToString()
Overrides the base ToString method to return the qualified name of the member.

Syntax

public abstract class MemberInfo : ICustomAttributeProvider, IEquatable<MemberInfo>
{
    // Properties
    public abstract Type? DeclaringType { get; }
    public abstract string Name { get; }
    public abstract Type? ReflectedType { get; }
    public abstract MemberTypes MemberType { get; }

    // Methods
    public abstract object[] GetCustomAttributes(bool inherit);
    public abstract object[] GetCustomAttributes(Type attributeType, bool inherit);
    public abstract bool IsDefined(Type attributeType, bool inherit);

    // Protected Methods
    protected virtual string ToString();
}