ConstructorBuilder.SetImplementationFlags メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > ConstructorBuilder.SetImplementationFlags メソッドの意味・解説 

ConstructorBuilder.SetImplementationFlags メソッド

このコンストラクタメソッド実装フラグ設定します

名前空間: System.Reflection.Emit
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Sub SetImplementationFlags ( _
    attributes As MethodImplAttributes _
)
Dim instance As ConstructorBuilder
Dim attributes As MethodImplAttributes

instance.SetImplementationFlags(attributes)
public void SetImplementationFlags (
    MethodImplAttributes attributes
)
public:
void SetImplementationFlags (
    MethodImplAttributes attributes
)
public void SetImplementationFlags (
    MethodImplAttributes attributes
)
public function SetImplementationFlags (
    attributes : MethodImplAttributes
)

パラメータ

attributes

メソッド実装フラグ

例外例外
例外種類条件

InvalidOperationException

外側の型が CreateType を使用して作成されています。

解説解説

SetImplementationFlags使用方法については、次のコード例参照してください

Dim myMethodBuilder As MethodBuilder = Nothing
Dim myCurrentDomain As AppDomain = AppDomain.CurrentDomain
' Create assembly in current CurrentDomain.
Dim myAssemblyName As New
 AssemblyName()
myAssemblyName.Name = "TempAssembly"
' Create a dynamic assembly.
myAssemblyBuilder = myCurrentDomain.DefineDynamicAssembly _
                                      (myAssemblyName, AssemblyBuilderAccess.Run)
' Create a dynamic module in the assembly.
myModuleBuilder = myAssemblyBuilder.DefineDynamicModule("TempModule",
 True)
Dim myFieldInfo2 As FieldInfo = myModuleBuilder.DefineUninitializedData
 _
                                      ("myField",
 2, FieldAttributes.Public)
' Create a type in the module.
Dim myTypeBuilder As TypeBuilder = myModuleBuilder.DefineType
 _
                                            ("TempClass",
 TypeAttributes.Public)
Dim myGreetingField As FieldBuilder = myTypeBuilder.DefineField
 _
                                 ("Greeting", GetType(String),
 FieldAttributes.Public)
Dim myConstructorArgs As Type() = {GetType(String)}
' Define a constructor of the dynamic class.
Dim myConstructor As ConstructorBuilder = myTypeBuilder.DefineConstructor
 _
                  (MethodAttributes.Public, CallingConventions.Standard, myConstructorArgs)
' Set the method implementation flags for the constructor.
myConstructor.SetImplementationFlags(MethodImplAttributes.PreserveSig Or
 _
                                     MethodImplAttributes.Runtime)
' Get the method implementation flags for the constructor.
Dim myMethodAttributes As MethodImplAttributes
 = myConstructor.GetMethodImplementationFlags()
Dim myAttributeType As Type = GetType(MethodImplAttributes)
Dim myAttribValue As Integer
 = CInt(myMethodAttributes)
If Not myAttributeType.IsEnum Then
   Console.WriteLine("This is not an Enum")
End If
' Display the field info names of the retrieved method implementation
 flags.
Dim myFieldInfo As FieldInfo() = myAttributeType.GetFields(BindingFlags.Public
 Or _
                                                           BindingFlags.Static)
