-
Notifications
You must be signed in to change notification settings - Fork 1
/
AssemblyReference.cs
90 lines (82 loc) · 2.93 KB
/
AssemblyReference.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Copyright 2012 - 2013 dbones.co.uk
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Boxes
{
using System.Reflection;
using FileScanning;
/// <summary>
/// contains information about an assembly, this is required to load it into the app domain
/// note this is used to lazy load the assembly.
/// </summary>
public class AssemblyReference
{
/// <summary>
/// ctor
/// </summary>
/// <param name="file">the associated file</param>
/// <param name="assemblyName">the assemblies name</param>
public AssemblyReference(File file, AssemblyName assemblyName)
{
File = file;
AssemblyName = assemblyName;
Module = new Module(assemblyName);
}
/// <summary>
/// the assemblies file
/// </summary>
public File File { get; private set; }
/// <summary>
/// the assemblies name
/// </summary>
public AssemblyName AssemblyName { get; private set; }
/// <summary>
/// the actual assembly, once it has been loaded.
/// </summary>
public Assembly Assembly { get; private set; }
/// <summary>
/// the assemblies module information
/// </summary>
public Module Module { get; private set; }
/// <summary>
/// load the assembly from the file
/// </summary>
public void LoadFromFile()
{
if (Assembly== null)
{
Assembly = Assembly.LoadFile(File.FullName);
//is it possible to use the following line, and supply
//some form of location meta-data, as this will allow
//to abstract out the folder dir and use zipfiles/network streams/etc
//Assembly = Assembly.Load(File.ContentsAsBytes);
}
}
/// <summary>
/// provide an instance of the assembly to associate with this assemblyReference
/// </summary>
/// <param name="assembly">the instance of the assembly</param>
public void AssociateWithExisting(Assembly assembly)
{
Assembly = assembly;
}
public override string ToString()
{
if (Assembly != null)
{
return Assembly.GetName().Name;
}
return string.Format("{0} - not loaded", File.Name);
}
}
}