Search code examples
c#linqpad

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.


Solution

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