cを文字列に一致するプラグインを取得し、私のプラグインクラスは、私は、ときにアプリケーションと呼ばれている各プラグインのAction
メソッドを呼び出す機能を持っている私のローダークラスでは、この私はプラグインシステムを持っている#
namespace CSV_Analyzer_Pro.Core.PluginSystem
{
public interface IPlugin
{
string Name { get; }
string Version { get; }
string TargetVersion { get; }
string Description { get; }
string TargetFramework { get; }
void Action();
}
}
のように見えます
public void Init()
{
if(Plugins != null)
{
Plugins.ForEach(plugin => plugin.Action());
}
}
をロードされ、私は自分のアプリケーションに
を呼び出すことができますので、私は似メソッドを使用したいですそれは何を知っているのに役立ちます場合はこれはこれは私がこれまで
public void GetPluginByTargetFramework(string framework)
{
//Get all plugins
List<IPlugin> frameworkPlugs = new List<IPlugin>();
//Put all plugins targeting framework into list
if(frameworkPlugs != null)
{
frameworkPlugs.ForEach(plugin => plugin.Action());
}
}
持っているものである
"UI"
フレームワークをターゲットにすべてのプラグインを取得し、リストに入れ、その後、私は方法を反復処理することができなければなりません異なる変数はここにある全体PluginLoader
クラス
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using System.Threading.Tasks;
namespace CSV_Analyzer_Pro.Core.PluginSystem {
public class PluginLoader {
public static List<IPlugin> Plugins { set; get; }
public void LoadPlugins() {
Plugins = new List<IPlugin>();
if (Directory.Exists(Constants.PluginFolder)) {
string[] files = Directory.GetFiles(Constants.PluginFolder);
foreach(string file in files) {
if (file.EndsWith(".dll")) {
Assembly.LoadFile(Path.GetFullPath(file));
}
}
}
Type interfaceType = typeof(IPlugin);
Type[] types = AppDomain.CurrentDomain.GetAssemblies().SelectMany(a => a.GetTypes()).Where(p => interfaceType.IsAssignableFrom(p) && p.IsClass).ToArray();
foreach(Type type in types) {
Plugins.Add((IPlugin)Activator.CreateInstance(type));
}
}
public void Init() {
if(Plugins != null) {
Plugins.ForEach(plugin => plugin.Action());
}
}
public void GetPluginByTargetFramework(string framework) {
//Get all plugins
List<IPlugin> frameworkPlugs = new List<IPlugin>();
//Put all plugins targeting framework into list
if(frameworkPlugs != null) {
frameworkPlugs.ForEach(plugin => plugin.Action());
}
}
}
}
したがって、特定の 'フレームワーク 'を持つ' Plugins'の項目だけが必要ですか? –
あなたの_question_は何ですか?それは何ですか?具体的には、あなたは理解しづらいことがありますか?あなたの疑問を解決して、良いコード[mcve]が含まれていることを確認し、そのコードが現在正確に何をしているのか、あなたが何をしたいのかを明確かつ詳細に説明し、解決できない_specific_問題の説明。 –