-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathLegacySolcNet.cs
67 lines (60 loc) · 2.07 KB
/
LegacySolcNet.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
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
namespace Meadow.SolCodeGen
{
static class LegacySolcNet
{
public static string ResolveNativeLibPath(string solcNetLegacyLibFile, Version solcVersion)
{
Assembly solcNetLegacyAssembly;
try
{
solcNetLegacyAssembly = Assembly.LoadFile(solcNetLegacyLibFile);
}
catch (Exception ex)
{
throw new Exception("Failed to load SolcNet.Legacy assembly from file: " + solcNetLegacyLibFile, ex);
}
Type resolverClassType;
const string SOLCNET_LEGACY_LIBPATH = "SolcNet.Legacy.LibPath";
try
{
resolverClassType = solcNetLegacyAssembly.GetType(SOLCNET_LEGACY_LIBPATH, throwOnError: true, ignoreCase: false);
}
catch (Exception ex)
{
throw new Exception($"Failed to load class {SOLCNET_LEGACY_LIBPATH} from SolcNet.Legacy", ex);
}
const string GET_LIB_PATH = "GetLibPath";
MethodInfo getLibPathMethod;
try
{
getLibPathMethod = resolverClassType.GetMethod(GET_LIB_PATH, new[] { typeof(Version) });
if (getLibPathMethod == null)
{
throw new Exception("Null GetMethod result");
}
}
catch (Exception ex)
{
throw new Exception($"Failed to find method {GET_LIB_PATH} in SolcNet.Legacy", ex);
}
string nativeLib;
try
{
nativeLib = (string)getLibPathMethod.Invoke(null, new object[] { solcVersion });
}
catch (TargetInvocationException ex)
{
throw ex.InnerException;
}
catch (Exception ex)
{
throw new Exception($"Exception when invoking {GET_LIB_PATH}", ex);
}
return nativeLib;
}
}
}