Yosef Bernal
Yosef Bernal

Reputation: 1064

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

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.

Upvotes: 6

Views: 963

Answers (3)

Joe Albahari
Joe Albahari

Reputation: 30964

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;
    }
}    

Upvotes: 7

StriplingWarrior
StriplingWarrior

Reputation: 156654

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

Upvotes: 1

NetMage
NetMage

Reputation: 26926

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));

Upvotes: 1

Related Questions