Console.WriteLine("The Field info names of the MethodImplAttributes
 for the constructor are:")
Dim i As Integer
For i = 0 To myFieldInfo.Length - 1
   Dim myFieldValue As Integer
 = CType(myFieldInfo(i).GetValue(Nothing), Int32)
   If(myFieldValue And myAttribValue) = myFieldValue
 Then
      Console.WriteLine("   " + myFieldInfo(i).Name)
   End If
Next i
MethodBuilder myMethodBuilder = null;
AppDomain myCurrentDomain = AppDomain.CurrentDomain;
// Create assembly in current CurrentDomain.
AssemblyName myAssemblyName = new AssemblyName();
myAssemblyName.Name = "TempAssembly";
// Create a dynamic assembly.
myAssemblyBuilder = myCurrentDomain.DefineDynamicAssembly
   (myAssemblyName, AssemblyBuilderAccess.Run);
// Create a dynamic module in the assembly.
myModuleBuilder = myAssemblyBuilder.DefineDynamicModule("TempModule", true);
FieldInfo myFieldInfo2 =
   myModuleBuilder.DefineUninitializedData("myField", 2, FieldAttributes.Public);
// Create a type in the module.
TypeBuilder myTypeBuilder = myModuleBuilder.DefineType("TempClass",TypeAttributes.Public);
FieldBuilder myGreetingField = myTypeBuilder.DefineField("Greeting", 
   typeof(String), FieldAttributes.Public);
Type[] myConstructorArgs = { typeof(String) };
// Define a constructor of the dynamic class.
ConstructorBuilder myConstructor = myTypeBuilder.DefineConstructor(
   MethodAttributes.Public, CallingConventions.Standard, myConstructorArgs);
// Set the method implementation flags for the constructor.
myConstructor.SetImplementationFlags(MethodImplAttributes.PreserveSig | MethodImplAttributes.Runtime);
// Get the method implementation flags for the constructor.
MethodImplAttributes myMethodAttributes = myConstructor.GetMethodImplementationFlags();
Type myAttributeType = typeof(MethodImplAttributes);
int myAttribValue = (int) myMethodAttributes;
if(! myAttributeType.IsEnum)
{
   Console.WriteLine("This is not an Enum");
}
// Display the field info names of the retrieved method implementation
 flags.
FieldInfo[] myFieldInfo = myAttributeType.GetFields(BindingFlags.Public | BindingFlags.Static);
Console.WriteLine("The Field info names of the MethodImplAttributes for
 the constructor are:");
for (int i = 0; i < myFieldInfo.Length;
 i++)
{
   int myFieldValue = (Int32)myFieldInfo[i].GetValue(null);
   if ((myFieldValue & myAttribValue) == myFieldValue)
   {
      Console.WriteLine("   " + myFieldInfo[i].Name);
   }
}
MethodBuilder^ myMethodBuilder = nullptr;
AppDomain^ myCurrentDomain = AppDomain::CurrentDomain;

// Create assembly in current CurrentDomain.
AssemblyName^ myAssemblyName = gcnew AssemblyName;
myAssemblyName->Name = "TempAssembly";

// Create a dynamic assembly.
myAssemblyBuilder = myCurrentDomain->DefineDynamicAssembly( myAssemblyName, AssemblyBuilderAccess::Run
 );

// Create a dynamic module in the assembly.
myModuleBuilder = myAssemblyBuilder->DefineDynamicModule( "TempModule",
 true );
FieldInfo^ myFieldInfo2 = myModuleBuilder->DefineUninitializedData( "myField",
 2, FieldAttributes::Public );

// Create a type in the module.
TypeBuilder^ myTypeBuilder = myModuleBuilder->DefineType( "TempClass",
 TypeAttributes::Public );
FieldBuilder^ myGreetingField = myTypeBuilder->DefineField( "Greeting",
 String::typeid, FieldAttributes::Public );
array<Type^>^myConstructorArgs = {String::typeid};

// Define a constructor of the dynamic class.
ConstructorBuilder^ myConstructor = myTypeBuilder->DefineConstructor( MethodAttributes::Public,
 CallingConventions::Standard, myConstructorArgs );

// Set the method implementation flags for the constructor.
myConstructor->SetImplementationFlags( static_cast<MethodImplAttributes>(MethodImplAttributes::PreserveSig
 | MethodImplAttributes::Runtime) );

// Get the method implementation flags for the constructor.
MethodImplAttributes myMethodAttributes = myConstructor->GetMethodImplementationFlags();
Type^ myAttributeType = MethodImplAttributes::typeid;
int myAttribValue = (int)myMethodAttributes;
if (  !myAttributeType->IsEnum )
{
   Console::WriteLine( "This is not an Enum" );
}

// Display the field info names of the retrieved method implementation
 flags.
array<FieldInfo^>^myFieldInfo = myAttributeType->GetFields( static_cast<BindingFlags>(BindingFlags::Public
 | BindingFlags::Static) );
Console::WriteLine( "The Field info names of the MethodImplAttributes for
 the constructor are:" );
for ( int i = 0; i < myFieldInfo->Length;
 i++ )
{
   int myFieldValue =  *safe_cast<Int32^>(myFieldInfo[ i
 ]->GetValue( nullptr ));
   if ( (myFieldValue & myAttribValue) == myFieldValue )
   {
      Console::WriteLine( " {0}", myFieldInfo[ i ]->Name );
   }
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ConstructorBuilder クラス
ConstructorBuilder メンバ
System.Reflection.Emit 名前空間


このページでは「.NET Framework クラス ライブラリ リファレンス」からConstructorBuilder.SetImplementationFlags メソッドを検索した結果を表示しています。
Weblioに収録されているすべての辞書からConstructorBuilder.SetImplementationFlags メソッドを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からConstructorBuilder.SetImplementationFlags メソッド を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

ConstructorBuilder.SetImplementationFlags メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



ConstructorBuilder.SetImplementationFlags メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS