How to add (not replace) the content of a DumpContainer in LINQPad
Asked Answered
E

3

6

I have a DumpContainer to which I'd like to add content dynamically. I know I can set the Content property to a new object but that gets rid of the previous content.

How can I add instead of replace?

Thanks for your help.

Esperance answered 19/5, 2020 at 16:31 Comment(2)
Is there some reason you can't just concatenate new content? What are you putting in Content? (e.g. dc.Content += "\n new line of content";).Lockjaw
Hi @NetMage, thanks for helping. The problem with += is that the new content gets stacked to the right of the old content. I'd like it to go down. Close tho!Esperance
O
7

A couple more options:

If you want the items displayed vertically, but not in a table, use Util.VerticalRun inside a DumpContainer:

var content = new List<object>();
var dc = new DumpContainer (Util.VerticalRun (content)).Dump();

content.Add ("some text");
dc.Refresh();

content.Add (new Uri ("http://www.linqpad.net"));
dc.Refresh();

If the items are generated asynchronously, use an asynchronous stream (C# 8):

async Task Main()
{
    // LINQPad dumps IAsyncEnumerables in the same way as IObservables:
    RangeAsync (0, 10).Dump();
}

public static async IAsyncEnumerable<int> RangeAsync (int start, int count)
{
    for (int i = start; i < start + count; i++)
    {
        await Task.Delay (100);
        yield return i;
    }
}    
Olga answered 20/5, 2020 at 5:17 Comment(2)
This did the trick! You're a legend @JoeAlbahari, thanks a lot :)Esperance
Perhaps more of these Util methods could be documented somewhere? :)Lockjaw
L
1

If you are putting general objects in the DumpContainer that are displayed with field values, etc. you could convert to a similar (but without the Display in Grid button) format with Util.ToHtmlString and then concatenate.

var dc = new DumpContainer();
dc.Dump();

dc.Content = Util.RawHtml(Util.ToHtmlString(true, aVariable));

// some time later...

dc.Content = Util.RawHtml(Util.ToHtmlString(dc.Content)+Util.ToHtmlString(true, anotherVar));
Lockjaw answered 19/5, 2020 at 22:59 Comment(0)
R
1

Instead of adding content to the DumpContainer, go ahead and update it, but make its contents be something that has all the data you're trying to add.

var c = new DumpContainer();
var list = new List<string> {"message 1"};
c.Content = list;
c.Dump();
list.Add("message 2");
c.UpdateContent(list);

Updated DumpContainer

Alternatively, you can dump an IObservable<>, and it'll automatically get updated as objects are emitted. (Import the System.Reactive NuGet package to make this work.)

var s = new Subject<string>();
s.Dump();
s.OnNext("message 1");
s.OnNext("message 2");

Dumped Observable

Retroflexion answered 19/5, 2020 at 23:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.