Reading Method argument values

Do you program directly PostSharp.CodeModel or another low-level API and need help? Put your questions here and we will try to answer.

Reading Method argument values

Postby Lance on Wed Apr 09, 2008 12:26 pm

Hi,
I'm implmenting ASP.NET application logging using one of the PostSharp demos as a basis. I've figured out how to get a Method's name, and arguments, but I'm not sure how to get at the values of the arguments. I mostly just want to ToString() the args so that when viewing the Trace, I can see what information is being fed to each Method.

FYI - I'm using this Attribute at the Assembly level, thanks for the awsomeness of the cascade!



As a side note, having used PostSharp for under a day, I'm quite impressed with how much coding this is saving me! PostSharp is Supercool, in my book!


Here's what I have so far:
Code: Select all
   [EasyTrace(null, AttributeExclude = true)]
    [Serializable]
    public class EasyTrace : OnMethodBoundaryAspect
    {
...
       public override void OnEntry(MethodExecutionEventArgs eventArgs)
        {
                string s = string.Format("Entering {2}.{0}.{1}.",
                                   eventArgs.Method.DeclaringType.Name,
                                   eventArgs.Method.Name,
                                   eventArgs.Method.Module);


                ParameterInfo[] pi = eventArgs.Method.GetParameters();
                if (pi.Length > 0)
                {
                    s += " ARGUMENTS:(";
                    for (int x = 0; x < pi.Length; x++)
                    {
                        s += String.Format("{0} - {1}: ", pi[x].Name, pi[x].ParameterType);
                    }
                    s += ")";
                }

                Utility.Log(s);
                WriteTrace(s);
        }
...
}



btw: I'm using Laos, so was a little unsure of where to post this message.
Lance
 
Posts: 2
Joined: Wed Apr 09, 2008 12:14 pm
Full Name: Lance

Re: Reading Method argument values

Postby gfraiteur on Wed Apr 09, 2008 12:43 pm

eventArgs.GetArguments()
Gael Fraiteur, project leader
got good support? consider donating to the project.
gfraiteur
Site Admin
 
Posts: 651
Joined: Tue Dec 18, 2007 3:09 pm
Full Name: Gael Fraiteur
Company: postsharp.org


Return to PostSharp Core