标签:
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; } } }
标签:
原文地址:http://www.cnblogs.com/heisaijuzhen/p/4502307.html