FieldBuilder クラス
アセンブリ: mscorlib (mscorlib.dll 内)

<ClassInterfaceAttribute(ClassInterfaceType.None)> _ <ComVisibleAttribute(True)> _ Public NotInheritable Class FieldBuilder Inherits FieldInfo Implements _FieldBuilder
[ClassInterfaceAttribute(ClassInterfaceType.None)] [ComVisibleAttribute(true)] public sealed class FieldBuilder : FieldInfo, _FieldBuilder
[ClassInterfaceAttribute(ClassInterfaceType::None)] [ComVisibleAttribute(true)] public ref class FieldBuilder sealed : public FieldInfo, _FieldBuilder

![]() |
---|
このクラスに適用される HostProtectionAttribute 属性の Resources プロパティの値は、MayLeakOnAbort です。HostProtectionAttribute は、デスクトップ アプリケーション (一般的には、アイコンをダブルクリック、コマンドを入力、またはブラウザに URL を入力して起動するアプリケーション) には影響しません。詳細については、HostProtectionAttribute クラスのトピックまたは「SQL Server プログラミングとホスト保護属性」を参照してください。 |
DefineField、DefineInitializedData、または DefineUninitializedData を呼び出して、FieldBuilder のインスタンスを取得します。

FieldBuilder の使用方法については、次のコード例を参照してください。
Imports System Imports System.Threading Imports System.Reflection Imports System.Reflection.Emit Imports System.Security.Permissions Public Class FieldBuilder_Sample Private Shared Function CreateType(currentDomain As AppDomain) As Type ' Create an assembly. Dim myAssemblyName As New AssemblyName() myAssemblyName.Name = "DynamicAssembly" Dim myAssembly As AssemblyBuilder = currentDomain.DefineDynamicAssembly(myAssemblyName, _ AssemblyBuilderAccess.Run) ' Create a dynamic module in Dynamic Assembly. Dim myModuleBuilder As ModuleBuilder = myAssembly.DefineDynamicModule("MyModule") ' Define a public class named "MyClass" in the assembly. Dim myTypeBuilder As TypeBuilder = myModuleBuilder.DefineType("MyClass", _ TypeAttributes.Public) ' Define a private String field named "MyField" in the type. Dim myFieldBuilder As FieldBuilder = myTypeBuilder.DefineField("MyField", _ GetType(String), FieldAttributes.Private Or FieldAttributes.Static) ' Create the constructor. Dim constructorArgs As Type() = {GetType(String)} Dim constructor As ConstructorBuilder = _ myTypeBuilder.DefineConstructor(MethodAttributes.Public, _ CallingConventions.Standard, constructorArgs) Dim constructorIL As ILGenerator = constructor.GetILGenerator() constructorIL.Emit(OpCodes.Ldarg_0) Dim superConstructor As ConstructorInfo = GetType(Object).GetConstructor(New Type() {}) constructorIL.Emit(OpCodes.Call, superConstructor) constructorIL.Emit(OpCodes.Ldarg_0) constructorIL.Emit(OpCodes.Ldarg_1) constructorIL.Emit(OpCodes.Stfld, myFieldBuilder) constructorIL.Emit(OpCodes.Ret) ' Create the MyMethod method. Dim myMethodBuilder As MethodBuilder = myTypeBuilder.DefineMethod("MyMethod", _ MethodAttributes.Public, GetType(String), Nothing) Dim methodIL As ILGenerator = myMethodBuilder.GetILGenerator() methodIL.Emit(OpCodes.Ldarg_0) methodIL.Emit(OpCodes.Ldfld, myFieldBuilder) methodIL.Emit(OpCodes.Ret) Console.WriteLine("Name :" + myFieldBuilder.Name) Console.WriteLine("DeclaringType :" + myFieldBuilder.DeclaringType.ToString()) Console.WriteLine("Type :" + myFieldBuilder.FieldType.ToString()) Console.WriteLine("Token :" + myFieldBuilder.GetToken().Token.ToString()) Return myTypeBuilder.CreateType() End Function 'CreateType <PermissionSetAttribute(SecurityAction.Demand, Name:="FullTrust")> _ Public Shared Sub Main() Try Dim myType As Type = CreateType(Thread.GetDomain()) ' Create an instance of the "HelloWorld" class. Dim helloWorld As Object = Activator.CreateInstance(myType, New Object() {"HelloWorld"}) ' Invoke the "MyMethod" method of the "MyClass" class. Dim myObject As Object = myType.InvokeMember("MyMethod", _ BindingFlags.InvokeMethod, Nothing, helloWorld, Nothing) Console.WriteLine("MyClass.MyMethod returned: " & Microsoft.VisualBasic.Chr(34) & myObject & Microsoft.VisualBasic.Chr(34) ) Catch e as Exception Console.WriteLine("Exception Caught "+e.Message) End Try End Sub 'Main End Class 'FieldBuilder_Sample
using System; using System.Threading; using System.Reflection; using System.Reflection.Emit; using System.Security.Permissions; public class FieldBuilder_Sample { private static Type CreateType(AppDomain currentDomain) { // Create an assembly. AssemblyName myAssemblyName = new AssemblyName(); myAssemblyName.Name = "DynamicAssembly"; AssemblyBuilder myAssembly = currentDomain.DefineDynamicAssembly(myAssemblyName,AssemblyBuilderAccess.Run); // Create a dynamic module in Dynamic Assembly. ModuleBuilder myModuleBuilder=myAssembly.DefineDynamicModule("MyModule"); // Define a public class named "MyClass" in the assembly. TypeBuilder myTypeBuilder= myModuleBuilder.DefineType("MyClass",TypeAttributes.Public); // Define a private String field named "MyField" in the type. FieldBuilder myFieldBuilder= myTypeBuilder.DefineField("MyField" , typeof(string),FieldAttributes.Private|FieldAttributes.Static); // Create the constructor. Type[] constructorArgs = { typeof(String) }; ConstructorBuilder constructor = myTypeBuilder.DefineConstructor( MethodAttributes.Public, CallingConventions.Standard, constructorArgs); ILGenerator constructorIL = constructor.GetILGenerator(); constructorIL.Emit(OpCodes.Ldarg_0); ConstructorInfo superConstructor = typeof(Object).GetConstructor(new Type[0]); constructorIL.Emit(OpCodes.Call, superConstructor); constructorIL.Emit(OpCodes.Ldarg_0); constructorIL.Emit(OpCodes.Ldarg_1); constructorIL.Emit(OpCodes.Stfld, myFieldBuilder); constructorIL.Emit(OpCodes.Ret); // Create the MyMethod method. MethodBuilder myMethodBuilder= myTypeBuilder.DefineMethod("MyMethod" , MethodAttributes.Public,typeof(String),null); ILGenerator methodIL = myMethodBuilder.GetILGenerator(); methodIL.Emit(OpCodes.Ldarg_0); methodIL.Emit(OpCodes.Ldfld, myFieldBuilder); methodIL.Emit(OpCodes.Ret); Console.WriteLine("Name :"+myFieldBuilder.Name); Console.WriteLine("DeclaringType :"+myFieldBuilder.DeclaringType); Console.WriteLine("Type :"+myFieldBuilder.FieldType); Console.WriteLine("Token :"+myFieldBuilder.GetToken().Token); return myTypeBuilder.CreateType(); } [PermissionSetAttribute(SecurityAction.Demand, Name="FullTrust")] public static void Main() { try { Type myType = CreateType(Thread.GetDomain()); // Create an instance of the "HelloWorld" class. Object helloWorld = Activator.CreateInstance(myType, new Object[] { "HelloWorld" }); // Invoke the "MyMethod" method of the "MyClass" class. Object myObject = myType.InvokeMember("MyMethod", BindingFlags.InvokeMethod, null, helloWorld, null); Console.WriteLine("MyClass.MyMethod returned: \"" + myObject + "\""); } catch( Exception e) { Console.WriteLine("Exception Caught "+e.Message); } } }
using namespace System; using namespace System::Threading; using namespace System::Reflection; using namespace System::Reflection::Emit; Type^ CreateType( AppDomain^ currentDomain ) { // Create an assembly. AssemblyName^ myAssemblyName = gcnew AssemblyName; myAssemblyName->Name = "DynamicAssembly"; AssemblyBuilder^ myAssembly = currentDomain->DefineDynamicAssembly( myAssemblyName, AssemblyBuilderAccess::Run ); // Create a dynamic module in Dynamic Assembly. ModuleBuilder^ myModuleBuilder = myAssembly->DefineDynamicModule( "MyModule" ); // Define a public class named S"MyClass" in the assembly. TypeBuilder^ myTypeBuilder = myModuleBuilder->DefineType( "MyClass", TypeAttributes::Public ); // Define a private String field named S"MyField" in the type. FieldBuilder^ myFieldBuilder = myTypeBuilder->DefineField( "MyField", String::typeid, static_cast<FieldAttributes>(FieldAttributes::Private | FieldAttributes::Static) ); // Create the constructor. array<Type^>^constructorArgs = {String::typeid}; ConstructorBuilder^ constructor = myTypeBuilder->DefineConstructor( MethodAttributes::Public, CallingConventions::Standard, constructorArgs ); ILGenerator^ constructorIL = constructor->GetILGenerator(); constructorIL->Emit( OpCodes::Ldarg_0 ); ConstructorInfo^ superConstructor = Object::typeid->GetConstructor( gcnew array<Type^>(0) ); constructorIL->Emit( OpCodes::Call, superConstructor ); constructorIL->Emit( OpCodes::Ldarg_0 ); constructorIL->Emit( OpCodes::Ldarg_1 ); constructorIL->Emit( OpCodes::Stfld, myFieldBuilder ); constructorIL->Emit( OpCodes::Ret ); // Create the MyMethod method. MethodBuilder^ myMethodBuilder = myTypeBuilder->DefineMethod( "MyMethod", MethodAttributes::Public, String::typeid, nullptr ); ILGenerator^ methodIL = myMethodBuilder->GetILGenerator(); methodIL->Emit( OpCodes::Ldarg_0 ); methodIL->Emit( OpCodes::Ldfld, myFieldBuilder ); methodIL->Emit( OpCodes::Ret ); Console::WriteLine( "Name : {0}", myFieldBuilder->Name ); Console::WriteLine( "DeclaringType : {0}", myFieldBuilder->DeclaringType ); Console::WriteLine( "Type : {0}", myFieldBuilder->FieldType ); Console::WriteLine( "Token : {0}", myFieldBuilder->GetToken().Token ); return myTypeBuilder->CreateType(); } int main() { try { Type^ myType = CreateType( Thread::GetDomain() ); // Create an instance of the S"HelloWorld" class. array<Object^>^type = {"HelloWorld"}; Object^ helloWorld = Activator::CreateInstance( myType, type ); // Invoke the S"MyMethod" method of the S"MyClass" class. Object^ myObject = myType->InvokeMember( "MyMethod", BindingFlags::InvokeMethod, nullptr, helloWorld, nullptr ); Console::WriteLine( "MyClass::MyMethod returned: \"{0}\"", myObject ); } catch ( Exception^ e ) { Console::WriteLine( "Exception Caught {0}", e->Message ); } }

System.Reflection.MemberInfo
System.Reflection.FieldInfo
System.Reflection.Emit.FieldBuilder


Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


FieldBuilder プロパティ

名前 | 説明 | |
---|---|---|
![]() | Attributes | オーバーライドされます。 このフィールドの属性を示します。このプロパティは読み取り専用です。 |
![]() | DeclaringType | オーバーライドされます。 このフィールドを宣言する型の Type オブジェクトへの参照を示します。このプロパティは読み取り専用です。 |
![]() | FieldHandle | オーバーライドされます。 このフィールドの内部メタデータ ハンドルを示します。このプロパティは読み取り専用です。 |
![]() | FieldType | オーバーライドされます。 このフィールドの型を表す Type オブジェクトを示します。このプロパティは読み取り専用です。 |
![]() | IsAssembly | このフィールドに、アセンブリ レベルの参照可能範囲が設定されているかどうかを示す値を取得します。 ( FieldInfo から継承されます。) |
![]() | IsFamily | このフィールドに、ファミリ レベルの参照可能範囲が設定されているかどうかを示す値を取得します。 ( FieldInfo から継承されます。) |
![]() | IsFamilyAndAssembly | このフィールドに、FamilyAndAssembly レベルの参照可能範囲が設定されているかどうかを示す値を取得します。 ( FieldInfo から継承されます。) |
![]() | IsFamilyOrAssembly | このフィールドに、FamilyOrAssembly レベルの参照可能範囲が設定されているかどうかを示す値を取得します。 ( FieldInfo から継承されます。) |
![]() | IsInitOnly | フィールドをコンストラクタの本体だけでしか設定できないのかどうかを示す値を取得します。 ( FieldInfo から継承されます。) |
![]() | IsLiteral | 値がコンパイル時に書き込まれ、変更できないかどうかを示す値を取得します。 ( FieldInfo から継承されます。) |
![]() | IsNotSerialized | このフィールドに、NotSerialized 属性が設定されているかどうかを示す値を取得します。 ( FieldInfo から継承されます。) |
![]() | IsPinvokeImpl | 対応する PinvokeImpl 属性が FieldAttributes に設定されているかどうかを示す値を取得します。 ( FieldInfo から継承されます。) |
![]() | IsPrivate | フィールドがプライベートかどうかを示す値を取得します。 ( FieldInfo から継承されます。) |
![]() | IsPublic | フィールドがパブリックかどうかを示す値を取得します。 ( FieldInfo から継承されます。) |
![]() | IsSpecialName | 対応する SpecialName 属性が FieldAttributes 列挙子に設定されているかどうかを示す値を取得します。 ( FieldInfo から継承されます。) |
![]() | IsStatic | フィールドが静的かどうかを示す値を取得します。 ( FieldInfo から継承されます。) |
![]() | MemberType | このメンバがフィールドであることを示す MemberTypes 値を取得します。 ( FieldInfo から継承されます。) |
![]() | MetadataToken | メタデータ要素を識別する値を取得します。 ( MemberInfo から継承されます。) |
![]() | Module | オーバーライドされます。 このフィールドを含む型が定義されるモジュールを取得します。 |
![]() | Name | オーバーライドされます。 このフィールドの名前を示します。このプロパティは読み取り専用です。 |
![]() | ReflectedType | オーバーライドされます。 このオブジェクトの取得元である Type オブジェクトへの参照を示します。このプロパティは読み取り専用です。 |

FieldBuilder メソッド


名前 | 説明 | |
---|---|---|
![]() | System.Runtime.InteropServices._FieldBuilder.GetIDsOfNames | 名前のセットを対応するディスパッチ識別子のセットに割り当てます。 |
![]() | System.Runtime.InteropServices._FieldBuilder.GetTypeInfo | オブジェクトの型情報を取得します。この型情報は、インターフェイスの型情報を取得するために使用できます。 |
![]() | System.Runtime.InteropServices._FieldBuilder.GetTypeInfoCount | オブジェクトが提供する型情報インターフェイスの数を取得します (0 または 1)。 |
![]() | System.Runtime.InteropServices._FieldBuilder.Invoke | オブジェクトによって公開されているプロパティおよびメソッドにアクセスできるようにします。 |

FieldBuilder メンバ
フィールドを定義および表現します。このクラスは継承できません。
FieldBuilder データ型で公開されるメンバを以下の表に示します。

名前 | 説明 | |
---|---|---|
![]() | Attributes | オーバーライドされます。 このフィールドの属性を示します。このプロパティは読み取り専用です。 |
![]() | DeclaringType | オーバーライドされます。 このフィールドを宣言する型の Type オブジェクトへの参照を示します。このプロパティは読み取り専用です。 |
![]() | FieldHandle | オーバーライドされます。 このフィールドの内部メタデータ ハンドルを示します。このプロパティは読み取り専用です。 |
![]() | FieldType | オーバーライドされます。 このフィールドの型を表す Type オブジェクトを示します。このプロパティは読み取り専用です。 |
![]() | IsAssembly | このフィールドに、アセンブリ レベルの参照可能範囲が設定されているかどうかを示す値を取得します。(FieldInfo から継承されます。) |
![]() | IsFamily | このフィールドに、ファミリ レベルの参照可能範囲が設定されているかどうかを示す値を取得します。(FieldInfo から継承されます。) |
![]() | IsFamilyAndAssembly | このフィールドに、FamilyAndAssembly レベルの参照可能範囲が設定されているかどうかを示す値を取得します。(FieldInfo から継承されます。) |
![]() | IsFamilyOrAssembly | このフィールドに、FamilyOrAssembly レベルの参照可能範囲が設定されているかどうかを示す値を取得します。(FieldInfo から継承されます。) |
![]() | IsInitOnly | フィールドをコンストラクタの本体だけでしか設定できないのかどうかを示す値を取得します。(FieldInfo から継承されます。) |
![]() | IsLiteral | 値がコンパイル時に書き込まれ、変更できないかどうかを示す値を取得します。(FieldInfo から継承されます。) |
![]() | IsNotSerialized | このフィールドに、NotSerialized 属性が設定されているかどうかを示す値を取得します。(FieldInfo から継承されます。) |
![]() | IsPinvokeImpl | 対応する PinvokeImpl 属性が FieldAttributes に設定されているかどうかを示す値を取得します。(FieldInfo から継承されます。) |
![]() | IsPrivate | フィールドがプライベートかどうかを示す値を取得します。(FieldInfo から継承されます。) |
![]() | IsPublic | フィールドがパブリックかどうかを示す値を取得します。(FieldInfo から継承されます。) |
![]() | IsSpecialName | 対応する SpecialName 属性が FieldAttributes 列挙子に設定されているかどうかを示す値を取得します。(FieldInfo から継承されます。) |
![]() | IsStatic | フィールドが静的かどうかを示す値を取得します。(FieldInfo から継承されます。) |
![]() | MemberType | このメンバがフィールドであることを示す MemberTypes 値を取得します。(FieldInfo から継承されます。) |
![]() | MetadataToken | メタデータ要素を識別する値を取得します。(MemberInfo から継承されます。) |
![]() | Module | オーバーライドされます。 このフィールドを含む型が定義されるモジュールを取得します。 |
![]() | Name | オーバーライドされます。 このフィールドの名前を示します。このプロパティは読み取り専用です。 |
![]() | ReflectedType | オーバーライドされます。 このオブジェクトの取得元である Type オブジェクトへの参照を示します。このプロパティは読み取り専用です。 |


名前 | 説明 | |
---|---|---|
![]() | System.Runtime.InteropServices._FieldBuilder.GetIDsOfNames | 名前のセットを対応するディスパッチ識別子のセットに割り当てます。 |
![]() | System.Runtime.InteropServices._FieldBuilder.GetTypeInfo | オブジェクトの型情報を取得します。この型情報は、インターフェイスの型情報を取得するために使用できます。 |
![]() | System.Runtime.InteropServices._FieldBuilder.GetTypeInfoCount | オブジェクトが提供する型情報インターフェイスの数を取得します (0 または 1)。 |
![]() | System.Runtime.InteropServices._FieldBuilder.Invoke | オブジェクトによって公開されているプロパティおよびメソッドにアクセスできるようにします。 |

_FieldBuilder インターフェイス
アセンブリ: mscorlib (mscorlib.dll 内)

<ComVisibleAttribute(True)> _ <GuidAttribute("CE1A3BF5-975E-30CC-97C9-1EF70F8F3993")> _ <InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)> _ <CLSCompliantAttribute(False)> _ Public Interface _FieldBuilder
[ComVisibleAttribute(true)] [GuidAttribute("CE1A3BF5-975E-30CC-97C9-1EF70F8F3993")] [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)] [CLSCompliantAttribute(false)] public interface _FieldBuilder
[ComVisibleAttribute(true)] [GuidAttribute(L"CE1A3BF5-975E-30CC-97C9-1EF70F8F3993")] [InterfaceTypeAttribute(ComInterfaceType::InterfaceIsIUnknown)] [CLSCompliantAttribute(false)] public interface class _FieldBuilder


Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


_FieldBuilder メソッド

名前 | 説明 | |
---|---|---|
![]() | GetIDsOfNames | 一連の名前を対応する一連のディスパッチ識別子に割り当てます。 |
![]() | GetTypeInfo | オブジェクトの型情報を取得します。その後は、インターフェイスの型情報の取得に使用できます。 |
![]() | GetTypeInfoCount | オブジェクトが提供する型情報インターフェイスの数 (0 または 1) を取得します。 |
![]() | Invoke | オブジェクトが公開するプロパティおよびメソッドにアクセスできるようにします。 |

_FieldBuilder メンバ
System.Reflection.Emit.FieldBuilder クラスをアンマネージ コードに公開します。
_FieldBuilder データ型で公開されるメンバを以下の表に示します。

名前 | 説明 | |
---|---|---|
![]() | GetIDsOfNames | 一連の名前を対応する一連のディスパッチ識別子に割り当てます。 |
![]() | GetTypeInfo | オブジェクトの型情報を取得します。その後は、インターフェイスの型情報の取得に使用できます。 |
![]() | GetTypeInfoCount | オブジェクトが提供する型情報インターフェイスの数 (0 または 1) を取得します。 |
![]() | Invoke | オブジェクトが公開するプロパティおよびメソッドにアクセスできるようにします。 |

- FieldBuilderのページへのリンク