FieldInfo.FieldType Propiedad
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í.
Obtiene el tipo de este objeto de campo.
public:
abstract property Type ^ FieldType { Type ^ get(); };
public abstract Type FieldType { get; }
member this.FieldType : Type
Public MustOverride ReadOnly Property FieldType As Type
Tipo de este objeto de campo.
En el ejemplo siguiente se crea un campo, se obtiene su tipo y FieldInfo, y se muestra su FieldType.
using namespace System;
using namespace System::Reflection;
public ref class TestClass
{
// Define a field.
private:
String^ field = "private field" ;
// public:
// Myfield()
// : field( "private field" )
// {}
//
//
// property String^ Field
// {
// String^ get()
// {
// return field;
// }
//
// }
};
void main()
{
TestClass^ cl = gcnew TestClass;
// Get the type and FieldInfo.
Type^ t = cl->GetType();
FieldInfo^ fi = t->GetField("field",
static_cast<BindingFlags>(BindingFlags::Instance | BindingFlags::NonPublic));
// Get and display the Ftype s ieldType.
Console::WriteLine("Field Name: {0}.{1}", t->FullName, fi->Name );
Console::WriteLine("Field Value: '{0}'", fi->GetValue(cl));
Console::WriteLine("Field Type: {0}", fi->FieldType);
}
// The example displays the following output:
// Field Name: TestClass.field
// Field Value: 'private field'
// Field Type: System.String
using System;
using System.Reflection;
public class TestClass
{
// Define a field.
private string field = "private field";
}
public class Example
{
public static void Main()
{
var cl= new TestClass();
// Get the type and FieldInfo.
Type t = cl.GetType();
FieldInfo fi = t.GetField("field",
BindingFlags.Instance | BindingFlags.NonPublic);
// Get and display the field type.
Console.WriteLine("Field Name: {0}.{1}", t.FullName, fi.Name);
Console.WriteLine("Field Value: '{0}'", fi.GetValue(cl));
Console.WriteLine("Field Type: {0}", fi.FieldType);
}
}
// The example displays the following output:
// Field Name: TestClass.field
// Field Value: 'private field'
// Field Type: System.String
Imports System.Reflection
Public Class TestClass
' Define a field.
Private field As String = "private field"
End Class
Public Module Example
Public Sub Main()
Dim cl As New TestClass()
' Get the type and FieldInfo.
Dim t As Type = cl.GetType()
Dim fi As FieldInfo = t.GetField("field", _
BindingFlags.Instance Or BindingFlags.NonPublic)
' Get and display the FieldType.
Console.WriteLine("Field Name: {0}.{1}", t.FullName, fi.Name)
Console.WriteLine("Field Value: '{0}'", fi.GetValue(cl))
Console.WriteLine("Field Type: {0}", fi.FieldType)
End Sub
End Module
' The example displays the following output:
' Field Name: TestClass.field
' Field Value: 'private field'
' Field Type: System.String
El tipo es un tipo de datos primitivo, como String
, Boolean
o GUID
.
Para obtener la FieldType
propiedad , primero obtenga la clase Type
.
Type
En , obtenga .FieldInfo
FieldInfo
En , obtenga el FieldType
valor .
Produto | Versións |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1 |
UWP | 10.0 |
Comentarios de .NET
.NET é un proxecto de código aberto. Selecciona unha ligazón para ofrecer comentarios: