メソッド名やクラス名を表示

Delegate で設定されたメソッド名やクラス名を表示します。

前田稔(Maeda Minoru)の超初心者のプログラム入門

プログラムの説明

  1. delegate には設定されたメソッド名やクラス名など、多くの情報が記録されています。
    これらの情報を幾つか拾い出して表示してみましょう。
  2. デリゲート(Sample)を生成して、記録されている情報を表示します。
    これ以外にも多くの情報が記録されているので試して下さい。
        delegate void TestDelegate();
    
        Class1 class1 = new Class1();
        TestDelegate testdelegate = new TestDelegate( class1.method );
        Console.WriteLine( testdelegate.Method.Name );
        Console.WriteLine( testdelegate.Method.CallingConvention );
        Console.WriteLine( testdelegate.Method.ReturnType );
        Console.WriteLine( testdelegate.Target.GetType().FullName );
        Console.WriteLine( testdelegate.Target.GetType().Attributes );
        
  3. プログラムの全ソースコードです。
    Delegate の基礎は Delegate の基礎 を参照して下さい。
    /*************************************************/
    /*★ メソッド名やクラス名を表示する    前田 稔 ★*/
    /*************************************************/
    using System;
    
    namespace ConsoleApp
    {
        delegate void TestDelegate();
        class Class1
        {
            public void method()
            {
                Console.WriteLine( "Hello!" );
            }
            static void Main()
            {
                Class1 class1 = new Class1();
                TestDelegate testdelegate = new TestDelegate( class1.method );
                Console.WriteLine( testdelegate.Method.Name );
                Console.WriteLine( testdelegate.Method.CallingConvention );
                Console.WriteLine( testdelegate.Method.ReturnType );
                Console.WriteLine( testdelegate.Target.GetType().FullName );
                Console.WriteLine( testdelegate.Target.GetType().Attributes );
                Console.ReadLine();
            }
        }
    }
    

超初心者のプログラム入門(C# Frame Work)