3

アプリケーションをどのように設計するか、実際にはFirefoxやChromeなどのアドオンをダウンロードして使用できるアプリケーションを知りたいです??!! .Netでどのように行うのですか???

4

3 に答える 3

3

他のユーザーがアプリのアドオンを作成できるようにする方法は?

1>DLLを持つ を作成しますinterface。これinterfaceは、他の人に定義および実装してもらいたい一連のメソッド、プロパティ、イベントを定義します。

プラグイン開発者は、このインターフェイスを定義する必要があります。この DLL は、アプリとプラグイン開発者に必要です。

2>プラグイン開発者は、その共有を使用しDLL、メソッドまたはプロパティを定義することでインターフェイスを実装します。

3>アプリはそのプラグインをロードして共有 DLL にキャストしinterface、必要なメソッド、プロパティ、つまりインターフェイスで定義されたものを呼び出します。

アプリはプラグインをどのように取得しますか?

folderを検索する場所を作成します。これは、他の人がpluginsいるフォルダですまたは.pluginsinstalledplaced


これはあなたの共有DLLです

//this is the shared plugin
namespace Shared 
{
    interface IWrite 
    {
        void write();
    }
}

プラグイン開発者

//this is how plugin developer would implement the interface
using Shared;//<-----the shared dll is included
namespace PlugInApp 
{
    public class plugInClass : IWrite //its interface implemented
    {
        public  void write() 
        {
            Console.Write("High from plugInClass");
        }
    }
}

これはあなたのプログラムです

using Shared;//the shared plugin is required for the cast
class Program
    {
        static void Main(string[] args)
        {
            //this is how you search in the folder
            foreach (string s in Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "*PlugIn.dll"))//getting plugins in base directory ending with PlugIn.dll
            {
                Assembly aWrite = Assembly.LoadFrom(s);
                //this is how you cast the plugin with the shared dll's interface
                Type tWrite = aWrite.GetType("PlugInApp.plugInClass");
                IWrite click = (IWrite)Activator.CreateInstance(tWrite);//you create the object
                click.write();//you call the method
            }
        } 
    }
于 2012-12-01T10:20:40.100 に答える
2

Managed Extensibility Framework (MEF) を使用する必要があります。

http://mef.codeplex.com/

http://msdn.microsoft.com/en-us/library/dd460648.aspx

于 2012-12-01T09:54:49.490 に答える
0

MEF を使用します。

Managed Extensibility Framework (MEF) は、.NET の新しいライブラリであり、アプリケーションとコンポーネントの再利用を大幅に促進します。MEF を使用すると、.NET アプリケーションは、静的にコンパイルされたものから動的に構成されたものへと移行できます。拡張可能なアプリケーション、拡張可能なフレームワーク、およびアプリケーションの拡張機能を構築している場合は、MEF が適しています。

MEF の便利なリンク。

http://mef.codeplex.com/

http://www.codeproject.com/Articles/376033/From-Zero-to-Proficient-with-MEF

http://www.codeproject.com/Articles/232868/MEF-Features-with-Examples

于 2012-12-01T11:13:12.597 に答える