Ejemplo n.º 1
0
        private bool LoadExternalModule(string path)
        {
            bool     rt = false;
            Assembly a  = null;

            try
            {
                a = Assembly.LoadFrom(path);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return(rt);
            }
            var classtype = from t in a.GetTypes() where t.IsClass && (t.GetInterface("IAppFunctionality") != null) select t;

            foreach (Type item in classtype)
            {
                rt = true;
                IAppFunctionality b = (IAppFunctionality)a.CreateInstance(item.FullName, true);
                b.Doit();
                loadsnapins.Items.Add(item.FullName);
                c(item);
            }
            return(rt);
        }
Ejemplo n.º 2
0
        private static bool LoadExternalModule(string path)
        {
            bool     foundSnapIn  = false;
            Assembly theSnapInAsm = null;

            try
            {
                // Dynamically load the selected assembly
                theSnapInAsm = Assembly.LoadFrom(path);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"An error occurred loading the snapin: {ex.Message}");
                return(foundSnapIn);
            }

            // Get all IAppFunctionality compatible classes in assembly.
            var theClassTypes = from t in theSnapInAsm.GetTypes()
                                where t.IsClass && (t.GetInterface("IAppFunctionality") != null)
                                select t;

            // Now create the object and call Doit() method.
            foreach (Type t in theClassTypes)
            {
                foundSnapIn = true;

                // Use late binding to create the type
                IAppFunctionality itfApp = (IAppFunctionality)theSnapInAsm.CreateInstance(t.FullName, true);
                itfApp?.Doit();

                // Show company info
                DisplayCompanyData(t);
            }

            return(foundSnapIn);
        }