include cache update

This commit is contained in:
fox
2026-06-24 11:51:15 +01:00
parent 689276ea7d
commit a2a6c15808
64 changed files with 744 additions and 1104 deletions
@@ -2,19 +2,16 @@ using System.Diagnostics.CodeAnalysis;
namespace Solicitors.HtmlParsing.Models;
internal class HtmlNode(string tagName, IHtmlAttribute[] attributes)
internal class HtmlNode(string name, IHtmlAttribute[] attributes)
: IHtmlNode
{
private readonly IHtmlAttribute[] _attributes = attributes;
private readonly string _tagName = tagName;
public virtual bool TryGetByTagName(
string tagName,
[NotNullWhen(true)] out IHtmlNode? node,
bool noChildren = false)
{
node = null;
if (tagName == _tagName)
if (tagName == name)
node = this;
return node is not null;
@@ -24,7 +21,7 @@ internal class HtmlNode(string tagName, IHtmlAttribute[] attributes)
{
get
{
var classAttribute = _attributes
var classAttribute = attributes
.Where(a => a is HtmlValueAttribute)
.Select(a => (a as HtmlValueAttribute)!)
.FirstOrDefault(a => a.Name.Equals("class", StringComparison.CurrentCultureIgnoreCase));
@@ -55,7 +52,7 @@ internal class HtmlNode(string tagName, IHtmlAttribute[] attributes)
bool noChildren = false)
{
node = null;
if (tagName == _tagName && Classes.Contains(className, StringComparer.InvariantCultureIgnoreCase))
if (tagName == name && Classes.Contains(className, StringComparer.InvariantCultureIgnoreCase))
node = this;
return node is not null;
@@ -75,7 +72,7 @@ internal class HtmlNode(string tagName, IHtmlAttribute[] attributes)
public bool HasAttribute(string attributeName)
{
return _attributes
return attributes
.Any(a => a.Name.Equals(attributeName, StringComparison.InvariantCultureIgnoreCase));
}
@@ -83,7 +80,7 @@ internal class HtmlNode(string tagName, IHtmlAttribute[] attributes)
{
attributeValue = null;
var matchingAttribute = _attributes.FirstOrDefault(
var matchingAttribute = attributes.FirstOrDefault(
a => a.Name.Equals(attributeName, StringComparison.InvariantCultureIgnoreCase)
);
@@ -5,8 +5,6 @@ namespace Solicitors.HtmlParsing.Models;
internal class ParentHtmlNode(string tagName, IHtmlAttribute[] attributes, IHtmlNode[] children)
: HtmlNode(tagName, attributes)
{
private readonly IHtmlNode[] _children = children;
public override bool TryGetByTagName(
string tagName,
[NotNullWhen(true)] out IHtmlNode? node,
@@ -15,7 +13,7 @@ internal class ParentHtmlNode(string tagName, IHtmlAttribute[] attributes, IHtml
node = null;
if (!base.TryGetByTagName(tagName, out node, noChildren) && !noChildren)
{
var nodesToCheck = new Queue<IHtmlNode>(_children);
var nodesToCheck = new Queue<IHtmlNode>(children);
while (nodesToCheck.TryDequeue(out var child))
{
if (child.TryGetByTagName(tagName, out var childNode, true))
@@ -41,7 +39,7 @@ internal class ParentHtmlNode(string tagName, IHtmlAttribute[] attributes, IHtml
node = null;
if (!base.TryGetByClass(className, out node, noChildren) && !noChildren)
{
var nodesToCheck = new Queue<IHtmlNode>(_children);
var nodesToCheck = new Queue<IHtmlNode>(children);
while (nodesToCheck.TryDequeue(out var child))
{
if (child.TryGetByClass(className, out var childNode, true))
@@ -68,7 +66,7 @@ internal class ParentHtmlNode(string tagName, IHtmlAttribute[] attributes, IHtml
node = null;
if (!base.TryGetByTagNameAndClass(tagName, className, out node, noChildren) && !noChildren)
{
var nodesToCheck = new Queue<IHtmlNode>(_children);
var nodesToCheck = new Queue<IHtmlNode>(children);
while (nodesToCheck.TryDequeue(out var child))
{
if (child.TryGetByTagNameAndClass(tagName, className, out var childNode, true))
@@ -86,9 +84,9 @@ internal class ParentHtmlNode(string tagName, IHtmlAttribute[] attributes, IHtml
return node is not null;
}
public override bool TryGetChildren([NotNullWhen(true)] out IEnumerable<IHtmlNode>? children)
public override bool TryGetChildren([NotNullWhen(true)] out IEnumerable<IHtmlNode>? children1)
{
children = _children;
return _children.Length != 0;
children1 = children;
return children.Length != 0;
}
}
@@ -5,8 +5,6 @@ namespace Solicitors.HtmlParsing.Models;
internal class StringNode(string content)
: IHtmlNode
{
private readonly string _content = content;
public bool TryGetByTagName(
string tagName,
[NotNullWhen(true)] out IHtmlNode? node,
@@ -37,7 +35,7 @@ internal class StringNode(string content)
public bool TryGetText([NotNullWhen(true)] out string? text)
{
text = _content;
text = content;
return !string.IsNullOrEmpty(text);
}