码迷,mamicode.com
首页 > Windows程序 > 详细

C#中动态加载以及推迟绑定

时间:2015-05-14 08:37:28      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace Reflection
{
    class Program
    {
        static void Main(string[] args)
        {
            Assembly objAssembly;
            objAssembly = Assembly.Load("mscorlib,2.0.0.0,Neutral,b77a5c");

            Type[] types = objAssembly.GetTypes();
            //foreach (var t in types)
            //{
            //    Console.WriteLine(t.Name);
            //}

            objAssembly = Assembly.GetExecutingAssembly();

            Type t = objAssembly.GetType("Reflection.Car",false,true);

            Object obj = Activator.CreateInstance(t);
            MethodInfo mi = t.GetMethod("IsMoving");

            var isMoving = (bool)mi.Invoke(obj,null);

            if (isMoving)
            {
                Console.WriteLine("Is Moving");
            }
            else
            {
                Console.WriteLine("Not is moving");
              }

            Console.ReadLine();
        }
      
    }
    public class Car
    {
        public bool IsMoving()
        {
            return true;

        }
    }
}

 

C#中动态加载以及推迟绑定

标签:

原文地址:http://www.cnblogs.com/heisaijuzhen/p/4502307.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!