Public Interface IPlugin ReadOnly Property Name() As String ' plugin Name Sub DoSomething() Function Calc(ByVal A As Double) As Double End Interface
Public Class Plugin_Copley Implements IPlugin Public Function Calc(ByVal A As Double) As Double Implements IPlugin.Calc Return A * 1.200056 End Function Public Sub DoSomething() Implements IPlugin.DoSomething System.Windows.Forms.MessageBox.Show("Do Something in Copley Plugin") End Sub Public ReadOnly Property Name As String Implements IPlugin.Name Get Name = "Copley Plugin" End Get End Property End Class
Imports MOTION_INTERFACE Public Class Main Private _Plugins As Dictionary(Of String, IPlugin) Dim Y_Button As Integer = 5 Private Sub Main_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load End Sub Sub New() ' This call is required by the designer. InitializeComponent() ' Add any initialization after the InitializeComponent() call. Load_PluginList() End Sub Private Sub Load_PluginList() _Plugins = New Dictionary(Of String, IPlugin) Dim plugins As ICollection(Of IPlugin) = PluginLoader.LoadPluginList("PLUGINS") If plugins Is Nothing Then Close() MsgBox("No plugins loaded. Application Closed.") Return End If For Each item In plugins _Plugins.Add(item.Name, item) Dim b = New Button With { .Text = item.Name} AddHandler b.Click, AddressOf b_Click Dim t As Point t.X = 5 t.Y = Y_Button Y_Button = Y_Button + 30 b.Location = t Me.Controls.Add(b) Next End Sub Private Sub b_Click(sender As Object, e As System.EventArgs) Dim b As Button = sender If b IsNot Nothing Then Dim key As String = b.Text.ToString() If _Plugins.ContainsKey(key) Then Dim plugin As IPlugin = _Plugins(key) plugin.DoSomething() End If End If End Sub
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)