FieldInfo Clase
Definición
Detecta los atributos de un campo y proporciona acceso a sus metadatos.Discovers the attributes of a field and provides access to field metadata.
public ref class FieldInfo abstract : System::Reflection::MemberInfo
public ref class FieldInfo abstract : System::Reflection::MemberInfo, System::Runtime::InteropServices::_FieldInfo
public abstract class FieldInfo : System.Reflection.MemberInfo
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)]
[System.Serializable]
public abstract class FieldInfo : System.Reflection.MemberInfo, System.Runtime.InteropServices._FieldInfo
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)]
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public abstract class FieldInfo : System.Reflection.MemberInfo, System.Runtime.InteropServices._FieldInfo
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)]
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public abstract class FieldInfo : System.Reflection.MemberInfo
type FieldInfo = class
inherit MemberInfo
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)>]
[<System.Serializable>]
type FieldInfo = class
inherit MemberInfo
interface _FieldInfo
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)>]
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type FieldInfo = class
inherit MemberInfo
interface _FieldInfo
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)>]
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type FieldInfo = class
inherit MemberInfo
Public MustInherit Class FieldInfo
Inherits MemberInfo
Public MustInherit Class FieldInfo
Inherits MemberInfo
Implements _FieldInfo
- Herencia
- Derivado
- Atributos
- Implementaciones
Ejemplos
En el ejemplo siguiente se usa el Type.GetFields método para obtener la información relacionada con el campo de la FieldInfo clase y, a continuación, se muestran los atributos de campo.The following example uses the Type.GetFields method to get the field-related information from the FieldInfo class, and then displays field attributes.
using namespace System;
using namespace System::Reflection;
public ref class FieldInfoClass
{
public:
int myField1;
protected:
String^ myField2;
};
int main()
{
array<FieldInfo^>^myFieldInfo;
Type^ myType = FieldInfoClass::typeid;
// Get the type and fields of FieldInfoClass.
myFieldInfo = myType->GetFields( static_cast<BindingFlags>(BindingFlags::NonPublic | BindingFlags::Instance | BindingFlags::Public) );
Console::WriteLine( "\nThe fields of FieldInfoClass are \n" );
// Display the field information of FieldInfoClass.
for ( int i = 0; i < myFieldInfo->Length; i++ )
{
Console::WriteLine( "\nName : {0}", myFieldInfo[ i ]->Name );
Console::WriteLine( "Declaring Type : {0}", myFieldInfo[ i ]->DeclaringType );
Console::WriteLine( "IsPublic : {0}", myFieldInfo[ i ]->IsPublic );
Console::WriteLine( "MemberType : {0}", myFieldInfo[ i ]->MemberType );
Console::WriteLine( "FieldType : {0}", myFieldInfo[ i ]->FieldType );
Console::WriteLine( "IsFamily : {0}", myFieldInfo[ i ]->IsFamily );
}
}
using System;
using System.Reflection;
public class FieldInfoClass
{
public int myField1 = 0;
protected string myField2 = null;
public static void Main()
{
FieldInfo[] myFieldInfo;
Type myType = typeof(FieldInfoClass);
// Get the type and fields of FieldInfoClass.
myFieldInfo = myType.GetFields(BindingFlags.NonPublic | BindingFlags.Instance
| BindingFlags.Public);
Console.WriteLine("\nThe fields of " +
"FieldInfoClass are \n");
// Display the field information of FieldInfoClass.
for(int i = 0; i < myFieldInfo.Length; i++)
{
Console.WriteLine("\nName : {0}", myFieldInfo[i].Name);
Console.WriteLine("Declaring Type : {0}", myFieldInfo[i].DeclaringType);
Console.WriteLine("IsPublic : {0}", myFieldInfo[i].IsPublic);
Console.WriteLine("MemberType : {0}", myFieldInfo[i].MemberType);
Console.WriteLine("FieldType : {0}", myFieldInfo[i].FieldType);
Console.WriteLine("IsFamily : {0}", myFieldInfo[i].IsFamily);
}
}
}
Imports System.Reflection
Public Class FieldInfoClass
Public myField1 As Integer = 0
Protected myField2 As String = Nothing
Public Shared Sub Main()
Dim myFieldInfo() As FieldInfo
Dim myType As Type = GetType(FieldInfoClass)
' Get the type and fields of FieldInfoClass.
myFieldInfo = myType.GetFields(BindingFlags.NonPublic Or _
BindingFlags.Instance Or BindingFlags.Public)
Console.WriteLine(ControlChars.NewLine & "The fields of " & _
"FieldInfoClass class are " & ControlChars.NewLine)
' Display the field information of FieldInfoClass.
Dim i As Integer
For i = 0 To myFieldInfo.Length - 1
Console.WriteLine(ControlChars.NewLine + "Name : {0}", myFieldInfo(i).Name)
Console.WriteLine("Declaring Type : {0}", myFieldInfo(i).DeclaringType)
Console.WriteLine("IsPublic : {0}", myFieldInfo(i).IsPublic)
Console.WriteLine("MemberType : {0}", myFieldInfo(i).MemberType)
Console.WriteLine("FieldType : {0}", myFieldInfo(i).FieldType)
Console.WriteLine("IsFamily : {0}", myFieldInfo(i).IsFamily)
Next i
End Sub
End Class
Comentarios
La información del campo se obtiene de los metadatos.The field information is obtained from metadata. La FieldInfo clase no tiene un constructor público.The FieldInfo class does not have a public constructor. FieldInfo los objetos se obtienen llamando al GetFields método o GetField de un Type
objeto.FieldInfo objects are obtained by calling either the GetFields or GetField method of a Type
object.
Los campos son variables definidas en la clase.Fields are variables defined in the class. FieldInfo proporciona acceso a los metadatos de un campo dentro de una clase y proporciona la funcionalidad de set y Get dinámica para el campo.FieldInfo provides access to the metadata for a field within a class and provides dynamic set and get functionality for the field. La clase no se carga en memoria hasta que se llama a Invoke o get en el objeto.The class is not loaded into memory until invoke or get is called on the object.
Notas a los implementadores
Al heredar de FieldInfo, es necesario reemplazar los miembros siguientes: GetValue(Object) y SetValue(Object, Object, BindingFlags, Binder, CultureInfo).When you inherit from FieldInfo, you must override the following members: GetValue(Object) and SetValue(Object, Object, BindingFlags, Binder, CultureInfo).
Constructores
FieldInfo() |
Inicializa una nueva instancia de la clase |
Propiedades
Attributes |
Obtiene los atributos asociados a este campo.Gets the attributes associated with this field. |
CustomAttributes |
Obtiene una colección que contiene los atributos personalizados de este miembro.Gets a collection that contains this member's custom attributes. (Heredado de MemberInfo) |
DeclaringType |
Obtiene la clase que declara este miembro.Gets the class that declares this member. (Heredado de MemberInfo) |
FieldHandle |
Obtiene una estructura |
FieldType |
Obtiene el tipo de este objeto de campo.Gets the type of this field object. |
IsAssembly |
Obtiene un valor que indica si Assembly describe la visibilidad posible de este campo; es decir, el campo es visible como mucho para otros tipos del mismo ensamblado y no es visible para los tipos derivados fuera del ensamblado.Gets a value indicating whether the potential visibility of this field is described by Assembly; that is, the field is visible at most to other types in the same assembly, and is not visible to derived types outside the assembly. |
IsCollectible |
Obtiene un valor que indica si este objeto MemberInfo forma parte de un ensamblado contenido en un AssemblyLoadContext recopilable.Gets a value that indicates whether this MemberInfo object is part of an assembly held in a collectible AssemblyLoadContext. (Heredado de MemberInfo) |
IsFamily |
Obtiene un valor que indica si Family describe la visibilidad de este campo; es decir, el campo sólo es visible dentro de su clase y clases derivadas.Gets a value indicating whether the visibility of this field is described by Family; that is, the field is visible only within its class and derived classes. |
IsFamilyAndAssembly |
Obtiene un valor que indica si FamANDAssem describe la visibilidad de este campo; es decir, se puede tener acceso al campo desde clases derivadas, pero sólo si están en el mismo ensamblado.Gets a value indicating whether the visibility of this field is described by FamANDAssem; that is, the field can be accessed from derived classes, but only if they are in the same assembly. |
IsFamilyOrAssembly |
Obtiene un valor que indica si FamORAssem describe la visibilidad posible de este campo; es decir, las clases derivadas pueden tener acceso al campo con independencia de dónde se encuentren, así como las clases del mismo ensamblado.Gets a value indicating whether the potential visibility of this field is described by FamORAssem; that is, the field can be accessed by derived classes wherever they are, and by classes in the same assembly. |
IsInitOnly |
Obtiene un valor que indica si el campo sólo se puede establecer en el cuerpo del constructor.Gets a value indicating whether the field can only be set in the body of the constructor. |
IsLiteral |
Obtiene un valor que indica si el valor se escribe en tiempo de compilación y no puede cambiarse.Gets a value indicating whether the value is written at compile time and cannot be changed. |
IsNotSerialized |
Obtiene un valor que indica si este campo dispone del atributo |
IsPinvokeImpl |
Obtiene un valor que indica si el atributo |
IsPrivate |
Obtiene un valor que indica si el campo es privado.Gets a value indicating whether the field is private. |
IsPublic |
Obtiene un valor que indica si el campo es público.Gets a value indicating whether the field is public. |
IsSecurityCritical |
Obtiene un valor que indica si el campo actual es crítico para la seguridad o crítico para la seguridad y disponible desde código transparente en el nivel de confianza actual.Gets a value that indicates whether the current field is security-critical or security-safe-critical at the current trust level. |
IsSecuritySafeCritical |
Obtiene un valor que indica si el campo actual es crítico para la seguridad y disponible desde código transparente en el nivel de confianza actual.Gets a value that indicates whether the current field is security-safe-critical at the current trust level. |
IsSecurityTransparent |
Obtiene un valor que indica si el campo actual es transparente en el nivel de confianza actual.Gets a value that indicates whether the current field is transparent at the current trust level. |
IsSpecialName |
Obtiene un valor que indica si el atributo |
IsStatic |
Obtiene un valor que indica si el campo es estático.Gets a value indicating whether the field is static. |
MemberType |
Obtiene un valor de MemberTypes que indica que este miembro es un campo.Gets a MemberTypes value indicating that this member is a field. |
MemberType |
Cuando se invalida en una clase derivada, obtiene un valor MemberTypes que indica el tipo de miembro: método, constructor, evento, etc.When overridden in a derived class, gets a MemberTypes value indicating the type of the member - method, constructor, event, and so on. (Heredado de MemberInfo) |
MetadataToken |
Obtiene un valor que identifica un elemento de metadatos.Gets a value that identifies a metadata element. (Heredado de MemberInfo) |
Module |
Obtiene el módulo en el que el tipo que declara el miembro representado por el objeto MemberInfo actual está definido.Gets the module in which the type that declares the member represented by the current MemberInfo is defined. (Heredado de MemberInfo) |
Name |
Obtiene el nombre del miembro actual.Gets the name of the current member. (Heredado de MemberInfo) |
ReflectedType |
Obtiene el objeto de la clase utilizado para obtener esta instancia de |
Métodos
Equals(Object) |
Devuelve un valor que indica si esta instancia es igual que un objeto especificado.Returns a value that indicates whether this instance is equal to a specified object. |
Equals(Object) |
Devuelve un valor que indica si esta instancia es igual que un objeto especificado.Returns a value that indicates whether this instance is equal to a specified object. (Heredado de MemberInfo) |
GetCustomAttributes(Boolean) |
Cuando se reemplaza en una clase derivada, devuelve una matriz de todos los atributos personalizados aplicados a este miembro.When overridden in a derived class, returns an array of all custom attributes applied to this member. (Heredado de MemberInfo) |
GetCustomAttributes(Type, Boolean) |
Cuando se invalida en una clase derivada, devuelve una matriz de atributos personalizados aplicados a este miembro e identificado por Type.When overridden in a derived class, returns an array of custom attributes applied to this member and identified by Type. (Heredado de MemberInfo) |
GetCustomAttributesData() |
Devuelve una lista de objetos CustomAttributeData que representan datos sobre los atributos que se aplicaron al miembro de destino.Returns a list of CustomAttributeData objects representing data about the attributes that have been applied to the target member. (Heredado de MemberInfo) |
GetFieldFromHandle(RuntimeFieldHandle) |
Obtiene FieldInfo para el campo representado por el identificador especificado.Gets a FieldInfo for the field represented by the specified handle. |
GetFieldFromHandle(RuntimeFieldHandle, RuntimeTypeHandle) |
Obtiene FieldInfo para el campo representado por el identificador especificado, para el tipo genérico especificado.Gets a FieldInfo for the field represented by the specified handle, for the specified generic type. |
GetHashCode() |
Devuelve el código hash de esta instancia.Returns the hash code for this instance. |
GetHashCode() |
Devuelve el código hash de esta instancia.Returns the hash code for this instance. (Heredado de MemberInfo) |
GetOptionalCustomModifiers() |
Obtiene una matriz de tipos que identifican los modificadores personalizados opcionales del campo.Gets an array of types that identify the optional custom modifiers of the field. |
GetRawConstantValue() |
Devuelve un valor literal asociado al campo mediante un compilador.Returns a literal value associated with the field by a compiler. |
GetRequiredCustomModifiers() |
Obtiene una matriz de tipos que identifican los modificadores personalizados necesarios de la propiedad.Gets an array of types that identify the required custom modifiers of the property. |
GetType() |
Detecta los atributos de un campo de clase y proporciona acceso a sus metadatos.Discovers the attributes of a class field and provides access to field metadata. |
GetType() |
Detecta los atributos de un miembro y proporciona acceso a sus metadatos.Discovers the attributes of a member and provides access to member metadata. (Heredado de MemberInfo) |
GetValue(Object) |
Cuando se reemplaza en una clase derivada, devuelve el valor de un campo compatible con un objeto concreto.When overridden in a derived class, returns the value of a field supported by a given object. |
GetValueDirect(TypedReference) |
Devuelve el valor de un campo compatible con un objeto dado.Returns the value of a field supported by a given object. |
HasSameMetadataDefinitionAs(MemberInfo) | (Heredado de MemberInfo) |
IsDefined(Type, Boolean) |
Cuando se reemplaza en una clase derivada, indica si se aplican a este miembro uno o más atributos del tipo especificado o de sus tipos derivados.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. (Heredado de MemberInfo) |
MemberwiseClone() |
Crea una copia superficial del Object actual.Creates a shallow copy of the current Object. (Heredado de Object) |
SetValue(Object, Object) |
Establece el valor del campo admitido por el objeto determinado.Sets the value of the field supported by the given object. |
SetValue(Object, Object, BindingFlags, Binder, CultureInfo) |
Cuando se reemplaza en una clase derivada, se establece el valor del campo compatible con el objeto dado.When overridden in a derived class, sets the value of the field supported by the given object. |
SetValueDirect(TypedReference, Object) |
Establece el valor del campo admitido por el objeto determinado.Sets the value of the field supported by the given object. |
ToString() |
Devuelve una cadena que representa el objeto actual.Returns a string that represents the current object. (Heredado de Object) |
Operadores
Equality(FieldInfo, FieldInfo) |
Indica si dos objetos FieldInfo son iguales.Indicates whether two FieldInfo objects are equal. |
Inequality(FieldInfo, FieldInfo) |
Indica si dos objetos FieldInfo no son iguales.Indicates whether two FieldInfo objects are not equal. |
Implementaciones de interfaz explícitas
_FieldInfo.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) |
Asigna un conjunto de nombres a un conjunto correspondiente de identificadores de envío.Maps a set of names to a corresponding set of dispatch identifiers. |
_FieldInfo.GetType() |
Obtiene un objeto Type que representa el tipo de FieldInfo.Gets a Type object representing the FieldInfo type. |
_FieldInfo.GetTypeInfo(UInt32, UInt32, IntPtr) |
Recupera la información de tipo de un objeto, que se puede usar después para obtener la información de tipo de una interfaz.Retrieves the type information for an object, which can then be used to get the type information for an interface. |
_FieldInfo.GetTypeInfoCount(UInt32) |
Recupera el número de interfaces de información de tipo que proporciona un objeto (0 ó 1).Retrieves the number of type information interfaces that an object provides (either 0 or 1). |
_FieldInfo.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) |
Proporciona acceso a las propiedades y los métodos expuestos por un objeto.Provides access to properties and methods exposed by an object. |
_MemberInfo.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) |
Asigna un conjunto de nombres a un conjunto correspondiente de identificadores de envío.Maps a set of names to a corresponding set of dispatch identifiers. (Heredado de MemberInfo) |
_MemberInfo.GetType() |
Objeto Type que representa la clase MemberInfo.Gets a Type object representing the MemberInfo class. (Heredado de MemberInfo) |
_MemberInfo.GetTypeInfo(UInt32, UInt32, IntPtr) |
Recupera la información de tipo de un objeto, que se puede usar después para obtener la información de tipo de una interfaz.Retrieves the type information for an object, which can then be used to get the type information for an interface. (Heredado de MemberInfo) |
_MemberInfo.GetTypeInfoCount(UInt32) |
Recupera el número de interfaces de información de tipo que proporciona un objeto (0 ó 1).Retrieves the number of type information interfaces that an object provides (either 0 or 1). (Heredado de MemberInfo) |
_MemberInfo.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) |
Proporciona acceso a las propiedades y los métodos expuestos por un objeto.Provides access to properties and methods exposed by an object. (Heredado de MemberInfo) |
ICustomAttributeProvider.GetCustomAttributes(Boolean) |
Devuelve una matriz de todos los atributos personalizados definidos en este miembro, excluidos los atributos con nombre, o una matriz vacía si no hay atributos personalizados.Returns an array of all of the custom attributes defined on this member, excluding named attributes, or an empty array if there are no custom attributes. (Heredado de MemberInfo) |
ICustomAttributeProvider.GetCustomAttributes(Type, Boolean) |
Devuelve una matriz de atributos personalizados definidos en este miembro, identificados por tipo, o una matriz vacía si no hay atributos personalizados de ese tipo.Returns an array of custom attributes defined on this member, identified by type, or an empty array if there are no custom attributes of that type. (Heredado de MemberInfo) |
ICustomAttributeProvider.IsDefined(Type, Boolean) |
Indica si una o más instancias de |
Métodos de extensión
GetCustomAttribute(MemberInfo, Type) |
Recupera un atributo personalizado de un tipo especificado que se aplica a un miembro concreto.Retrieves a custom attribute of a specified type that is applied to a specified member. |
GetCustomAttribute(MemberInfo, Type, Boolean) |
Recupera un atributo personalizado de un tipo especificado que se aplica a un miembro concreto y, opcionalmente, inspecciona los antecesores de dicho miembro.Retrieves a custom attribute of a specified type that is applied to a specified member, and optionally inspects the ancestors of that member. |
GetCustomAttribute<T>(MemberInfo) |
Recupera un atributo personalizado de un tipo especificado que se aplica a un miembro concreto.Retrieves a custom attribute of a specified type that is applied to a specified member. |
GetCustomAttribute<T>(MemberInfo, Boolean) |
Recupera un atributo personalizado de un tipo especificado que se aplica a un miembro concreto y, opcionalmente, inspecciona los antecesores de dicho miembro.Retrieves a custom attribute of a specified type that is applied to a specified member, and optionally inspects the ancestors of that member. |
GetCustomAttributes(MemberInfo) |
Recupera una colección de atributos personalizados que se aplican a un miembro especificado.Retrieves a collection of custom attributes that are applied to a specified member. |
GetCustomAttributes(MemberInfo, Boolean) |
Recupera una colección de atributos personalizados que se aplican a un miembro concreto y, opcionalmente, inspecciona los antecesores de dicho miembro.Retrieves a collection of custom attributes that are applied to a specified member, and optionally inspects the ancestors of that member. |
GetCustomAttributes(MemberInfo, Type) |
Recupera una colección de atributos personalizados de un tipo especificado que se aplican a un miembro concreto.Retrieves a collection of custom attributes of a specified type that are applied to a specified member. |
GetCustomAttributes(MemberInfo, Type, Boolean) |
Recupera una colección de atributos personalizados de un tipo especificado que se aplican a un miembro concreto y, opcionalmente, inspecciona los antecesores de dicho miembro.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. |
GetCustomAttributes<T>(MemberInfo) |
Recupera una colección de atributos personalizados de un tipo especificado que se aplican a un miembro concreto.Retrieves a collection of custom attributes of a specified type that are applied to a specified member. |
GetCustomAttributes<T>(MemberInfo, Boolean) |
Recupera una colección de atributos personalizados de un tipo especificado que se aplican a un miembro concreto y, opcionalmente, inspecciona los antecesores de dicho miembro.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. |
IsDefined(MemberInfo, Type) |
Indica si se deben aplicar atributos personalizados de un tipo especificado a un miembro especificado.Indicates whether custom attributes of a specified type are applied to a specified member. |
IsDefined(MemberInfo, Type, Boolean) |
Indica si los atributos personalizados de un tipo especificado se aplican a un miembro especificado y, opcionalmente, se aplican a sus antecesores.Indicates whether custom attributes of a specified type are applied to a specified member, and, optionally, applied to its ancestors. |
GetMetadataToken(MemberInfo) |
Obtiene un token de metadatos del miembro determinado, si está disponible.Gets a metadata token for the given member, if available. |
HasMetadataToken(MemberInfo) |
Devuelve un valor que indica si un token de metadatos está disponible para el miembro especificado.Returns a value that indicates whether a metadata token is available for the specified member. |
Se aplica a
Seguridad para subprocesos
Este tipo es seguro para la ejecución de subprocesos.This type is thread safe.