注意:所有示例代码都大大简化了。
我有一个 DLL 定义为:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Web;
namespace RIV.Module
{
public interface IModule
{
StringWriter ProcessRequest(HttpContext context);
string Decrypt(string interactive);
string ExecutePlayerAction(object ParamObjectFromFlash);
void LogEvent(object LoggingObjectFromFlash);
}
}
现在,在我的解决方案之外,其他开发人员可以定义具体的类并将它们放入我的应用程序的 BIN 文件夹中。也许是这样的:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RIV.Module;
namespace RIV.Module.Greeting
{
public class Module : IModule
{
public System.IO.StringWriter ProcessRequest(System.Web.HttpContext context)
{
//...
}
public string Decrypt(string interactive)
{
//...
}
public string ExecutePlayerAction(object ParamObjectFromFlash)
{
//...
}
public void LogEvent(object LoggingObjectFromFlash)
{
//...
}
}
}
现在,在我的应用程序中,我需要知道有一个新模块可用(我猜测是通过 web.config 或类似的东西),然后能够根据数据库 Campaign 表中的某个触发器调用它(映射到用于该特定活动的模块)。
我正在尝试以这种方式实例化它:
var type = typeof(RIV.Module.Greeting.Module);
var obj = (RIV.Module.Greeting.Module)Activator.CreateInstance(type);
但是,编译器会打嗝,因为从未将引用设置为RIV.Module.Greeting.dll!
我究竟做错了什么?