Description
I've run into problems with the Print<T>
and Out<T>
generics. These do a ToString()
on whatever is passed in, which is generally nice for usability, but I have more than once accidentally passed in something that gets auto-stringized, rather than the compile failing and catching my mistake.
Furthermore, the generic blocks my ability to add extension methods for custom type handling. A great example of this is when I wanted to add an Out(Spectre.Console.Rendering.IRenderable)
extension. Unfortunately, the Out<T>
always wins over an extension, and for any parameter type. And if I simply forget to call AnsiConsole.Console.ToAnsi
first, then I get the default/bad Object.ToString
behavior. IMO these generic functions cause more problems than they solve.
I can think of a few potential improvements:
- Remove
Out<T>
entirely - Rename to
OutValue<T>
- Move
Out<T>
to an extension method - Change it to
Out(object)
(as withSystem.IO.TextWriter
, adding in a bunch of overloads for primitives to reduce boxing)
My favorite is the first option. Cathode feels to me much more close-to-the-metal API vs the console stuff .NET ships with. Lots of work has gone into minimizing allocs and avoiding copying. So these stringizing helper methods feel out of place to me.
(Related: #192 (comment))
Activity