本文介绍了Mono.Addin实现不检索加载项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Mono.Addins框架,C#和Visual Studio 2010编写可扩展的应用程序.

I'm writing an extendible application using Mono.Addins framework, C# and visual studio 2010.

我的应用程序的结构如下:

the structure of my application is the following:

project1:

namespace Plugins
{
    [TypeExtensionPoint]
    public interface IPlugin<InitParamsType>
    {
        void Refresh();

        string PlugInName { get; }

        void Initialize(InitParamsType parameters);
    }

    [TypeExtensionPoint]
    public interface IOrganizerPlugin : IPlugin<string>
    {
        bool AllowsToEditBrandCode { get; }

        UserControl GetUI();
    }

    public interface IPluginHost<PluginSpecalizedType>
    {
        void EmbedPlugin(PluginSpecalizedType plugin);
    }
}

项目2(引用project1):

project 2 (references project1):

    [assembly: AddinRoot("App.Organizer", "1.0")]
namespace App.Organizer
{
    public partial class frm_Supplier_Managed : Form, IPluginHost<IOrganizerPlugin>
        {

        public frm_Supplier_Managed()
        {
                 AddinManager.Initialize();
                AddinManager.Registry.Update(null);

                foreach (IOrganizerPlugin Addin in AddinManager.GetExtensionObjects(typeof(IOrganizerPlugin)))
                {
                    EmbedPlugin(Addin);
                }
         }


        public void EmbedPlugin(IOrganizerPlugin plugin)
        {
           //embedding UI and so on..
        }
        }
 }

项目3(引用项目1):

project 3 (references project 1):

[assembly: Addin("App.OrganizerPro", "1.0")]
[assembly: AddinDependency("App.Organizer", "1.0")]

namespace App
{
    [Extension]
    public class MainPlugIn : IOrganizerPlugin
    {
        public void Refresh()
        {
            return;
        }

        public string PlugInName
        {
            get { return ""; }
        }

        public void Initialize(string supplierCode)
        {
        }

        public UserControl Interface
        {
            get { return null; }
        }

        public bool AllowsToEditBrandCode
        {
            get { return true; }
        }

        public UserControl GetUI()
        {
            return null;
        }
    }
}

问题是:在foreach语句中没有产生插件.

the problem is:in the foreach statement no plugins are yielded.

p.s .:所有.dll都编译在同一目录中.

p.s.: all .dll are compiled in the same directory.

推荐答案

此处的问题是IOrganizerPlugin的扩展点是在project1中定义的,它既不是外接程序也不是外接程序根.解决方案是将此引用添加到project2中:

The problem here is that the extension point for IOrganizerPlugin is defined in project1, which is not an addin nor an add-in root. The solution is to add this reference in project2:

[assembly:ImportAddinAssembly("project1.dll")]

[assembly:ImportAddinAssembly ("project1.dll")]

通过这种方式,project1成为App.Organizer加载项根目录的一部分,并且project1.dll中的扩展点将被正确注册.

In this way project1 becomes part of the App.Organizer add-in root, and the extension points in project1.dll will be correctly registered.

这篇关于Mono.Addin实现不检索加载项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-13 22:03