-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDllHelper.cs
More file actions
120 lines (109 loc) · 3.87 KB
/
DllHelper.cs
File metadata and controls
120 lines (109 loc) · 3.87 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace DynamicScriptExecutor
{
public class DllHelper
{
public static FileSystemInfo[] GetDllInfos(string path)
{
string folderPath = path;
DirectoryInfo dir = new DirectoryInfo(folderPath);
FileSystemInfo[] dllInfos = null;
if (dir.Exists)
{
DirectoryInfo dirD = dir as DirectoryInfo;
dllInfos = dirD.GetFileSystemInfos();
}
return dllInfos;
}
public static ICollection<string> GetExtraDllNamespaces(ExecOption execOption)
{
if (!execOption.AddExtraUsingWhenGeneratingClass)
{
return new HashSet<string>();
}
List<Assembly> extraAssemblies = new List<Assembly>();
GetExtraDllsAndAssemblies(execOption, null, extraAssemblies);
HashSet<string> result = new HashSet<string>();
foreach (Assembly assembly in extraAssemblies)
{
foreach (Type type in assembly.GetTypes())
{
if (!result.Contains(type.Namespace))
{
result.Add(type.Namespace);
}
}
}
return result;
}
internal static void GetExtraDllsAndAssemblies(ExecOption execOption, List<string> dlls, List<Assembly> extraAssemblies)
{
// Dll文件夹中的dll
if (execOption.ExtraDllFolderList != null)
{
foreach (string extraDllFolder in execOption.ExtraDllFolderList)
{
FileSystemInfo[] dllInfos = GetDllInfos(extraDllFolder);
if (dllInfos != null && dllInfos.Count() != 0)
{
foreach (FileSystemInfo dllInfo in dllInfos)
{
Assembly assembly = Assembly.LoadFrom(dllInfo.FullName);
if (dlls != null)
{
dlls.Add(dllInfo.FullName);
}
if (extraAssemblies != null)
{
extraAssemblies.Add(assembly);
}
}
}
}
}
// 单独的dll
if (execOption.ExtraDllFileList != null)
{
foreach (string extraDllFile in execOption.ExtraDllFileList)
{
if (dlls != null)
{
dlls.Add(extraDllFile);
}
if (extraAssemblies != null)
{
Assembly assembly = Assembly.LoadFrom(extraDllFile);
extraAssemblies.Add(assembly);
}
}
}
}
internal static string ExtractPath(string text)
{
string pattern = "[\"'“”‘’]([^\"'“”‘’]+)[\"'“”‘’]";
var match = Regex.Match(text, pattern);
if (match.Success)
{
foreach (Group group in match.Groups)
{
if (group.Value.Contains("'") || group.Value.Contains("\"") || group.Value.Contains("“"))
{
continue;
}
else
{
return group.Value;
}
}
}
return null;
}
}
}