#region License Information
/* HeuristicLab
* Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using System.Diagnostics;
using System.Linq;
namespace HeuristicLab.PluginInfrastructure {
///
/// Default implementation of the IPlugin interface.
///
public abstract class PluginBase : IPlugin {
///
/// Initializes a new instance of .
///
public PluginBase() { }
private PluginAttribute PluginAttribute {
get {
object[] pluginAttributes = this.GetType().GetCustomAttributes(typeof(PluginAttribute), false);
// exactly one attribute of the type PluginDescriptionAttribute must be given
if (pluginAttributes.Length != 1) {
throw new InvalidPluginException("Found multiple PluginAttributes on type " + this.GetType());
}
return (PluginAttribute)pluginAttributes[0];
}
}
#region IPlugin Members
///
public string Name {
get {
return PluginAttribute.Name;
}
}
/////
//public Version Version {
// get {
// var pluginAttribute = PluginDescriptionAttribute;
// // if the version is not set in the attribute then the version of the assembly is used as default
// if (string.IsNullOrEmpty(pluginAttribute.Version)) {
// return this.GetType().Assembly.GetName().Version;
// } else {
// return new Version(pluginAttribute.Version);
// }
// }
//}
/////
//public string Description {
// get {
// var pluginAttribute = PluginDescriptionAttribute;
// // if the description is not explicitly set in the attribute then the name of the plugin is used as default
// if (string.IsNullOrEmpty(pluginAttribute.Description)) {
// return pluginAttribute.Name;
// } else {
// return pluginAttribute.Description;
// }
// }
//}
///
public IEnumerable FileNames {
get {
// get all attributes of type PluginFileAttribute, multiple usage is possible
return from x in this.GetType().GetCustomAttributes(typeof(PluginFileAttribute), false)
let pluginFileAttr = (PluginFileAttribute)x
select pluginFileAttr.Filename;
}
}
///
public virtual void OnLoad() { }
#endregion
}
}