zoukankan      html  css  js  c++  java
  • 动态解析dll及使用类

    /// <summary>
            /// 动态解析dll
            /// </summary>
            public object DomainSerializer(Module _Module)
            {
                object ReturnValue = null;
                int state = 0;
                try
                {
                    //获取类库的绝对路径
                    string path = Server.MapPath("bin\" + _Module.DLLNAME + ".dll");
    
                    Assembly assembly = Assembly.LoadFile(path);
                    bool isExistsClass = false;
                    foreach (Type pluginType in assembly.GetTypes())
                    {
                        if (!pluginType.IsPublic || pluginType.IsAbstract || pluginType.IsInterface)
                            continue;
    
                        //判断参数是否一致及类名是否相同
                        if (pluginType.Name == _Module.CLASSNAME)
                        {
                            object obj = System.Activator.CreateInstance(pluginType);
                            MethodInfo Mymethodinfoa = pluginType.GetMethod(_Module.FUNNAME);
                            ParameterInfo[] Parameter = Mymethodinfoa.GetParameters();
                            if (Parameter.Count() == _Module.DICTION.Count())
                            {
                                isExistsClass = true;
                                state = 1;
                                ReturnValue = Mymethodinfoa.Invoke(obj, _Module.DICTION);
                            }
                        }
                    }
                    if (!isExistsClass)
                        ReturnValue="99类库" + _Module.DLLNAME + "中不存在" + _Module.CLASSNAME + "!";
                }
                catch (Exception ex)
                {
                    if (state == 0)
                        ReturnValue = "99类库" + _Module.DLLNAME + "加载失败!" + ex.Message;
                    else if (state == 1)
                        ReturnValue = "99"+_Module.CLASSNAME + "中方法参数不一致!" + ex.Message;
                }
                return ReturnValue;
            }
    更多技术交流+QQ:318617848
  • 相关阅读:
    放大图 带回弹效果
    用recyclerview实现对话(通过接口实现)
    java 问号表达式
    recyclerview的使用
    我遇到的报错信息整理
    横竖屏切换
    NOIP 2017提高组自测 奶酪
    小蝌蚪找妈妈 牛客
    牛客练习赛50 C tokitsukaze and Soldier
    洛谷P1630 求和
  • 原文地址:https://www.cnblogs.com/huyaguang/p/5888847.html
Copyright © 2011-2022 走看看