forked from trungnt2910/MemoryModule.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNativeAssembly.cs
More file actions
68 lines (59 loc) · 1.89 KB
/
Copy pathNativeAssembly.cs
File metadata and controls
68 lines (59 loc) · 1.89 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
namespace MemoryModule
{
public class NativeAssembly : IDisposable
{
private IntPtr _handle;
private bool _disposedValue;
private NativeAssembly(IntPtr handle)
{
_handle = handle;
}
public static NativeAssembly Load(byte[] data)
{
return new NativeAssembly(NativeAssemblyImpl.LoadLibrary(data));
}
public void Unload()
{
IntPtr deadHandle = IntPtr.Zero;
deadHandle = Interlocked.Exchange(ref _handle, deadHandle);
if (deadHandle != IntPtr.Zero)
{
NativeAssemblyImpl.FreeLibrary(deadHandle);
}
}
public T GetDelegate<T>(string name) where T : Delegate
{
return NativeAssemblyImpl.GetDelegate<T>(_handle, name);
}
protected virtual void Dispose(bool disposing)
{
if (!_disposedValue)
{
if (disposing)
{
// TODO: dispose managed state (managed objects)
}
// TODO: free unmanaged resources (unmanaged objects) and override finalizer
// TODO: set large fields to null
Unload();
_disposedValue = true;
}
}
// TODO: override finalizer only if 'Dispose(bool disposing)' has code to free unmanaged resources
~NativeAssembly()
{
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
Dispose(disposing: false);
}
public void Dispose()
{
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
}
}