home
products
contribute
download
documentation
forum
Home
Forums
New posts
Search forums
What's new
New posts
All posts
Latest activity
Members
Registered members
Current visitors
Donate
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Search titles only
By:
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
General Forums
OffTopic
C# code for Plugin System
Contact us
RSS
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="and-81" data-source="post: 211219" data-attributes="member: 11844"><p>Here's a slightly modified piece of code from my IR Server program.</p><p></p><p>Basically it just goes through all the dll files in the plugin folder to find ones that contain plugins in them (plugins must inherit the IRServerPluginBase class).</p><p></p><p>[CODE]</p><p> List<IRServerPluginBase> AvailablePlugins()</p><p> {</p><p> try</p><p> {</p><p> List<IRServerPluginBase> plugins = new List<IRServerPluginBase>();</p><p></p><p> string installFolder = SystemRegistry.GetInstallFolder();</p><p> if (String.IsNullOrEmpty(installFolder))</p><p> return null;</p><p></p><p> string[] files = Directory.GetFiles(installFolder + "\\IR Server Plugins\\", "*.dll", SearchOption.TopDirectoryOnly);</p><p></p><p> foreach (string file in files)</p><p> {</p><p> try</p><p> {</p><p> Assembly assembly = Assembly.LoadFrom(file);</p><p> Type[] types = assembly.GetExportedTypes();</p><p></p><p> foreach (Type type in types)</p><p> {</p><p> if (type.IsClass && !type.IsAbstract && type.IsSubclassOf(typeof(IRServerPluginBase)))</p><p> {</p><p> IRServerPluginBase plugin = (IRServerPluginBase)assembly.CreateInstance(type.FullName);</p><p></p><p> if (plugin != null)</p><p> plugins.Add(plugin);</p><p> }</p><p> }</p><p> }</p><p> catch (BadImageFormatException)</p><p> {</p><p> // Ignore Bad Image Format Exceptions, just keep checking for IR Server Plugins</p><p> }</p><p> catch (TypeLoadException)</p><p> {</p><p> // Ignore Type Load Exceptions, just keep checking for IR Server Plugins</p><p> }</p><p> catch (Exception ex)</p><p> {</p><p> MessageBox.Show(ex.ToString(), "IR Server Plugin Error");</p><p> }</p><p> }</p><p></p><p> return plugins;</p><p> }</p><p> catch</p><p> {</p><p> return null;</p><p> }</p><p> }</p><p>[/CODE]</p><p></p><p>Hope that helps,</p></blockquote><p></p>
[QUOTE="and-81, post: 211219, member: 11844"] Here's a slightly modified piece of code from my IR Server program. Basically it just goes through all the dll files in the plugin folder to find ones that contain plugins in them (plugins must inherit the IRServerPluginBase class). [CODE] List<IRServerPluginBase> AvailablePlugins() { try { List<IRServerPluginBase> plugins = new List<IRServerPluginBase>(); string installFolder = SystemRegistry.GetInstallFolder(); if (String.IsNullOrEmpty(installFolder)) return null; string[] files = Directory.GetFiles(installFolder + "\\IR Server Plugins\\", "*.dll", SearchOption.TopDirectoryOnly); foreach (string file in files) { try { Assembly assembly = Assembly.LoadFrom(file); Type[] types = assembly.GetExportedTypes(); foreach (Type type in types) { if (type.IsClass && !type.IsAbstract && type.IsSubclassOf(typeof(IRServerPluginBase))) { IRServerPluginBase plugin = (IRServerPluginBase)assembly.CreateInstance(type.FullName); if (plugin != null) plugins.Add(plugin); } } } catch (BadImageFormatException) { // Ignore Bad Image Format Exceptions, just keep checking for IR Server Plugins } catch (TypeLoadException) { // Ignore Type Load Exceptions, just keep checking for IR Server Plugins } catch (Exception ex) { MessageBox.Show(ex.ToString(), "IR Server Plugin Error"); } } return plugins; } catch { return null; } } [/CODE] Hope that helps, [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
General Forums
OffTopic
C# code for Plugin System
Contact us
RSS
Top
Bottom