|
-
Jan 28th, 2003, 12:02 PM
#1
Thread Starter
Lively Member
How to retrieve the methods from a dll?
How to retrieve the methods from a dll?
Can I retrieve them using the System.Reflection.Assembly? How?
Thanks!
-
Jan 28th, 2003, 12:33 PM
#2
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
-
Jan 28th, 2003, 12:37 PM
#3
Thread Starter
Lively Member
What an excellent reply! Thank you very much, Cander!
-
Jan 28th, 2003, 01:09 PM
#4
Thread Starter
Lively Member
BTW, is it possible to know the security settings of the methods declared with the [PrincipalPermissionAttribute()] ?
Thanks!
-
Jan 28th, 2003, 01:14 PM
#5
do you mean check if its public,private, friend, etc?
-
Jan 28th, 2003, 01:18 PM
#6
Thread Starter
Lively Member
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).
-
Jan 28th, 2003, 01:25 PM
#7
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.
-
Jan 28th, 2003, 04:33 PM
#8
Thread Starter
Lively Member
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!
-
Jan 28th, 2003, 06:21 PM
#9
yay gay
search by my posts and reflection...cander some time ago posted a version of that code in C#
\m/  \m/
-
Jan 29th, 2003, 09:34 AM
#10
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.
Last edited by Cander; Jan 29th, 2003 at 09:41 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|