日期:2014-05-18 浏览次数:21190 次
static class GlobalData {
public static Dictionary<string, Action> dict = new Dictionary<string, Action>();
}
------解决方案--------------------
把函数当做参数传递,在使用函数前,定义函数并把它加入到楼上说的函数字典里,这样通过函数字典就知道要调用哪个方法了
------解决方案--------------------
这个需要用到assembly和interface的内容。给你一段我自己的代码吧,我一直这么用。
private void initializeAssemblys()
{
List<string> FileNames = getFileFullNames("FunModules");
Assembly assembly = null;
IChildModule childModule = null;
foreach (string fileName in FileNames)
{
try
{
assembly = Assembly.LoadFile(fileName);
string assemblyString = getNameFromFull(fileName);
Type childModuleType = assembly.GetType(assemblyString + "." + assemblyString + "Assembly");
if (childModuleType == null) continue;
if (!childModuleType.GetType().IsInstanceOfType(typeof(IChildModule))) continue;
childModule = childModuleType.GetConstructor(new Type[] { }).Invoke(new object[] { }) as IChildModule;
childModule.childService.Connection = MainForm.service.Connection;
childModule.LoginUser = MainForm.LoginUser;
childModules.Add(childModule);
}
catch (FileLoadException ex)
{
onChildModuleErr(new Exception(fileName + " load err," + ex.Message));
}
catch (Exception ex)
{
onChildModuleErr(ex);
}
}
}