﻿/* ======================================================================== 
* 【本类功能概述】 
* 
* 作者：He Jiaxun 时间：2014-6-24 18:38:41 
* 文件名：ReflectionUsage 
* CLR版本：4.0.30319.1022
* ======================================================================== 
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Demo_ExtensionMethod.IDAL;
using Demo_ExtensionMethod.Common;
using System.Threading;
using System.Reflection;

namespace Demo_Reflection
{
    public class ReflectionUsage
    {
        /// <summary>
        /// 演示反射方法的调用
        /// </summary>
        public static void DisplayMethodInvoke()
        {
            IExampleDAL iExampleDAL = Factory.CreateExampleDAL();
            Type t = iExampleDAL.GetType();
            Console.WriteLine("Instance of Type \'{0}\' has been created.", t.FullName);
            Thread.Sleep(1000);
            Console.WriteLine("开始遍历对象的方法...");
            Thread.Sleep(1000);
            MethodInfo[] methods = t.GetMethods();
            foreach (MethodInfo method in methods)
            {
                Console.WriteLine(method.Name);
            }
            Thread.Sleep(1000);
            Console.WriteLine("调用删除方法...");
            Thread.Sleep(1000);
            MethodInfo deleteMethod = t.GetMethod("DeleteExample");
            deleteMethod.Invoke(iExampleDAL, new object[] { 10 });//参数1类型为object[]，代表方法的对应参数，输入值为null代表没有参数
            Console.WriteLine("删除完毕");
        }
    }
}
