How to retrieve the methods from a dll?
Can I retrieve them using the System.Reflection.Assembly? How?
Thanks!
Printable View
How to retrieve the methods from a dll?
Can I retrieve them using the System.Reflection.Assembly? How?
Thanks!
yep
VB Code:
Imports System Imports System.Reflection Public Module DLLReport Public Sub Main(ByVal args() As String) LoadDLL(args(0)) End Sub Public Sub LoadDLL(ByVal filename As String) Dim asm As [Assembly] ' Assembly is reserved vb word so use the brackets to override Dim myClasses() As Type Dim myMethods() As MethodInfo Dim myEvents() As EventInfo Dim myProperties() As PropertyInfo Dim myParameters() As ParameterInfo Dim myTypes As Type Dim myMethodInfo As MethodInfo Dim myEventInfo As EventInfo Dim myPropertyInfo As PropertyInfo Dim myParameterInfo As ParameterInfo asm = [Assembly].LoadFrom(filename) If Not(asm Is Nothing) Then myClasses = asm.GetTypes() End If For Each myTypes In myClasses ' Output Classname Console.Writeline(myTypes.ToString()) ' Lets get all methods(sub and function) from this class myMethods = myTypes.GetMethods() For Each myMethodInfo In myMethods Console.Writeline("---Method---" & myMethodInfo.Name & " Returns " & myMethodInfo.ReturnType.ToString()) ' Now lets get the Parameters for this method myParameters = myMethodInfo.GetParameters() For Each myParameterInfo In myParameters Console.WriteLine(" ---Parameter---" & myParameterInfo.Name & " As " & myParameterInfo.ParameterType.ToString()) Next myParameterInfo Next myMethodInfo ' Lets get all events myEvents = myTypes.GetEvents() For Each myEventInfo In myEvents Console.Writeline("---Event---" & myEventInfo.Name) Next myEventInfo ' Lets get all properties myProperties = myTypes.GetProperties() For Each myPropertyInfo In myProperties Console.Writeline("---Properties---" & myPropertyInfo.Name & " As " & myPropertyInfo.PropertyType.ToString()) Next myPropertyInfo Next myTypes End Sub End Module
What an excellent reply! Thank you very much, Cander!
BTW, is it possible to know the security settings of the methods declared with the [PrincipalPermissionAttribute()] ?
Thanks!
do you mean check if its public,private, friend, etc?
No this is about the System.Security of the .Net framework
I need to know wich username or role is the method expecting. Or, at least, to know if my Principal has the permissions that allow-me to execute the method safely (without having to call the method explicitly in search for an exception).
well I havnt really worked with Attributes much yet so I cant be 100%, but you may try looking into the MethodInfo objects Attributes property. Maybe that will provide some clue as since I dont know much about using Attributes, I wouldnt really be able to piece together what to do.
Well, I think that's not the way. At least I didn't found nothing...
I've made the question about reading the assembly methods on the c# forum. In fact, I've converted your code to c#. Do you mind if I publish that code with a reference to you and this thread on that forum?
Thanks!
search by my posts and reflection...cander some time ago posted a version of that code in C#
Actually I dont think I did this code in C#. I did the plug-in code orginally in C# and Edneeis ported that to VB.NET
But yeah hd..that is fine with me.