/// <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("加载插件失败!请验证插件的正确性...", "错误");
            }
        }
posted on 2008-06-16 16:22  网碾平  阅读(565)  评论(0编辑  收藏  举报