5

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.

Yosef Bernal
  • 1,006
  • 9
  • 20
  • 1
    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";`). – NetMage May 19 '20 at 22:37
  • 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! – Yosef Bernal May 20 '20 at 08:49

3 Answers3

6

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;
    }
}    
Joe Albahari
  • 30,118
  • 7
  • 80
  • 91
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));
NetMage
  • 26,163
  • 3
  • 34
  • 55
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

StriplingWarrior
  • 151,543
  • 27
  • 246
  • 315