-
Notifications
You must be signed in to change notification settings - Fork 0
/
AppDomainConfigurator.cs
67 lines (54 loc) · 1.57 KB
/
AppDomainConfigurator.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System;
using System.IO;
using System.Reflection;
namespace Limes
{
public class AppDomainConfigurator : MarshalByRefObject, IDisposable
{
private readonly AppDomain _appDomain;
public AppDomainConfigurator()
{
_appDomain = AppDomain.CurrentDomain;
_appDomain.AssemblyResolve += OnAssemblyResolve;
}
internal AppDomainResolver SourceResolver { get; set; }
public void Dispose()
{
_appDomain.AssemblyResolve -= OnAssemblyResolve;
}
public void SetConsoleOut(TextWriter writer)
{
Console.SetOut(writer);
}
public void SetConsoleError(TextWriter writer)
{
Console.SetError(writer);
}
public void SetConsoleIn(TextReader reader)
{
Console.SetIn(reader);
}
public void LoadAssembly(string path)
{
Assembly.LoadFrom(path);
}
public void LoadAssembly(byte[] assembly)
{
Assembly.Load(assembly);
}
private Assembly OnAssemblyResolve(object sender, ResolveEventArgs args)
{
string path = null;
AppDomainResolver resolver = SourceResolver;
if (resolver != null)
{
path = resolver.Resolve(args.Name);
}
if (path != null)
{
return Assembly.LoadFrom(path);
}
return null;
}
}
}