개정판 43e1d368
issue #0000 코드 정리
Change-Id: I7c8ba4ef6d78a7e4f51b72f226507cddac722939
ConvertService/ServiceBase/Markus.Service.Extensions/Exntensions/GenericPluginLoader.cs | ||
---|---|---|
18 | 18 |
using System.Collections.Generic; |
19 | 19 |
using System.IO; |
20 | 20 |
using System.Reflection; |
21 |
using System.Linq; |
|
21 | 22 |
|
22 | 23 |
namespace Markus.Service.Extensions |
23 | 24 |
{ |
... | ... | |
28 | 29 |
string[] dllFileNames = null; |
29 | 30 |
|
30 | 31 |
if(Directory.Exists(path)) |
31 |
{ |
|
32 |
{ |
|
33 |
ICollection<Assembly> assemblies = new List<Assembly>(); |
|
34 |
ICollection<T> plugins = new List<T>(); |
|
35 |
Type pluginType = typeof(T); |
|
36 |
|
|
32 | 37 |
dllFileNames = Directory.GetFiles(path, "*.dll",SearchOption.AllDirectories); |
33 | 38 |
|
34 |
ICollection<Assembly> assemblies = new List<Assembly>(dllFileNames.Length); |
|
39 |
if(dllFileNames.Count() == 0) |
|
40 |
{ |
|
41 |
throw new Exception($"download Plugin Not Found. {path}"); |
|
42 |
} |
|
43 |
|
|
35 | 44 |
foreach(string dllFile in dllFileNames) |
36 | 45 |
{ |
37 | 46 |
AssemblyName an = AssemblyName.GetAssemblyName(dllFile); |
38 | 47 |
Assembly assembly = Assembly.Load(an); |
39 |
assemblies.Add(assembly); |
|
40 |
} |
|
41 | 48 |
|
42 |
Type pluginType = typeof(T); |
|
43 |
ICollection<Type> pluginTypes = new List<Type>(); |
|
44 |
foreach(Assembly assembly in assemblies) |
|
45 |
{ |
|
46 |
if(assembly != null) |
|
49 |
if (assembly.GetTypes()[0].GetInterfaces().Count(x=>x == pluginType) > 0) |
|
47 | 50 |
{ |
48 |
Type[] types = assembly.GetTypes(); |
|
49 |
|
|
50 |
foreach(Type type in types) |
|
51 |
{ |
|
52 |
if(type.IsInterface || type.IsAbstract) |
|
53 |
{ |
|
54 |
continue; |
|
55 |
} |
|
56 |
else |
|
57 |
{ |
|
58 |
if(type.GetInterface(pluginType.FullName) != null) |
|
59 |
{ |
|
60 |
pluginTypes.Add(type); |
|
61 |
} |
|
62 |
} |
|
63 |
} |
|
51 |
assemblies.Add(assembly); |
|
64 | 52 |
} |
65 | 53 |
} |
66 | 54 |
|
67 |
ICollection<T> plugins = new List<T>(pluginTypes.Count); |
|
68 |
foreach(Type type in pluginTypes) |
|
69 |
{ |
|
70 |
T plugin = (T)Activator.CreateInstance(type); |
|
71 |
plugins.Add(plugin); |
|
72 |
} |
|
55 |
ICollection<Type> pluginTypes = new List<Type>(); |
|
56 |
foreach (Assembly assembly in assemblies) |
|
57 |
{ |
|
58 |
if (assembly != null) |
|
59 |
{ |
|
60 |
Type[] types = assembly.GetTypes(); |
|
61 |
|
|
62 |
foreach (Type type in types) |
|
63 |
{ |
|
64 |
if (type.IsInterface || type.IsAbstract) |
|
65 |
{ |
|
66 |
continue; |
|
67 |
} |
|
68 |
else |
|
69 |
{ |
|
70 |
if (type.GetInterface(pluginType.FullName) != null) |
|
71 |
{ |
|
72 |
pluginTypes.Add(type); |
|
73 |
} |
|
74 |
} |
|
75 |
} |
|
76 |
} |
|
77 |
} |
|
78 |
|
|
79 |
foreach (Type type in pluginTypes) |
|
80 |
{ |
|
81 |
T plugin = (T)Activator.CreateInstance(type); |
|
82 |
plugins.Add(plugin); |
|
83 |
} |
|
73 | 84 |
|
74 |
return plugins;
|
|
85 |
return plugins;
|
|
75 | 86 |
} |
76 | 87 |
|
77 | 88 |
return null; |
내보내기 Unified diff