反射原理的简单例子
源代码:CLib.rar
using System;
using System.Collections.Generic;
using System.Text;
namespace CLibConsole
{
public interface ITest
{
void SysTest();
}
}
using System.Collections.Generic;
using System.Text;
namespace CLibConsole
{
public interface ITest
{
void SysTest();
}
}
using System;
using System.Collections.Generic;
using System.Text;
using CLibConsole;
namespace CLibConsole
{
public class Test : ITest
{
public void SysTest()
{
System.Console.WriteLine("Hello Reflection");
}
}
}
using System.Collections.Generic;
using System.Text;
using CLibConsole;
namespace CLibConsole
{
public class Test : ITest
{
public void SysTest()
{
System.Console.WriteLine("Hello Reflection");
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
namespace CLibConsole
{
class Program
{
static void Main(string[] args)
{
//Assembly ass = System.Reflection.Assembly.LoadFrom("CLib.dll");
//Type type = ass.GetType("CLibConsole.Test");
//Type type = System.Activator.CreateInstanceFrom("CLib.dll", "CLibConsole.Test").GetType();
ITest test = (ITest)System.Activator.CreateInstance("CLib", "CLibConsole.Test").Unwrap();
test.SysTest();
}
}
}
using System.Collections.Generic;
using System.Text;
using System.Reflection;
namespace CLibConsole
{
class Program
{
static void Main(string[] args)
{
//Assembly ass = System.Reflection.Assembly.LoadFrom("CLib.dll");
//Type type = ass.GetType("CLibConsole.Test");
//Type type = System.Activator.CreateInstanceFrom("CLib.dll", "CLibConsole.Test").GetType();
ITest test = (ITest)System.Activator.CreateInstance("CLib", "CLibConsole.Test").Unwrap();
test.SysTest();
}
}
}