NBAIS
asked on
Calling a Method by it's string name and pass variables
How do I use the following system.reflection code to call a method by it's string name and pass that method a variable?
Imports System.Reflection
Public Class Reflect
Public Shared Function ExecuteMethod(ByVal name As String, ByVal parameters() As Object) As Object
Dim assy As Assembly = [Assembly].GetExecutingAss embly()
Dim ns As String = assy.GetType().Namespace
Dim method As MethodInfo = assy.GetType().GetMethod(n s & "." & name)
Return method.Invoke(Nothing, parameters)
End Function
End Class
Imports System.Reflection
Public Class Reflect
Public Shared Function ExecuteMethod(ByVal name As String, ByVal parameters() As Object) As Object
Dim assy As Assembly = [Assembly].GetExecutingAss
Dim ns As String = assy.GetType().Namespace
Dim method As MethodInfo = assy.GetType().GetMethod(n
Return method.Invoke(Nothing, parameters)
End Function
End Class
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you!
If you working on a project that had some special case where you actually needed to do this, then you would also have enough experience to read the documentation and learn how to do it for yourself. The very fact that you are asking this question tells me that whatever you are trying to do could be implemented in a better way.
Someone else will probably answer your question more directly, but that doesn't mean that they've given you the right answer for what you need to do.
Good luck.