Results 1 to 7 of 7

Thread: Reflection...

  1. #1

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729

    Reflection...

    when seeing functions/methods using reflection is it possible to see in a function the name of the parameters? or not?
    \m/\m/

  2. #2
    Lively Member hbandarra's Avatar
    Join Date
    Aug 2002
    Location
    Lisbon, PT
    Posts
    66
    No. That's just code naming that is lost after compiling. Only the arguments types are (obviously) preserved. If you compile in debug mode, that information is preserved, but I don't know how to access it.

  3. #3
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    wrong. You can. Use the ParameterInfo class. You can the name and type.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  4. #4
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    sorry this is in VB, but you can get the idea
    Code:
    ' This program writes a report about assembly
    
    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
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  5. #5

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    yeah i can

    ty
    \m/\m/

  6. #6
    Lively Member hbandarra's Avatar
    Join Date
    Aug 2002
    Location
    Lisbon, PT
    Posts
    66
    Wow! .Net is fantastic!

  7. #7

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    no

    its me who's fantastic
    \m/\m/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width