ToDump alignment and newline issues.
I am trying to write a class that amongst other things provides a customised ToDump
method to return a number nicely formatted and aligned.
The following is a very much simplified example
public class GV { private decimal val; public GV(decimal input) { val = input; } public override string ToString() { return val.ToString("0.0###") ; } object ToDump() => Util.WithStyle(this.ToString() , val < 3.9m ? "color:red; float:right" : "float:right"); }
This works fine when the object is contained within another class or a list etc. For example
Enumerable.Range(0,5).Select(a=> new GV(a)).Dump("");
produces
But dumping the object on its own produces weird results. For example
for (int i = 0; i < 5; i++) i.Dump(""); for (int i = 0; i < 5; i++) (new GV(i)).Dump("");
produces
I can understand the results being right-aligned, but why all on one line?
If I change the style to be float:left, then
for (int i = 0; i < 5; i++) i.Dump(""); for (int i = 0; i < 5; i++) (new GV(i)).Dump( ); Enumerable.Range(0, 5).Select(a => new GV(a)).Dump("");
produces
I can add a space to the output which at least makes the output readable in the above examples, but was wondering if there is anything better that can be done about this?
Behaviour is the same in Linqpad 5, 7 and 8
Comments
I think this is consistent with the "normal" behavior of the css float feature.
Note that if you apply any style or formatting feature in the ToDump method, LINQPad should right-align numbers within tables automatically, if you allow LINQPad to format the number:
Note that this doesn't work right now in single-column tables (it probably should).
The problem with leaving the value as numbers is that I lose control of the formatting, and I get the results like the unformatted column below, whereas I would like it to look like the formatted column.
I know that also means that I lose the totals, which in this case is not what I really want, but sometimes it is handy (as in the last column where the total price does not make sense).
I can't use the Edit/Preferences/Formatting rules as I don't want the same format to apply to the price column.