我一直在試圖設計一個有效的接口,我用一些插件。我以爲我發現了一個體面的界面,但試圖實施它不是很好。所以我希望看看有沒有人在這裏有更好的建議,可以做到這一點。它的錯誤了與「不包含‘的GetEnumerator’一個公共定義」接口設計和效率比較兩個列表<string>
插件接口:
namespace ALeRT.PluginFramework
{
public interface IQueryPlugin
{
string PluginCategory { get; }
string Name { get; }
string Version { get; }
string Author { get; }
System.Collections.Generic.List TypesAccepted { get; }
}
interface IQueryPluginRBool : IQueryPlugin
{
bool Result(string input, bool sensitive);
}
interface IQueryPluginRString : IQueryPlugin
{
string Result(string input, bool sensitive);
}
}
從本質上說,我試圖採取的應使用類型列表中(類型可能是URL,名稱,電子郵件,IP等),並將它們與查詢插件中的值進行比較。每個查詢插件可能有多種類型,它接受。匹配時,它將執行查詢插件中的操作。
[ImportMany]
public IEnumerable<IQueryPlugin> QPlugins { get; set; }
private void QueryPlugins(List<string> val, bool sensitive)
{
foreach (string tType in val) //Cycle through a List<string>
{
foreach (var qPlugins in this.QPlugins) //Cycle through all query plugins
{
foreach (string qType in qPlugins) //Cycle though a List<string> within the IQueryPlugin interface AcceptedTypes
{
if (qType == tType) //Match the two List<strings>, one is the AcceptedTypes and the other is the one returned from ITypeQuery
{
//Do stuff here
}
}
}
}
}
什麼是this.QPlugins?你能否顯示方法QPlugins中引用的所有代碼? –
對不起,在第二部分代碼的[ImportMany]中加入了。 – lordzero
您是否閱讀過我的答案? –