I am trying to convert the code inside a function into a string. Is there any way to do this in VB.Net or C#.Net? For example:
Public Function Test() As String
Dim timestr As String = Now().ToString()
Return timestr
End Function
Then somehow convert the above into a string, i.e…
Dim funcstr As String = Test.ToString()
which funcstr would equal "Dim timestr As String = Now().ToString()Return timestr"
Thanks
EDIT
I marked JaredPar's answer because it helped solve my problem, even though what I'm asking isn't possible. My purpose was to have a duplicate copy of very sensitive and complicated code, and when the class is instantiated, compare the two and make sure they are exact just in case I accidentally changed a character (human error) during my coding. His solution allows me to accomplish this task. Here is my updated code from Jared's solution. Thanks!
Dim _type As Type = Me.GetType
Dim _method As System.Reflection.MethodInfo = _type.GetMethod("Test")
Dim _bytes() As Byte = _method.GetMethodBody.GetILAsByteArray()
Dim _method2 As System.Reflection.MethodInfo = _type.GetMethod("Test2")
Dim _bytes2() As Byte = _method2.GetMethodBody.GetILAsByteArray()
MsgBox(_bytes.SequenceEqual(_bytes2))