MemberTypes Enumeración
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Marca cada tipo de miembro definido como una clase derivada de MemberInfo.
Esta enumeración admite una combinación bit a bit de sus valores de miembro.
public enum class MemberTypes
[System.Flags]
public enum MemberTypes
[System.Flags]
[System.Serializable]
public enum MemberTypes
[System.Flags]
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public enum MemberTypes
[<System.Flags>]
type MemberTypes =
[<System.Flags>]
[<System.Serializable>]
type MemberTypes =
[<System.Flags>]
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type MemberTypes =
Public Enum MemberTypes
- Herencia
- Atributos
Campos
| Nombre | Valor | Description |
|---|---|---|
| Constructor | 1 | Especifica que el miembro es un constructor. |
| Event | 2 | Especifica que el miembro es un evento. |
| Field | 4 | Especifica que el miembro es un campo. |
| Method | 8 | Especifica que el miembro es un método. |
| Property | 16 | Especifica que el miembro es una propiedad . |
| TypeInfo | 32 | Especifica que el miembro es un tipo. |
| Custom | 64 | Especifica que el miembro es un tipo de miembro personalizado. |
| NestedType | 128 | Especifica que el miembro es un tipo anidado. |
| All | 191 | Especifica todos los tipos de miembro. |
Ejemplos
En el ejemplo siguiente se muestran los nombres de los miembros de la ReflectionTypeLoadException clase y sus tipos de miembro asociados.
using System;
using System.Reflection;
class Example
{
public static void Main()
{
// Get the type of a chosen class.
Type t = typeof(ReflectionTypeLoadException);
// Get the MemberInfo array.
MemberInfo[] members = t.GetMembers();
// Get and display the name and the MemberType for each member.
Console.WriteLine("Members of {0}", t.Name);
foreach (var member in members) {
MemberTypes memberType = member.MemberType;
Console.WriteLine(" {0}: {1}", member.Name, memberType);
}
}
}
// The example displays the following output:
// Members of ReflectionTypeLoadException
// get_Types: Method
// get_LoaderExceptions: Method
// GetObjectData: Method
// get_Message: Method
// get_Data: Method
// GetBaseException: Method
// get_InnerException: Method
// get_TargetSite: Method
// get_StackTrace: Method
// get_HelpLink: Method
// set_HelpLink: Method
// get_Source: Method
// set_Source: Method
// ToString: Method
// get_HResult: Method
// GetType: Method
// Equals: Method
// GetHashCode: Method
// GetType: Method
// .ctor: Constructor
// .ctor: Constructor
// Types: Property
// LoaderExceptions: Property
// Message: Property
// Data: Property
// InnerException: Property
// TargetSite: Property
// StackTrace: Property
// HelpLink: Property
// Source: Property
// HResult: Property
Imports System.Reflection
Module Example
Public Sub Main()
' Get the type of a particular class.
Dim t As Type = GetType(ReflectionTypeLoadException)
' Get the MemberInfo array.
Dim members As MemberInfo() = t.GetMembers()
' Get and display the name and the MemberType for each member.
Console.WriteLine("Members of {0}", t.Name)
For Each member In members
Dim memberType As MemberTypes = member.MemberType
Console.WriteLine(" {0}: {1}", member.Name, memberType)
Next
End Sub
End Module
' The example displays the following output:
' Members of ReflectionTypeLoadException
' get_Types: Method
' get_LoaderExceptions: Method
' GetObjectData: Method
' get_Message: Method
' get_Data: Method
' GetBaseException: Method
' get_InnerException: Method
' get_TargetSite: Method
' get_StackTrace: Method
' get_HelpLink: Method
' set_HelpLink: Method
' get_Source: Method
' set_Source: Method
' ToString: Method
' get_HResult: Method
' GetType: Method
' Equals: Method
' GetHashCode: Method
' GetType: Method
' .ctor: Constructor
' .ctor: Constructor
' Types: Property
' LoaderExceptions: Property
' Message: Property
' Data: Property
' InnerException: Property
' TargetSite: Property
' StackTrace: Property
' HelpLink: Property
' Source: Property
' HResult: Property
Comentarios
Estas propiedades devuelven estos valores de enumeración:
Para obtener el MemberTypes valor de un tipo:
Obtiene un Type objeto que representa ese tipo.
Recupere el valor de la Type.MemberType propiedad .
Para obtener los MemberTypes valores de los miembros de un tipo.
Obtiene un Type objeto que representa ese tipo.
Recupere la MemberInfo matriz que representa los miembros de ese tipo llamando al Type.GetMembers método .
Recupere el valor de la propiedad From MemberInfo.MemberType para cada miembro de la matriz. Normalmente se usa una
switchinstrucción en C# oSelect Caseinstrucción en Visual Basic para procesar los tipos de miembro.
MemberTypes coincide con CorTypeAttr tal como se define en el archivo corhdr.h.