Nate Bross
Contributor
I know there's gotta be a simple answer to this, but it's evading me.
I would like to pass a value to a method that I am invoking through System.Reflection.
I have a windows forms application that calls an external dll and invokes it's TestIt method.
I can call the method without any values; but I would like to pass values to it.
Here's what I have that isn't working. if MakeString doesn't take any values it works as expected.
I would like to pass a value to a method that I am invoking through System.Reflection.
I have a windows forms application that calls an external dll and invokes it's TestIt method.
I can call the method without any values; but I would like to pass values to it.
Here's what I have that isn't working. if MakeString doesn't take any values it works as expected.
Visual Basic:
'This is in the Windows Forms App.
Public Function MakeString(ByVal sdate As Object) As String
Return "The Time is: " & sdate.ToString()
End Function
'This is the dll
Public Class Class1
Public Sub TestIt()
System.Console.WriteLine("Class code Worked!")
Dim x As New IO.StreamWriter("c:\testdll.txt")
x.WriteLine("Class Code Worked")
Dim Assm As System.Reflection.Assembly = System.Reflection.Assembly.GetCallingAssembly
Dim Obj As Object = Assm.CreateInstance("CustomBinary.Form1", True)
Dim Meth As Reflection.MethodInfo = Obj.GetType.GetMethod("MakeString", True)
Dim ob As Object() = Nothing
ob(0) = DirectCast(DateTime.Now().ToString(), Object)
x.WriteLine(Meth.Invoke(Obj, ob))
x.Flush()
x.Close()
End Sub
End Class