Add IDE configs, update Beam version, and enhance RelationalDataProvider

Added JetBrains Rider IDE configuration files and a backup for Beam.Api.csproj. Updated aeqw89.Beam project version to 2.7.0 and package references, including Selenium.WebDriver and System.IO.Hashing. Enhanced RelationalDataProvider to support NextSibling and PreviousSibling relations and configurable traversal distance.
This commit is contained in:
qwsdcvghyu89
2025-11-23 01:47:53 +11:00
parent 580ceb8c3c
commit b16d17631e
8 changed files with 339 additions and 11 deletions
@@ -6,11 +6,14 @@ namespace Beam.Dynamic;
public enum RelationType {
Parent,
Child,
NextSibling,
PreviousSibling,
}
public class RelationalDataProvider : IComposableDataProvider<HtmlNode?> {
public RelationType RelationType { get; set; } = RelationType.Parent;
public int Distance { get; set; } = 1;
public IBinding? Content { get; set; }
public HtmlNode? Get(HtmlDocument document) {
@@ -23,10 +26,20 @@ public class RelationalDataProvider : IComposableDataProvider<HtmlNode?> {
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()
};
return _Select(node, Distance);
}
private HtmlNode? _Select(HtmlNode node, int distance = 0) {
while (true) {
if (distance == 0) return node;
node = RelationType switch {
RelationType.Parent => node.ParentNode,
RelationType.Child => node.FirstChild,
RelationType.NextSibling => node.NextSibling,
RelationType.PreviousSibling => node.PreviousSibling,
_ => throw new NotSupportedException()
};
distance = distance - 1;
}
}
}