FieldInfo.FieldType 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取此字段对象的类型。
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 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
注解
类型是某种基元数据类型,例如 String
、 Boolean
或 GUID
。
若要获取 FieldType
属性,请首先获取类 Type
。
Type
从 中获取 FieldInfo
。 从 中 FieldInfo
获取 FieldType
值。