-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssemblyLoader.cs
More file actions
53 lines (45 loc) · 1.25 KB
/
AssemblyLoader.cs
File metadata and controls
53 lines (45 loc) · 1.25 KB
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
using System.Reflection;
namespace SpaceEngineersLoader;
internal static class AssemblyLoader
{
private static readonly List<string> Paths = new();
private static readonly Dictionary<string, Assembly> ManagedAssemblies = new();
private static readonly string[] AssemblyExtensions = { "", ".dll" };
public static Assembly? GetOrLoadManaged(string name)
{
if (ManagedAssemblies.TryGetValue(name, out var managed))
{
return managed;
}
Assembly? loaded = LoadManaged(name);
if (loaded == null)
{
return null;
}
ManagedAssemblies[name] = loaded;
return loaded;
}
private static Assembly? LoadManaged(string name)
{
name = name.Split(',')[0];
foreach (string path in Paths)
{
foreach (var ext in AssemblyExtensions)
{
string file = Path.Combine(path, name + ext);
if (File.Exists(file))
{
return Assembly.LoadFrom(file);
}
}
}
return null;
}
public static void AddPath(string path)
{
if (!Paths.Contains(path))
{
Paths.Add(path);
}
}
}