3

When I am in debug mode, I see an object filled with values(objectInMemory). I want VS to automatically create a c# initialization code like this with the exact values that are present now in debug mode.

var object = new objectInMemory{ field1= 1, field2="text", .... } 

So that I can copy it, stop debugging and hard-code these values in mock (for example)

is it possible with VS or any other third party tool?

2 Answers 2

2

The answer is, probably not...

Though, you could hack around this a little with something like Json.net or some other serializer

When you are in the Quick Watch window. Just call

Newtonsoft.Json.JsonConvert.SerializeObject(obj); 

and wallah, you have a copy of your object to use later (and add pepper and salt to taste). However, obviously limitations apply

Lastly, you could probably write you own extension, or better methods to save to file or something

Disclaimer, i cannot be held responsible for anyone you maim or otherwise injure with this idea

Sign up to request clarification or add additional context in comments.

Comments

1

There is at least one visual studio extension to do this (this is one I was able to find quickly):

https://marketplace.visualstudio.com/items?itemName=OmarElabd.ObjectExporter

Later...

The extension I couldn't remember that triggered me to search was this one:

https://marketplace.visualstudio.com/items?itemName=CodeValueLtd.OzCode

Note that the above is a commercial product. Also note that I have used neither!

1 Comment

added but not appearing in Tools (where it is supposed to show up)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.