3
* Copyright © 2010, 2011, 2012 Wojciech Kowalczyk
4
* The program is distributed under the terms of the GNU General Public License Version 3.
5
* See LICENCE for details.
9
using System.Collections.Generic;
10
using System.Reflection;
11
using Glippy.Core.Api;
16
/// Plugins management.
18
public static class Plugins
23
/// <param name="dllName">Name of library which contains plugin.</param>
24
/// <returns>Loaded plugin instance or null.</returns>
25
public static IBase LoadPlugin(string dllName)
28
Assembly asm = Assembly.LoadFile((dllName.Contains(AppDomain.CurrentDomain.BaseDirectory) ? string.Empty : AppDomain.CurrentDomain.BaseDirectory) + dllName + (dllName.EndsWith(".dll") ? string.Empty : ".dll"));
30
foreach (Type t in asm.GetExportedTypes())
32
if (t.GetInterface(typeof(IBase).Name) != null)
33
plugin = Activator.CreateInstance(t) as IBase;
40
/// Loads all plugins.
42
public static List<IBase> LoadAllPlugins()
44
List<IBase> plugins = new List<IBase>();
46
foreach (string dll in System.IO.Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "*.dll"))
50
IBase plugin = LoadPlugin(dll);