• 利用反射调用类及其属性和方法



            /// <summary> 从DLL获取对象
            /// </summary>
            /// <param name="PControl"></param>
            /// <param name="dllPath"></param>
            /// <param name="NameSpacePath"></param>
            /// <param name="className"></param>
            public object LoadObjectByDll(string dllPath, string NameSpacePath, string className,bool isExePreLoad)
            {
                try
                {
                    //加载控件        
                    System.Reflection.Assembly assembly = System.Reflection.Assembly.LoadFrom(dllPath);
                    //获得类(型)        
                    Type type = assembly.GetType(String.Format("{0}.{1}", NameSpacePath, className), false, true);
                    //设置筛选标志        
                    System.Reflection.BindingFlags bflags = System.Reflection.BindingFlags.DeclaredOnly | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance;
                    //调用构造函数并获得对象        
                    Object obj = type.InvokeMember(className, bflags | System.Reflection.BindingFlags.CreateInstance, null, null, null);
                    //if (isExePreLoad)
                    //{
                    //    object obj2;
                    //    PropertyInfo info = type.GetProperty("isPreLoad");
                    //    obj2 = info.GetValue(obj,null);
                    //    //obj2 = type.InvokeMember("isPreLoad", BindingFlags.GetProperty | BindingFlags.Public, null, (IPlugin)obj, null);
                    //    if (obj2.ToString().ToLower() == "true")
                    //    {
                    //        MethodInfo mi = type.GetMethod("PreLoad");
                    //        mi.Invoke(obj, null);
                    //    }
                    //}
                    return obj;
                }
                catch (Exception ex)
                {
                    throw ex;
                    //MessageBox.Show("加载插件失败!请验证插件的正确性...", "错误");
                }
            }
  • 相关阅读:
    css3中calc()使用
    垂直居中
    QLineEdit IP地址校验
    UML类图几种关系的总结(网摘)
    如何解压 Mac OS X 下的 PKG 文件(网摘)
    %appdata%目录下配置文件修改
    文件字符串替换
    Qt版权符号显示问题
    Mac OS X 终端命令开启功能
    Qt 无边框拖拽实现
  • 原文地址:https://www.cnblogs.com/gghxh/p/1223168.html
Copyright © 2020-2023  润新知