MethodBuilder.DeclaringType プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > MethodBuilder.DeclaringType プロパティの意味・解説 

MethodBuilder.DeclaringType プロパティ

このメソッド宣言する型を返します

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

Public Overrides ReadOnly
 Property DeclaringType As Type
Dim instance As MethodBuilder
Dim value As Type

value = instance.DeclaringType
public override Type DeclaringType { get; }
public:
virtual property Type^ DeclaringType {
    Type^ get () override;
}
/** @property */
public Type get_DeclaringType ()

プロパティ
読み取り専用。このメソッド宣言する型。

使用例使用例

Type プロパティ使用方法については、次のコード例参照してください

Imports System
Imports System.Reflection
Imports System.Reflection.Emit
Imports MicroSoft.VisualBasic

Public Class MethodBuilderClass

   Public Shared Sub Main()
      Try
         ' Get the current AppDomain.
         Dim myAppDomain As AppDomain = AppDomain.CurrentDomain
         Dim myAssemblyName As New
 AssemblyName()
         myAssemblyName.Name = "MyDynamicAssembly"

         ' Create the dynamic assembly and set its access mode to 'Save'.
         Dim myAssemblyBuilder As AssemblyBuilder
 = myAppDomain.DefineDynamicAssembly _
                                                      (myAssemblyName, AssemblyBuilderAccess.Save)
         ' Create a dynamic module 'myModuleBuilder'.
         Dim myModuleBuilder As ModuleBuilder
 = myAssemblyBuilder.DefineDynamicModule _
                                                                     ("MyDynamicModule",
 True)
         ' Define a public class 'MyDynamicClass'.
         Dim myTypeBuilder As TypeBuilder =
 myModuleBuilder.DefineType _
                                                      ("MyDynamicClass",
 TypeAttributes.Public)
         ' Define a public string field named 'myField'.
         Dim myField As FieldBuilder = myTypeBuilder.DefineField("MyDynamicField",
 _
                                                   GetType(String),
 FieldAttributes.Public)
         ' Define the dynamic method 'MyDynamicMethod'.
         Dim myMethodBuilder As MethodBuilder
 = myTypeBuilder.DefineMethod("MyDynamicMethod",
 _
                                 MethodAttributes.Private, GetType(Integer),
 New Type() {})
         ' Generate the IL for 'myMethodBuilder'.
         Dim myMethodIL As ILGenerator = myMethodBuilder.GetILGenerator()
         ' Emit the necessary opcodes.
         myMethodIL.Emit(OpCodes.Ldarg_0)
         myMethodIL.Emit(OpCodes.Ldfld, myField)
         myMethodIL.Emit(OpCodes.Ret)

         ' Create 'myTypeBuilder' class.
         Dim myType1 As Type = myTypeBuilder.CreateType()

         ' Get the method information of 'myTypeBuilder'.
         Dim myInfo As MethodInfo() = myType1.GetMethods(BindingFlags.NonPublic
 Or _
                                                         BindingFlags.Instance)
         ' Print non-public methods present of 'myType1'.
         Console.WriteLine(ControlChars.Newline + "The Non-Public methods present
 in 'myType1' are:" + _
                                                                           ControlChars.NewLine)
         Dim i As Integer
         For i = 0 To myInfo.Length - 1
            Console.WriteLine(myInfo(i).Name)
         Next i
         ' Print the 'Attribute', 'Signature' of 'myMethodBuilder'.
         Console.WriteLine(ControlChars.Newline + "The Attribute of
 'MyDynamicMethod' is :{0}", _
                                                                        myMethodBuilder.Attributes)
         Console.WriteLine(ControlChars.Newline + "The Signature of
 'MyDynamicMethod' is : " + _
                                                ControlChars.Newline + myMethodBuilder.Signature)
      Catch e As Exception
         Console.WriteLine("Exception :{0}", e.Message)
      End Try
   End Sub 'Main
End Class 'MethodBuilderClass
using System;
using System.Reflection;
using System.Reflection.Emit;

