What is the .NET equivalent of PHP var_dump?

后端 未结 5 1002
春和景丽
春和景丽 2020-12-31 07:43

I remember seeing a while ago that there is some method in maybe the Reflection namespace that would recursively run ToString() on all of an object\'s propertie

5条回答
  •  情歌与酒
    2020-12-31 08:29

    You can write it by yourself. For example, serialize it into json using Newtonsoft's JSON.net library and write that json to console. Here is an example:

    using Newtonsoft.Json;
    
    static class Pretty
    {
        public static void Print (T x)
        {
            string json = JsonConvert.SerializeObject(x, Formatting.Indented);
            Console.WriteLine(json);
        }
    }
    

    Usage:

    Pretty.Print(whatever);
    

提交回复
热议问题