FieldInfo.FieldType Свойство
Определение
Важно!
Некоторые сведения относятся к предварительной версии продукта, в которую до выпуска могут быть внесены существенные изменения. Майкрософт не предоставляет никаких гарантий, явных или подразумеваемых, относительно приведенных здесь сведений.
Возвращает тип этого объекта поля.
public:
abstract property Type ^ FieldType { Type ^ get(); };
public abstract Type FieldType { get; }
member this.FieldType : Type
Public MustOverride ReadOnly Property FieldType As Type
Значение свойства
Тип этого объекта поля.
Реализации
Примеры
В следующем примере создается поле, возвращается его тип и FieldInfo, а затем отображается его FieldType.
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
Комментарии
Тип является примитивным типом данных, например String
, Boolean
или GUID
.
Чтобы получить FieldType
свойство , сначала получите класс Type
.
Type
Из получите FieldInfo
.
FieldInfo
Из получите FieldType
значение .