Last active
October 1, 2016 10:41
-
-
Save rwindegger/6754668a1ec8632d1b75f9e3e2f4264c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// <copyright file="AddinLoader.cs" company="Rene Windegger"> | |
// Copyright (c) 2013 Rene Windegger. All rights reserved. | |
// </copyright> | |
// <author>Rene Windegger</author> | |
// <date>23.12.2013</date> | |
// <summary>Implements the addin loader class</summary> | |
namespace wtf.windegger.addinframework | |
{ | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Reflection; | |
using System.Text; | |
using System.Threading.Tasks; | |
/// <summary> An addin loader. </summary> | |
/// <remarks> Rene Windegger, 23.12.2013. </remarks> | |
/// <typeparam name="PluginIdentifier"> Type of the plugin identifier. </typeparam> | |
/// <typeparam name="PluginType"> Type of the plugin type. </typeparam> | |
public class AddinLoader<PluginIdentifier, PluginType> | |
where PluginIdentifier : AddinIdentifierAttribute | |
{ | |
/// <summary> Identifier for the plugin. </summary> | |
private readonly Type m_PluginIdentifier; | |
/// <summary> Type of the plugin. </summary> | |
private readonly Type m_PluginType; | |
/// <summary> The addins. </summary> | |
private List<Addin<PluginType>> m_Addins = new List<Addin<PluginType>>(); | |
/// <summary> Gets the addins. </summary> | |
/// <value> The addins. </value> | |
public List<Addin<PluginType>> Addins | |
{ | |
get | |
{ | |
return m_Addins; | |
} | |
private set | |
{ | |
m_Addins = value; | |
} | |
} | |
/// <summary> Initializes a new instance of the AddinLoader class. </summary> | |
/// <remarks> Rene Windegger, 23.12.2013. </remarks> | |
public AddinLoader() | |
{ | |
m_PluginIdentifier = typeof(PluginIdentifier); | |
m_PluginType = typeof(PluginType); | |
} | |
/// <summary> Loads addins from file. </summary> | |
/// <remarks> Rene Windegger, 23.12.2013. </remarks> | |
/// <param name="fileName"> Filename of the file. </param> | |
public void LoadAddinsFromFile(string fileName) | |
{ | |
Assembly currentAssembly = Assembly.LoadFrom(fileName); | |
LoadAddinsFromAssembly(currentAssembly); | |
} | |
/// <summary> Loads addins from assembly. </summary> | |
/// <remarks> Rene Windegger, 23.12.2013. </remarks> | |
/// <param name="assembly"> The assembly. </param> | |
public void LoadAddinsFromAssembly(Assembly assembly) | |
{ | |
PluginIdentifier[] Attributes = (PluginIdentifier[])assembly.GetCustomAttributes(m_PluginIdentifier, false); | |
foreach (PluginIdentifier i in Attributes) | |
{ | |
m_Addins.Add(new Addin<PluginType>(assembly.GetType(i.ClassName))); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment