Get the values of method`s parameters
Hello!
How can I get the values of the parameters of a method that is in an assembly, at run-time?
Lets say we want to see the System.Xml assembly, XmlDocumnet class and and some application I don`t know calls the 'CreateNode(string, string, string)' method, e.g: xmlDocument.CreateNode("1","2","").
I want to make an aplication that has the input data the name of the assembly (e.g. System.Xml.dll) and with the System.Reflection namespace I was able to get the static structure of the assembly(classes, constructors, methods + signarure, proprietes, events).
When I click on a method, I want to see all the calls of that method since I`ve clicked on it until the current moment.
Is this possible?
Do you think this could help?
http://msdn2.microsoft.com/en-us/library/ms404386.aspx
Thanks!
[1006 byte] By [
Eusebiu] at [2007-12-24]
You can retrieve the parameters from the profiling API as well. The COR_PRF_FUNCTION_ARGUMENT_INFO and related structures can be used. However you'll need to go through the documentation and samples to determine how to use them. I believe there is a sample in MSDN or in the SDK that provides a base profiler implementation.
If you want to use a different method for examining method calls then please post what method you are using. I don't believe there is any way in .NET itself to arbitrarily monitor a specific method invocation without using the profiler.
Michael Taylor - 9/21/06
AFAIK there is no way to hook an arbitrary method invocation (such as XmlDocument.CreateNode) from within .NET and retrieve the argument information. The best you can do is use StackFrame and StackTrace to get the method that was called and where it is located. You could, in theory, get the IL offset and then enumerate the IL code but that would probably be really difficult. However since you can't arbitrary trap method invocations you would need to modify whatever method(s) you wanted to track such that they called a method you wrote to dump the information. Not pretty.
Michael Taylor - 9/21/06
Is there any example code of how to actually evaluate the function argument values anywhere? I have looked extensively and can't seem to find any. I have a CLR profiler that logs the function names, return type, and parameter types, but I would also like to log the value of each parameter. I have navigated into the COR_PRF_FUNCTION_ARGUMENT_RANGE structure and obtained the starting memory address of the memory block for each argument, and in the case of an integer I can evaluate it, but having trouble figuring how to make sense if it's any other type of variable or an object, class etc...