forked from Xamla/ROS.NET
-
Notifications
You must be signed in to change notification settings - Fork 2
/
AssemblyResolver.cs
32 lines (27 loc) · 994 Bytes
/
AssemblyResolver.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
namespace YAMLParser
{
public class AssemblyResolver : IDisposable
{
private readonly IEnumerable<Assembly> assemblies;
private readonly AppDomain appDomain;
public AssemblyResolver(IEnumerable<Assembly> assemblies, AppDomain appDomain)
{
this.assemblies = assemblies ?? throw new ArgumentNullException(nameof(assemblies));
this.appDomain = appDomain ?? throw new ArgumentNullException(nameof(appDomain));
this.appDomain.AssemblyResolve += OnAssemblyResolve;
}
public void Dispose()
{
this.appDomain.AssemblyResolve -= OnAssemblyResolve;
}
private Assembly OnAssemblyResolve(object sender, ResolveEventArgs args)
{
var assembly = assemblies.FirstOrDefault(x => x.FullName == args.Name);
return assembly;
}
}
}