public class MethodBuilderClass
{
   public static void Main()
   {
      try
      {
         // Get the current AppDomain.
         AppDomain myAppDomain = AppDomain.CurrentDomain;
         AssemblyName myAssemblyName = new AssemblyName();
         myAssemblyName.Name = "MyDynamicAssembly";

         // Create the dynamic assembly and set its access mode to 'Save'.
         AssemblyBuilder myAssemblyBuilder = myAppDomain.DefineDynamicAssembly(
                        myAssemblyName, AssemblyBuilderAccess.Save);
         // Create a dynamic module 'myModuleBuilder'.
         ModuleBuilder myModuleBuilder =
              myAssemblyBuilder.DefineDynamicModule("MyDynamicModule",
 true);
         // Define a public class 'MyDynamicClass'.
         TypeBuilder myTypeBuilder = myModuleBuilder.DefineType("MyDynamicClass"
,
                                                 TypeAttributes.Public);
         // Define a public string field named 'myField'.
         FieldBuilder myField = myTypeBuilder.DefineField("MyDynamicField"
,
                        typeof(String), FieldAttributes.Public);
         
         // Define the dynamic method 'MyDynamicMethod'.
         MethodBuilder myMethodBuilder = myTypeBuilder.DefineMethod("MyDynamicMethod"
,
                              MethodAttributes.Private, typeof(int),
 new Type[] {});
         // Generate the IL for 'myMethodBuilder'.
         ILGenerator myMethodIL = myMethodBuilder.GetILGenerator();
         // Emit the necessary opcodes.
         myMethodIL.Emit(OpCodes.Ldarg_0);
         myMethodIL.Emit(OpCodes.Ldfld, myField);
         myMethodIL.Emit(OpCodes.Ret);

         // Create 'myTypeBuilder' class.
         Type myType1 = myTypeBuilder.CreateType();

         // Get the method information of 'myTypeBuilder'.
         MethodInfo[] myInfo = myType1.GetMethods(BindingFlags.NonPublic |
                                                BindingFlags.Instance);
         // Print non-public methods present of 'myType1'.
         Console.WriteLine("\nThe Non-Public methods present in
 'myType1' are:\n");
         for(int i = 0; i < myInfo.Length;
 i++)
         {
            Console.WriteLine(myInfo[i].Name);
         }
         // Print the 'Attribute', 'Signature' of 'myMethodBuilder'.
         Console.WriteLine("\nThe Attribute of 'MyDynamicMethod' is :{0}"
 ,
                                    myMethodBuilder.Attributes);
         Console.WriteLine("\nThe Signature of 'MyDynamicMethod' is : \n"
                                    + myMethodBuilder.Signature);
      }
      catch(Exception e)
      {
         Console.WriteLine("Exception :{0}", e.Message);
      }
   }
}
using namespace System;
using namespace System::Reflection;
using namespace System::Reflection::Emit;
int main()
{
   try
   {
      // Get the current AppDomain.
      AppDomain^ myAppDomain = AppDomain::CurrentDomain;
      AssemblyName^ myAssemblyName = gcnew AssemblyName;
      myAssemblyName->Name = "MyDynamicAssembly";

      // Create the dynamic assembly and set its access mode to 'Save'.
      AssemblyBuilder^ myAssemblyBuilder = myAppDomain->DefineDynamicAssembly(
 myAssemblyName, AssemblyBuilderAccess::Save );

      // Create a dynamic module 'myModuleBuilder'.
      ModuleBuilder^ myModuleBuilder = myAssemblyBuilder->DefineDynamicModule(
 "MyDynamicModule", true );

      // Define a public class 'MyDynamicClass'.
      TypeBuilder^ myTypeBuilder = myModuleBuilder->DefineType( "MyDynamicClass",
 TypeAttributes::Public );

      // Define a public string field named 'myField'.
      FieldBuilder^ myField = myTypeBuilder->DefineField( "MyDynamicField",
 String::typeid, FieldAttributes::Public );

      // Define the dynamic method 'MyDynamicMethod'.
      array<Type^>^temp0 = gcnew array<Type^>(0);
      MethodBuilder^ myMethodBuilder = myTypeBuilder->DefineMethod( "MyDynamicMethod",
 MethodAttributes::Private, int::typeid, temp0 );

      // Generate the IL for 'myMethodBuilder'.
      ILGenerator^ myMethodIL = myMethodBuilder->GetILGenerator();

      // Emit the necessary opcodes.
      myMethodIL->Emit( OpCodes::Ldarg_0 );
      myMethodIL->Emit( OpCodes::Ldfld, myField );
      myMethodIL->Emit( OpCodes::Ret );

      // Create 'myTypeBuilder' class.
      Type^ myType1 = myTypeBuilder->CreateType();

      // Get the method information of 'myTypeBuilder'.
      array<MethodInfo^>^myInfo = myType1->GetMethods( static_cast<BindingFlags>(BindingFlags::NonPublic
 | BindingFlags::Instance) );

      // Print non-public methods present of 'myType1'.
      Console::WriteLine( "\nThe Non-Public methods present in
 'myType1' are:\n" );
      for ( int i = 0; i < myInfo->Length;
 i++ )
      {
         Console::WriteLine( myInfo[ i ]->Name );
      }
      Console::WriteLine( "\nThe Attribute of 'MyDynamicMethod' is :{0}",
 myMethodBuilder->Attributes );
      Console::WriteLine( "\nThe Signature of 'MyDynamicMethod' is : \n{0}",
 myMethodBuilder->Signature );
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( "Exception :{0}", e->Message );
   }
}
import System.*;
import System.Reflection.*;
import System.Reflection.Emit.*;

public class MethodBuilderClass
{
    public static void main(String[]
 args)
    {
        try {
            // Get the current AppDomain.
            AppDomain myAppDomain = AppDomain.get_CurrentDomain();
            AssemblyName myAssemblyName = new AssemblyName();
            myAssemblyName.set_Name("MyDynamicAssembly");

            // Create the dynamic assembly and set its access mode to
 'Save'.
            AssemblyBuilder myAssemblyBuilder = 
                myAppDomain.DefineDynamicAssembly(myAssemblyName, 
                AssemblyBuilderAccess.Save);

            // Create a dynamic module 'myModuleBuilder'.
            ModuleBuilder myModuleBuilder = 
                myAssemblyBuilder.DefineDynamicModule("MyDynamicModule",
 true);

            // Define a public class 'MyDynamicClass'.
            TypeBuilder myTypeBuilder = myModuleBuilder.DefineType(
                "MyDynamicClass", TypeAttributes.Public);

            // Define a public string field named 'myField'.
            FieldBuilder myField = myTypeBuilder.DefineField("MyDynamicField"
, 
                String.class.ToType(), FieldAttributes.Public);

            // Define the dynamic method 'MyDynamicMethod'.
            MethodBuilder myMethodBuilder = myTypeBuilder.DefineMethod(
                "MyDynamicMethod", MethodAttributes.Private, int.class.ToType()
,
                new Type[] {});

            // Generate the IL for 'myMethodBuilder'.
            ILGenerator myMethodIL = myMethodBuilder.GetILGenerator();

            // Emit the necessary opcodes.
            myMethodIL.Emit(OpCodes.Ldarg_0);
            myMethodIL.Emit(OpCodes.Ldfld, myField);
            myMethodIL.Emit(OpCodes.Ret);

            // Create 'myTypeBuilder' class.
            Type myType1 = myTypeBuilder.CreateType();

            // Get the method information of 'myTypeBuilder'.
            MethodInfo myInfo[] = myType1.GetMethods(BindingFlags.NonPublic 
                | BindingFlags.Instance);

            // Print non-public methods present of 'myType1'.
            Console.WriteLine("\nThe Non-Public methods present in
 "
                + "'myType1' are:\n");
            for (int i = 0; i < myInfo.length;
 i++) {
                Console.WriteLine(((MethodInfo)myInfo.get_Item(i)).get_Name());
            }

            // Print the 'Attribute', 'Signature' of 'myMethodBuilder'.
            Console.WriteLine("\nThe Attribute of 'MyDynamicMethod' is :{0}"
,
                myMethodBuilder.get_Attributes());
            Console.WriteLine("\nThe Signature of 'MyDynamicMethod' is : \n"
 
                + myMethodBuilder.get_Signature());
        }
        catch (System.Exception e) {
            Console.WriteLine("Exception :{0}", e.get_Message());
        }
    } //main
} //MethodBuilderClass
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
MethodBuilder クラス
MethodBuilder メンバ
System.Reflection.Emit 名前空間



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

辞書ショートカット

すべての辞書の索引

MethodBuilder.DeclaringType プロパティのお隣キーワード
検索ランキング

   

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



MethodBuilder.DeclaringType プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2024 GRAS Group, Inc.RSS