Copy object values in Visual Studio debug mode

前端 未结 12 514
轻奢々
轻奢々 2021-01-29 19:17

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 t

相关标签:
12条回答
  • 2021-01-29 19:40

    if you have a list and you want to find a specific variable: In the immediate window, type

     myList.Any(s => s.ID == 5062);
    

    if this returns true

    var myDebugVar = myList.FirstOrDefault(s => s.ID == 5062);
    ?myDebugVar
    
    0 讨论(0)
  • 2021-01-29 19:40

    useful tips here, I'll add my preference for when i next end up here asking this question again in the future. if you don't mind adding an extension that doesn't require output files or such there's the Hex Visualizer extension for visual studio, by mladen mihajlovic, he's done versions since 2015. provides a nice display of the array via the usual magnifine glass view object from the local variables window. https://marketplace.visualstudio.com/items?itemName=Mika76.HexVisualizer2019 is the 2019 version.

    0 讨论(0)
  • 2021-01-29 19:44

    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.

    0 讨论(0)
  • 2021-01-29 19:46

    Google led me to this 8-year-old question and I ended up using ObjectDumper to achieve something very similar to copy-pasting debugger data. It was a breeze.

    I know the question asked specifically about information from the debugger, but ObjectDumper gives information that is basically the same. I'm assuming those who google this question are like me and just need the data for debugging purposes and don't care whether it technically comes from the debugger or not.

    0 讨论(0)
  • 2021-01-29 19:46

    I've just right clicked on the variable and selected AddWatch, that's bring up watch window that consists of all the values. I selected all and paste it in a text a text editor, that's all.

    0 讨论(0)
  • 2021-01-29 19:47

    I know I'm a bit late to the party, but I wrote a JSON implementation for serializing an object, if you prefer to have JSON output. Uses Newtonsoft.Json reference.

    private static void WriteDebugJSON (dynamic obj, string filePath)
    {
        using (StreamWriter d = new StreamWriter(filePath))
        {
            d.Write(JsonConvert.SerializeObject(obj));
        }
    }
    
    0 讨论(0)
提交回复
热议问题