using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Reflection;
using System.IO;
using Contracts;
namespace Test
{
class Program
{
static void Main(string[] args)
{
SetupPlugEnvironment();
ExecuteOperator("1.0.0.0");
ExecuteOperator("2.0.0.0");
}
private static void ExecuteOperator(string version)
{
var operatorType = Type.GetType("Implements.Operator, Implements, version = " + version + "");
var operatorInstance = Activator.CreateInstance(operatorType) as IOperator;
operatorInstance.Operate();
}
private static void SetupPlugEnvironment()
{
AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
}
static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
AssemblyName name = new AssemblyName(args.Name);
var file = Path.Combine(
@"E:\Coding\HappyStudy\LoadContextStudy\Test\bin\Debug\Plugs",
name.Name,
name.Version.ToString(),
name.Name + ".dll");
Console.WriteLine("加载插件:" + name.Version);
return Assembly.LoadFile(file);
}
}
}