1

So I'm working with an Api that isn't working and I have subscribed to all of the events to see what is going on. So, on the event handler there are lots of parameters. I want to just print them out to the console.

I want to have a template (either visual studio 2010 or Resharper) to write out all of the parameters with the names and values.

In Resharper there is a built-in template outv that does them individually, but that is a pain to do each in turn.

I'm looking for something quick and can be throw-away.

Edit: Reasons why this isn't an exact duplicate at least any of the questions I've found or have been linked:

This is specifically about method parameters. Method parameters (as I have found) can not be reflected. I can use AOP, but that doesn't exactly fit my quasi-requirement for quick and easy. I am looking at that already, but I don't need anything long-term, so introducing postsharp into my project for only this concern seems an overkill.

Also, for objects, I am using System.Runtime.Serialization.Json.DataContractJsonSerializer. It is part of .net and json is easy to read and it is three lines that I can get rid of quickly. But not applicable to method parameters.

Eclipse has something like this.

Jeff Walker
  • 1,656
  • 1
  • 18
  • 36
  • sounds useful, what have you got so far? – RhysW Jan 08 '13 at 16:05
  • You may find [**LINQPad**](http://www.linqpad.com/) useful for debugging with complex object types. If you do `Console.WriteLine(obj)` from LINQPad, it recursively enumerates all the properties of the object and displays in a nice tabular format. – mellamokb Jan 08 '13 at 16:07
  • possible duplicates: [How do I intercept a method call in C#?](http://stackoverflow.com/questions/25803), [Easiest way to inject code to all methods and properties](http://stackoverflow.com/questions/6672080) – mellamokb Jan 08 '13 at 16:09

2 Answers2

3

This sounds like a typical issue for AOP (Aspect Oriented Programming). PostSharp is a good and simple framework to do the job. Have a look at this post.

Another way would be you use reflection to get all the information you need. Then you would have one method which can handle whatever you give to it and extract all the information it can find.

Community
  • 1
  • 1
MatthiasG
  • 4,434
  • 3
  • 27
  • 47
0

Perhaps an AOP tool like PostSharp (sharpcrafters.com) can help you.

pvieira
  • 1,687
  • 6
  • 17
  • 32