Para que no tengan que leerselo y analizarlo basicamente crea un objeto apartir de la dll a cargar comprobando que dentro de ella exista la clase Plugin
dentro de esta clase debe ir todo el contenido y además debe ser la clase principal y tambien el nombre de raiz y el del ensamblado del plugins deben ser los mismos, luego tenemos 2 funciones una que devuelve todos los controles dentro del plugin y otra que te devuelve solo los de un tipo en especifico por ejemplo solo los TextBox
Código
Public Class Dll #Region " Private " Private _ _DllInfo As FileInfo, _ _EntryPoint As String, _ _Assembly As Assembly, _ _ObjectType As Type, _ _ObjectInstance As Object #End Region #Region " Private Shared " #End Region #Region " Public " Public Sub New(ByVal Path As String) Try If IsSmartDll(Path) Then _DllInfo = New FileInfo(Path) _EntryPoint = New FileInfo(Path).Name.Split(CChar("."))(0) & "." _Assembly = Assembly.LoadFile(Path) _ObjectType = _Assembly.GetType(_EntryPoint & "Plugin") _ObjectInstance = _Assembly.CreateInstance(_EntryPoint & "Plugin") Else Throw New Exception(Path & " not belongs to SmartDll") End If Catch ex As Exception Throw New Exception(ex.Message, ex.InnerException) End Try End Sub Public ReadOnly Property FileInfo() As [FileInfo] Get Return _DllInfo End Get End Property Public Function GetControlsByType(ByVal FindType As Type) As List(Of Control) GetControlsByType = New List(Of Control) For Each Objeto As PropertyInfo In _ObjectType.GetProperties Try If Objeto.PropertyType.Name = FindType.Name Then GetControlsByType.Add(CType(Objeto.GetValue(_ObjectInstance, New Object() {}), Control)) Else Continue For End If Catch Continue For End Try Next End Function Public Function GetControls() As List(Of Control) GetControls = New List(Of Control) For Each Objeto As PropertyInfo In _ObjectType.GetProperties Try GetControls.Add(CType(Objeto.GetValue(_ObjectInstance, New Object() {}), Control)) Catch Continue For End Try Next End Function #End Region #Region " Public Shared " Public Shared Function IsSmartDll(ByVal Path) As Boolean Try Dim Dll As Assembly = Assembly.LoadFile(Path) Return Dll.GetType(New FileInfo(Path).Name.Split(CChar("."))(0) & ".Plugin") IsNot Nothing Catch Return False End Try End Function #End Region End Class
Pueden decir que creen ustedes que hace falta, dudas, criticas o correcciones de errorres o recomendaciones de mejores practicas
Notas:
- Para que serviria llamar Subs y Funciones de un plugin?