waf / CSharpRepl

A command line C# REPL with syntax highlighting – explore the language, libraries and nuget packages interactively.
https://fuqua.io/CSharpRepl/
Mozilla Public License 2.0
2.92k stars 113 forks source link

Consider using `Dumpify` for dumping objects #286

Closed MoaidHathot closed 1 year ago

MoaidHathot commented 1 year ago

Feature Description

Although CSharpRepl has the ability to "dump" objects into the Console, it can't do that for every type of object. Dumpify is a relatively new package, that uses Spectre.Console as well, to dump and render any type of .NET object into the console, but it support more features and is very customizable.

For example, the following code

public class Person
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
}

var moaid = new Person { FirstName = "Moaid", LastName = "Hathot" };

Outupts: image

While using Dumpify the same code outptus: image

Another example:

var map = new Dictionary<string, person>
  {
      ["Moaid"] = new person { FirstName = "Moaid", LastName = "Hathot" },
      ["Haneeni"] = new person { FirstName = "Haneeni", LastName = "Shibli" },
  };

CSharpRepl outputs: image

While Dumpify outputs: image

The colors are configurable, so CSharpRepl can change them to maintain the same color scheme. The only missing abilities that I currently see:

waf commented 1 year ago

Nice, Dumpify looks good, we should definitely consider it.

@kindermannhubert any thoughts on this? You have the most experience with our current rich object formatting.

kindermannhubert commented 1 year ago

That dot in .Person is definitely a bug (probably an empty namespace) - I've created a new issue #287.

As for

it can't do that for every type of object

It can.

@MoaidHathot - For detailed output you need to press Ctrl+Enter instead of Enter. Your first example then looks like this: image

We too support formatting with larger depths but you need to be careful about large and deep objects. These toy examples of course look better when they are fully dumped. Perhaps there is some space for improvement in some dynamic depth determination based on "something".

E.g. dumping of Type with Dumpify does not work for me: typeof(int).Dump() not even typeof(int).Dump(maxDepth: 3) it just prints typeof(int).

CSharpRepl: image

Our formatting is quite new and definitely not perfect. But just a few things from the top of my mind: we have better support for value tuples, we support DebuggerDisplay and DebuggerTypeProxy attributes, we support user-defined ToString methods, our output is much closer to "standard" Visual Studio formatting, ... Also, we will hopefully support interactive object inspection via #226 when I'll have time for it. I also prefer CSharpRepl's more compact formatting.

I don't see any benefit from using Dumpify. Please take no offense @MoaidHathot.

MoaidHathot commented 1 year ago

@kindermannhubert, that is ok, no offense taken :)

Regarding dumping types such as typeof(int).Dump(), the current output from Dumpify is by definition, since otherwise the outputted table is very big, and in most cases it will dump too much information. This of course can be changed if the community prefers otherwise, but Dumpify supports dumping System.Reflection types such as System.Type's members, for example: image

Btw, do you handle circular references with the Tree formatting? I still get only .person with ctrl+enter image

Regardless of this discussion, CSharpRepl is awesome, and I use it quit a lot, thanks! Good job and keep up the awesome work :)

waf commented 1 year ago

Closing this. If developers do want to use Dumpify with CSharpRepl it's a quick #r "nuget: Dumpify" away.

I agree that this is a library the .NET ecosystem sorely needs. Nice work on it so far.