using Beam.Abstractions; using HtmlAgilityPack; namespace Beam.Dynamic; public enum RelationType { Parent, Child, } public class RelationalDataProvider : IComposableDataProvider { public RelationType RelationType { get; set; } = RelationType.Parent; public IBinding? Content { get; set; } public HtmlNode? Get(HtmlDocument document) { return Select(document); } public HtmlNode? Get(HtmlNode node) { return Select(node); } public HtmlNode? Select(HtmlDocument doc) { return Select(Content?.Select(doc) ?? doc.DocumentNode); } public HtmlNode? Select(HtmlNode node) { return RelationType switch { RelationType.Parent => node.ParentNode, RelationType.Child => node.FirstChild, _ => throw new NotSupportedException() }; } }