/// <summary> /// Expose a plugin from a dll filename, if the dll is a valid plugin. /// </summary> private void ExposePlugin(string filename) { Assembly DLL = Assembly.LoadFile(filename); string[] names = DLL.GetManifestResourceNames(); //ResourceSet set = new ResourceSet(names[0]); string shortName = null; foreach (Type type in DLL.GetExportedTypes()) { if (typeof(IQuantSAPlugin).IsAssignableFrom(type)) // This class is a QuantSA plugin { IQuantSAPlugin plugin = Activator.CreateInstance(type) as IQuantSAPlugin; shortName = plugin.GetShortName(); MyAddIn.plugins.Add(plugin); } } if (shortName == null) { throw new Exception(Path.GetFileName(filename) + " is in the Plugins directory but is not a valid plugin."); } foreach (Type type in DLL.GetExportedTypes()) { foreach (MemberInfo member in type.GetMembers()) { QuantSAExcelFunctionAttribute attribute = member.GetCustomAttribute <QuantSAExcelFunctionAttribute>(); if (attribute != null) // We have found an excel exposed function. { if (!attribute.Category.Equals(shortName)) { throw new Exception(attribute.Name + " in plugin " + shortName + " is not in the excel category " + shortName); } string[] parts = attribute.Name.Split('.'); if (!(parts.Length == 2 && parts[0].Equals(shortName))) { throw new Exception(attribute.Name + " in plugin " + shortName + "does not following the naming convention: " + shortName + ".FunctionName"); } // TODO: Check that the category and naming are all acceptable UpdateDelgatesAndAtribs((MethodInfo)member); } if (member.MemberType.Equals(MemberTypes.Method)) { if (((MethodInfo)member).ReturnType.Equals(typeof(System.Drawing.Bitmap))) { Bitmap image = ((MethodInfo)member).Invoke(null, null) as Bitmap; assemblyImageResources.Add(member.Name.Substring(4), image); } } } } }
public void SetInstance(IQuantSAPlugin itself) { PluginConnection.instance = itself; }