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
FieldInfo
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
字段信息是从元数据获取的。 类
FieldInfo
没有公共构造函数。
FieldInfo
对象是通过调用
GetFields
对象的 或
GetField
方法获取的
Type
。
字段是在 类中定义的变量。
FieldInfo
提供对类中字段元数据的访问,并为字段提供动态集和获取功能。 在对象上调用 invoke 或 get 之前,类不会加载到内存中。
实施者说明
当从
FieldInfo
继承时,必须重写下面的成员:
GetValue(Object)
和
SetValue(Object, Object, BindingFlags, Binder, CultureInfo)
。