This topic has not yet been rated - Rate this topic

MemberInfo Class

April 12, 2014

Obtains information about the attributes of a member and provides access to member metadata.

Namespace:  System.Reflection
Assembly:  mscorlib (in mscorlib.dll)
public abstract class MemberInfo : ICustomAttributeProvider

The MemberInfo type exposes the following members.

  NameDescription
Public propertyCustomAttributesGets a collection that contains this member's custom attributes.
Public propertyDeclaringTypeGets the class that declares this member.
Public propertyMemberTypeWhen overridden in a derived class, gets a MemberTypes value indicating the type of the member — method, constructor, event, and so on.
Public propertyMetadataTokenGets a value that identifies a metadata element.
Public propertyModuleGets the module in which the type that declares the member represented by the current MemberInfo is defined.
Public propertyNameGets the name of the current member.
Public propertyReflectedTypeGets the class object that was used to obtain this instance of MemberInfo.
Top
  NameDescription
Public methodEqualsReturns a value that indicates whether this instance is equal to a specified object. (Overrides Object.Equals(Object).)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetCustomAttributes(Boolean)When overridden in a derived class, returns an array of all custom attributes applied to this member.
Public methodGetCustomAttributes(Type, Boolean)When overridden in a derived class, returns an array of custom attributes applied to this member and identified by Type.
Public methodGetHashCodeReturns the hash code for this instance. (Overrides Object.GetHashCode().)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodIsDefinedWhen overridden in a derived class, indicates whether one or more attributes of the specified type or of its derived types is applied to this member.
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top
  NameDescription
Public Extension MethodGetCustomAttribute(Type)Overloaded. Retrieves a custom attribute of a specified type that is applied to a specified member. (Defined by CustomAttributeExtensions.)
Public Extension MethodGetCustomAttribute(Type, Boolean)Overloaded. Retrieves a custom attribute of a specified type that is applied to a specified member, and optionally inspects the ancestors of that member. (Defined by CustomAttributeExtensions.)
Public Extension MethodGetCustomAttribute<T>()Overloaded. Retrieves a custom attribute of a specified type that is applied to a specified member. (Defined by CustomAttributeExtensions.)
Public Extension MethodGetCustomAttribute<T>(Boolean)Overloaded. Retrieves a custom attribute of a specified type that is applied to a specified member, and optionally inspects the ancestors of that member. (Defined by CustomAttributeExtensions.)
Public Extension MethodGetCustomAttributes()Overloaded. Retrieves a collection of custom attributes that are applied to a specified member. (Defined by CustomAttributeExtensions.)
Public Extension MethodGetCustomAttributes(Type)Overloaded. Retrieves a collection of custom attributes of a specified type that are applied to a specified member. (Defined by CustomAttributeExtensions.)
Public Extension MethodGetCustomAttributes<T>()Overloaded. Retrieves a collection of custom attributes of a specified type that are applied to a specified member. (Defined by CustomAttributeExtensions.)
Public Extension MethodGetCustomAttributes<T>(Boolean)Overloaded. Retrieves a collection of custom attributes of a specified type that are applied to a specified member, and optionally inspects the ancestors of that member. (Defined by CustomAttributeExtensions.)
Public Extension MethodIsDefinedIndicates whether custom attributes of a specified type are applied to a specified member. (Defined by CustomAttributeExtensions.)
Top

The MemberInfo class is the abstract base class for classes used to obtain information about all members of a class (constructors, events, fields, methods, and properties).

This class introduces the basic functionality that all members provide.

In Windows Phone apps, you cannot derive new types from MemberInfo.

The following example displays the member name and type of a specified class.


using System;
using System.Reflection;

class Example
{
   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      // Get the Type and MemberInfo.
      Type MyType = typeof(System.Threading.Thread);

      // Display the MemberType and the member.
      outputBlock.Text += String.Format("There are {0} members in {1}:\n", 
         MyType.GetMembers().Length, MyType.FullName);

      foreach (MemberInfo mi in MyType.GetMembers())
      {
         outputBlock.Text += String.Format("  {0} - {1}\n",
            mi.MemberType, mi);
      }
   }
}


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

This type is thread safe.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.