日期:2014-05-18  浏览次数:20939 次

C#打开窗体有问
http://q.cnblogs.com/q/35451/

CSDN 连张图片都上传不了,真是悲催。
烦请各位移步博 客 园帮忙看看这个问题,万分感谢。

------解决方案--------------------
前提是委托怎么用你自己学。大概说说:

定义一个全局的字典:
C# code
static class GlobalData {
    public static Dictionary<string, Action> dict = new Dictionary<string, Action>();
}

------解决方案--------------------
把函数当做参数传递,在使用函数前,定义函数并把它加入到楼上说的函数字典里,这样通过函数字典就知道要调用哪个方法了
------解决方案--------------------
这个需要用到assembly和interface的内容。给你一段我自己的代码吧,我一直这么用。
C# code

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);
                }
            }
        }