forked from saary/node.net
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathSharpLibHelper.cpp
More file actions
41 lines (33 loc) · 1.19 KB
/
SharpLibHelper.cpp
File metadata and controls
41 lines (33 loc) · 1.19 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
#include "SharpLibHelper.h"
#include "WrapBase.h"
#using <mscorlib.dll>
using namespace System::Reflection;
using namespace System::IO;
using namespace System;
using namespace v8;
// we need to look for the assembly in the current directory
// by default node will search next to the node.exe binary
System::Reflection::Assembly ^OnAssemblyResolve(System::Object ^obj, System::ResolveEventArgs ^args)
{
System::String ^path = System::Environment::CurrentDirectory;
Console::WriteLine("Resolving an assembly..." + path);
array<System::String^>^ assemblies =
System::IO::Directory::GetFiles(path, "*.dll");
for (long ii = 0; ii < assemblies->Length; ii++) {
AssemblyName ^name = AssemblyName::GetAssemblyName(assemblies[ii]);
if (AssemblyName::ReferenceMatchesDefinition(gcnew AssemblyName(args->Name), name)) {
return Assembly::Load(name);
}
}
return nullptr;
}
// register a custom assembly load handler
void LoadAssembly()
{
System::AppDomain::CurrentDomain->AssemblyResolve +=
gcnew System::ResolveEventHandler(OnAssemblyResolve);
}
Handle<Value> SharpLibHelper::Instance(const v8::Arguments& args)
{
return WrapBase::New();
}