views:

105

answers:

3

In Visual Studio debug mode it's possible to hover over variables to show their value and then right-click to "Copy", "Copy Expression" or "Copy Value".

In case the variable is an object and not just a basic type, there's a + sign to expand and explore the object. It there a way to copy all that into the clipboard?

+2  A: 

Not exactly what youre asking for but you can add a watch for that object, and in the watch window, expand and select everything you want to copy and then copy it.

PMN
That does the job. It's not a pretty output, but it works.
Farinha
A: 

By using attributes to decorate your classes and methods you can have a specific value from your object display during debugging with the DebuggerDisplay attribute e.g.

[DebuggerDisplay("Person - {Name} is {Age} years old")]
public class Person
{
  public string Name { get; set; }
  public int Age { get; set; }
}
Dave Anderson
The thing is, I need to be able to copy all the object contents, and not just some of them. Yes, I could build a complex enough DebbuggerDisplay attribute with the whole object, but any changes to the class would need a change in the attribute as well.
Farinha
@Farinha What do you want to do with the object? Perhaps could have a property that is the serialized xml version of it.
Dave Anderson
+1  A: 

In the immediate window, type

?name_of_variable

This will print out everything, and you can manually copy that anywhere you want, or use the immediate window's logging features to automatically write it to a file.

Omer Raviv
Perfect! This outputs only the values and not all the variable types that are shown in a Watch.
Farinha