Example #1
0
        /// <summary>
        /// 创建并获取指定泛型类型的对象的动态代理实例,该实例在切向捕捉对象控制范围内
        /// </summary>
        /// <param name="FullClassName"></param>
        /// <param name="AssemblyPath"></param>
        /// <param name="Parameters">参数</param>
        /// <returns></returns>
        public static T GetInstance <T>(string AssemblyPath, string FullClassName, params object[] Parameters)
        {
            T          result = default(T);
            ClassDrive cdiv   = new ClassDrive();

            try
            {
                if (LemonEnvironment.GetInstance().UseProxy)
                {
                    result = cdiv.ProxyInstance <T>(FullClassName, AssemblyPath, Parameters);
                }
                else
                {
                    result = cdiv.Instance <T>(AssemblyPath, FullClassName, Parameters);
                }
            }
            catch
            {
                string        str    = "创建对象实例失败。 AssemblyPath:" + AssemblyPath + " FullClassName:" + FullClassName;
                MessageObject newmsg = new MessageObject(MessageType.Error);
                newmsg.Message = str;
                MessageFactory.GetMegBus().Send(newmsg);
            }
            return(result);
        }
Example #2
0
        /// <summary>
        /// 实例化
        /// </summary>
        /// <param name="FullClassName"></param>
        /// <param name="AssemblyName"></param>
        /// <param name="MenuForm"></param>
        /// <returns></returns>
        public virtual object Instance(string FullClassName, string AssemblyName, IMainForm MenuForm)
        {
            string assemblyfile = System.IO.Directory.GetCurrentDirectory() + "\\Module\\"
                                  + AssemblyName + "\\" + AssemblyName + ".dll";
            ClassDrive ci  = new ClassDrive();
            object     obj = ci.Instance <object>(assemblyfile, FullClassName);

            if (obj != null)
            {
                if (IsTargetInterface(obj))
                {
                    obj = SetCurrency((IModule)obj, MenuForm);
                    obj = SetModule((IModule)obj, MenuForm);
                }
                else if (this.successor != null)
                {
                    obj = this.successor.Instance(FullClassName, AssemblyName, MenuForm);
                }
                else
                {
                    obj = null;
                }
            }

            return(obj);
        }
Example #3
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            ClassDrive cdiv = new ClassDrive();
            Form1      frm  = cdiv.ProxyInstance <Form1>(typeof(Form1));

            Application.Run(frm);
        }
Example #4
0
        /// <summary>
        /// 在指定的文件夹中查找指定类型的对象并且实例化,只实例化匹配的第一个,实例类型必须有无参数构造函数
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="Directory"></param>
        /// <param name="Parameters"></param>
        /// <returns></returns>
        public static T FindInstanceFromDirectory <T>(string Directory, params object[] Parameters)
        {
            T             result = default(T);
            ClassDrive    cd     = new ClassDrive();
            DirectoryInfo dir    = new DirectoryInfo(Directory);

            FileInfo[] ff = dir.GetFiles("*.dll");
            foreach (FileInfo temp in ff)
            {
                Dictionary <string, Type> dic = cd.GetTypeListForInterface <T>(temp.FullName);
                foreach (string s in dic.Keys)
                {
                    result = Lemon.GetInstance <T>(dic[s], Parameters);
                    return(result);
                }
            }
            return(result);
        }
Example #5
0
        /// <summary>
        /// 在指定的文件夹中查找指定类型的对象并且实例化
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="IsPar">是否带参数构造</param>
        /// <param name="Directory"></param>
        /// <param name="ParFullClassName"></param>
        /// <param name="ParValue"></param>
        /// <returns></returns>
        public static List <T> FindInstanceFromDirectory <T>(string Directory, bool IsPar, List <string> ParFullClassName = null, List <object[]> ParValue = null)
        {
            List <T>      result = new List <T>();
            ClassDrive    cd     = new ClassDrive();
            DirectoryInfo dir    = new DirectoryInfo(Directory);

            FileInfo[] ff = dir.GetFiles("*.dll");
            foreach (FileInfo temp in ff)
            {
                Dictionary <string, Type> dic = cd.GetTypeListForInterface <T>(temp.FullName);
                foreach (string s in dic.Keys)
                {
                    object[] tmpPar = null;
                    if (IsPar)
                    {
                        if (ParFullClassName != null && ParValue != null)
                        {
                            int index = ParFullClassName.IndexOf(s);
                            if (index > -1)
                            {
                                tmpPar = ParValue[index];
                            }
                        }
                    }
                    T tmpobj = default(T);
                    if (tmpPar != null)
                    {
                        tmpobj = Lemon.GetInstance <T>(dic[s], tmpPar);
                    }
                    else
                    {
                        tmpobj = Lemon.GetInstance <T>(dic[s]);
                    }
                    if (tmpobj != null)
                    {
                        result.Add(tmpobj);
                    }
                }
            }
            return(result);
        }
Example #6
0
        /// <summary>
        /// 搜索所有模块程序集
        /// </summary>
        /// <returns></returns>
        public virtual void SearchAllModuleAssembly()
        {
            ClassDrive cd = new ClassDrive();

            this.infoList = new List <ModuleInfo>();
            DirectoryInfo rootDir = new DirectoryInfo(Lemon.GetModuleRootDirectory());

            DirectoryInfo[] childDir = rootDir.GetDirectories();
            foreach (DirectoryInfo dir in childDir)
            {
                FileInfo[] ff = dir.GetFiles("*.dll");
                foreach (FileInfo temp in ff)
                {
                    Dictionary <string, Type> dic = cd.GetTypeListForInterface <IModule>(temp.FullName);
                    foreach (string s in dic.Keys)
                    {
                        this.CheckinInfo(temp.FullName, s);
                    }
                }
            }
        }
Example #7
0
        /// <summary>
        /// 创建并获取指定泛型类型的对象的动态代理实例,使该实例在切向捕捉对象控制范围内
        /// </summary>
        /// <param name="InitType"></param>
        /// <param name="Parameters">参数</param>
        /// <returns></returns>
        public static T GetInstance <T>(Type InitType, params object[] Parameters)
        {
            T          result = default(T);
            ClassDrive cdiv   = new ClassDrive();

            try
            {
                if (LemonEnvironment.GetInstance().UseProxy)
                {
                    result = cdiv.ProxyInstance <T>(InitType, Parameters);
                }
                else
                {
                    result = cdiv.Instance <T>(InitType, Parameters);
                }
            }
            catch {
                string        str    = "创建对象实例失败。 " + InitType.ToString();
                MessageObject newmsg = new MessageObject(MessageType.Error);
                newmsg.Message = str;
                MessageFactory.GetMegBus().Send(newmsg);
            }
            return(result);
        }