Поделиться через


MemberInfo Class

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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

Inheritance Hierarchy

System.Object
  System.Reflection.MemberInfo
    System.Reflection.EventInfo
    System.Reflection.FieldInfo
    System.Reflection.MethodBase
    System.Reflection.PropertyInfo
    System.Type

Namespace:  System.Reflection
Assembly:  mscorlib (in mscorlib.dll)

Syntax

'Declaration
<ClassInterfaceAttribute(ClassInterfaceType.None)> _
<ComVisibleAttribute(True)> _
Public MustInherit Class MemberInfo _
    Implements ICustomAttributeProvider
[ClassInterfaceAttribute(ClassInterfaceType.None)]
[ComVisibleAttribute(true)]
public abstract class MemberInfo : ICustomAttributeProvider

The MemberInfo type exposes the following members.

Constructors

  Name Description
Protected method MemberInfo Initializes a new instance of the MemberInfo class.

Top

Properties

  Name Description
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 DeclaringType Gets the class that declares this member.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 MemberType When overridden in a derived class, gets a MemberTypes value indicating the type of the member — method, constructor, event, and so on.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 MetadataToken Gets a value that identifies a metadata element.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 Module Gets the module in which the type that declares the member represented by the current MemberInfo is defined.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 Name Gets the name of the current member.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 ReflectedType Gets the class object that was used to obtain this instance of MemberInfo.

Top

Methods

  Name Description
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 Finalize Allows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 GetCustomAttributes(Boolean) When overridden in a derived class, returns an array of all custom attributes applied to this member.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 GetCustomAttributes(Type, Boolean) When overridden in a derived class, returns an array of custom attributes applied to this member and identified by Type.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 GetType Gets the Type of the current instance. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 IsDefined When 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 methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 ToString Returns a string that represents the current object. (Inherited from Object.)

Top

Remarks

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 Silverlight-based applications, you cannot derive new types from MemberInfo.

Examples

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

Imports System.Reflection

Class Example

   Public Shared Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock) 

      ' Get the Type and MemberInfo.
      Dim MyType As Type = GetType(System.Threading.Thread)

      ' Display the MemberType and the member.
      outputBlock.Text &= String.Format("There are {0} members in {1}:" & vbLf, _
         MyType.GetMembers().Length, MyType.FullName)

      For Each mi As MemberInfo In MyType.GetMembers()
         outputBlock.Text &= String.Format("  {0} - {1}" & vbLf, _
            mi.MemberType, mi)
      Next 

   End Sub
End 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);
      }
   }
}

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Thread Safety

This type is thread safe.

See Also

Reference