2010-11-23 81 views
0

在我的桌面應用程序中,我在使用Interface類中的函數時遇到了問題。C#中的接口類

我有這樣的功能,用於執行插件

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 as

錯誤1類型名稱'IMFDBAnalyserPlugin'不存在於型 'MFDBAnalyser.MFDBAnalyser' d:\項目\ Mindfire \ GoalPlan \ MFDBAnalyser \ MFDBAnalyser \ PluginManager.cs 57 107 MFDBAnalyser

誰能幫助我

+0

C#中沒有`interface class`,只有`interface`或`class`。我認爲應該是'接口IMFDBAnalyserPlugin`,否則它不會編譯。 – 2010-11-23 06:02:21

+0

...只是FYI,沒有接口... – 2010-11-23 06:05:38

回答

1
namespace MFDBAnalyser 
{ 
    interface IMFDBAnalyserPlugin 
    { 
     void ExecutePlugin(); 
    } 
} 

否則oType.GetInterface("IMFDBAnalyserPlugin")將始終爲空,因爲那裏沒有這樣的接口。

2

你是否包括在usings MFDBAnalyser主要課程?

喜歡的東西

using MFDBAnalyser; 
PluginManager

此外,

你應該改變

public class IMFDBAnalyserPlugin 
{ 
    void ExecutePlugin(); 
} 

public interface IMFDBAnalyserPlugin 
{ 
    void ExecutePlugin(); 
} 

看一看interface (C# Reference)