Esempio n. 1
0
        private void ExamineAssembly(Assembly assembly, string code)
        {
            // Loop through all the types in the DLL, looking for a valid plugin
            foreach (var t in assembly.GetTypes())
            {
                // Only interested in Public types
                if (t.IsPublic)
                {
                    // And not interested in Abstract types
                    if (!t.Attributes.HasFlag(TypeAttributes.Abstract))
                    {
                        // Now check if it the type implements our interface
                        Type iface = t.GetInterface("IAgentPlugin", true);

                        if (iface != null)
                        {
                            // It does
                            AvailablePlugin p = new AvailablePlugin();
                            p.AssemblyPath = assembly.Location;
                            p.ClassName    = t.FullName;
                            p.Plugin       = CreateInstance(p);
                            if (p.Plugin.Code == code)
                            {
                                mPlugins.Add(p);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        private IAgentPlugin CreateInstance(AvailablePlugin availablePlugin)
        {
            IAgentPlugin plugin;

            try
            {
                Assembly dll = Assembly.LoadFrom(availablePlugin.AssemblyPath);
                plugin = (IAgentPlugin)dll.CreateInstance(availablePlugin.ClassName);
            }
            catch
            {
                return(null);
            }
            return(plugin);
        }