2013年1月5日土曜日

A Simple Demo Of MethodInfo


using System;
using System.Reflection;
 
namespace MethodInfoDemo
{
    public class Sample
    {
        private readonly string _name;
 
        public Sample(string val)
        {
            _name = val;
        }
 
        public string YourName()
        {
            return _name;
        }
    }
 
    internal class Program
    {
        private static void Main(string[] args)
        {
            var s = new Sample("Nat");
            MethodInfo mi = typeof (Sample).GetMethod("YourName"new Type[] {});
            Console.WriteLine(mi.Invoke(snull));
            Console.ReadLine();
        }
    }
}

0 件のコメント:

コメントを投稿