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: Object → MemberInfo
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:
Name
: Gets the simple name of the member.DeclaringType
: Gets the type that declares this member.ReflectedType
: Gets the type from which the current MemberInfo object was obtained.GetCustomAttributes(Type, bool)
: Returns an enumerated list of custom attributes of the specified type that are directly applied to this member, or a specified number of base class elements.IsDefined(Type, bool)
: Indicates whether one or more instances of specified attributes are applied to this member.
MemberInfo
is fundamental to dynamic code analysis and manipulation in .NET.
Public Properties
Type? DeclaringType { get; }
string Name { get; }
Type? ReflectedType { get; }
MemberTypes MemberType { get; }
Public Methods
object[] GetCustomAttributes(bool inherit)
object[] GetCustomAttributes(Type attributeType, bool inherit)
bool IsDefined(Type attributeType, bool inherit)
Protected Methods
string ToString()
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();
}