Page 13: Unbounded Nodes |
Suppose the actual number of sources in our provider database was configurable. The consumer would then want to find out at runtime exactly how many sources there are. This can be achieved with the following classes ...
private sealed class UnboundedSapphireRoot : Root<UnboundedSapphireRoot> { internal UnboundedSapphire Sapphire { get; private set; } } private sealed class UnboundedSapphire : FieldNode<UnboundedSapphire> { internal CollectionNode<Source> Sources { get; private set; } }
... which are used as follows:
AsyncPump.Run( async () => { using (var client = await ConnectAsync("localhost", 9000)) using (var consumer = await Consumer<UnboundedSapphireRoot>.CreateAsync(client)) { foreach (var source in consumer.Root.Sapphire.Sources.Children) { Console.WriteLine(source.Fader.Position.Value); } } });
Note that CollectionNodeTElement introduces a single point of unboundedness, all the benefits of the static interface and IntelliSense remain available for its children.
Proceed to Page 14: Optional Elements.