S
Steve Amey
Hiya
I want to execute a function using reflection and retrieve the value of a
string using a ByRef parameter. When I Invoke the MethodInfo passing in the
string parameter, it gets populated in the correct function but when I come
back out of the function that value is not passed back to the code that
called it.
Could somebody please tell me if I'm missing something here? I just need to
be able to use ByRef parameters using reflection to execute the methods.
***********************
Private Shared _aIUDHandler As IUDHandler
Public Shared Function SaveObject(ByVal paMyObject As MyObject, ByRef
psMessage As String) As Boolean
Dim aTypes() As Type = {paMyObject.GetType, psMessage.GetType}
Dim aMethodInfo As System.Reflection.MethodInfo =
_aIUDHandler.GetType.GetMethod("SaveMyObject")
If Not aMethodInfo Is Nothing Then
'// I want to retrieve the value in psMessage here
Dim aRet As Object = aMethodInfo.Invoke(_aIUDHandler, New Object()
{paMyObject , psMessage})
Return CType(aRet, Boolean)
Else
Throw New Exception("Not working")
End If
End Function
Public Class IUDHandler
Public Overloads Function SaveMyObject(ByVal paMyObject As MyObject, ByRef
psMessage As String) As Integer
psMessage = "This ByRef param is not being returned via the reflection call
but is on a normal call"
End Function
End Class
**************************
Kind regards,
Steve
I want to execute a function using reflection and retrieve the value of a
string using a ByRef parameter. When I Invoke the MethodInfo passing in the
string parameter, it gets populated in the correct function but when I come
back out of the function that value is not passed back to the code that
called it.
Could somebody please tell me if I'm missing something here? I just need to
be able to use ByRef parameters using reflection to execute the methods.
***********************
Private Shared _aIUDHandler As IUDHandler
Public Shared Function SaveObject(ByVal paMyObject As MyObject, ByRef
psMessage As String) As Boolean
Dim aTypes() As Type = {paMyObject.GetType, psMessage.GetType}
Dim aMethodInfo As System.Reflection.MethodInfo =
_aIUDHandler.GetType.GetMethod("SaveMyObject")
If Not aMethodInfo Is Nothing Then
'// I want to retrieve the value in psMessage here
Dim aRet As Object = aMethodInfo.Invoke(_aIUDHandler, New Object()
{paMyObject , psMessage})
Return CType(aRet, Boolean)
Else
Throw New Exception("Not working")
End If
End Function
Public Class IUDHandler
Public Overloads Function SaveMyObject(ByVal paMyObject As MyObject, ByRef
psMessage As String) As Integer
psMessage = "This ByRef param is not being returned via the reflection call
but is on a normal call"
End Function
End Class
**************************
Kind regards,
Steve