[英]Interface class in C#
在我的桌面應用程序中,使用Interface類中的函數時遇到問題。
我有一個這樣的函數來執行插件
public static string ExecutePugin(string PluginName, string ConnectionString)
{
//ToDo: Get the plugin dll in the memory in a different appdomain. call RunAnalysis method of that
//ToDo: shift the primary key checking method to inside the plugin and return the result back.
//Loads the IMFDBAnalyserPlugin.exe to the current application domain.
AppDomain.CurrentDomain.Load("IMFDBAnalyserPlugin");
// Load the plugin's assembly to the current application doamin.
Assembly oAssembly = AppDomain.CurrentDomain.Load(PluginName);
// This block of code will execute the plugin's assembly code.
foreach (Type oType in oAssembly.GetTypes())
{
if (oType.GetInterface("IMFDBAnalyserPlugin") != null)
{
object oPlugin = Activator.CreateInstance(oType, null, null);
((MFDBAnalyser.IMFDBAnalyserPlugin)oPlugin).ExecutePlugin();
}
}
return string.Empty;
}
其中IMFDBAnalyserPlugin類是一個接口,並包含類似這樣的代碼
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MFDBAnalyser
{
public class IMFDBAnalyserPlugin
{
void ExecutePlugin();
}
}
但是在構建項目時,我在MFDBAnalyser.IMFDBAnalyserPlugin中收到錯誤
錯誤1類型名稱'IMFDBAnalyserPlugin'在類型'MFDBAnalyser.MFDBAnalyser'中不存在D:\\ Projects \\ Mindfire \\ GoalPlan \\ MFDBAnalyser \\ MFDBAnalyser \\ PluginManager.cs 57107 MFDBAnalyser
誰能幫我
您是否在主類的用法中包括MFDBAnalyser
?
就像是
using MFDBAnalyser;
在PluginManager
?
也,
你應該改變
public class IMFDBAnalyserPlugin
{
void ExecutePlugin();
}
至
public interface IMFDBAnalyserPlugin
{
void ExecutePlugin();
}
看看接口(C#參考)
namespace MFDBAnalyser
{
interface IMFDBAnalyserPlugin
{
void ExecutePlugin();
}
}
否則, oType.GetInterface("IMFDBAnalyserPlugin")
將始終為null,因為那里沒有此類接口。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.