Files
2026-10-12 16:49:14 +08:00

49 lines
1.3 KiB
C#

using System;
using System.Collections.Generic;
namespace PDFPatcher.Model.PdfPath
{
public interface IPathExpression : IPathValue
{
IList<IPathPredicate> Predicates { get; }
IPathAxis Axis { get; }
string Name { get; }
DocumentObject SelectObject(DocumentObject source);
IList<DocumentObject> SelectObjects(DocumentObject source);
}
public class PathExpression : IPathExpression
{
internal static readonly IList<DocumentObject> EmptyMatchResult = new DocumentObject[0];
#region IPathExpression 成员
public PathValueType ValueType => PathValueType.Expression;
public IPathAxis Axis { get; }
public string Name { get; }
private IList<IPathPredicate> _Predicates;
///<summary>获取匹配条件列表。</summary>
public IList<IPathPredicate> Predicates => _Predicates ??= [];
public DocumentObject SelectObject(DocumentObject source) {
return Axis.SelectObject(source, Name, Predicates);
}
public IList<DocumentObject> SelectObjects(DocumentObject source) {
return Axis.SelectObjects(source, Name, _Predicates);
}
#endregion
public PathExpression(PathAxisType axis) {
Axis = PathAxes.Create(axis);
}
public PathExpression(PathAxisType axis, string name) {
Axis = PathAxes.Create(axis);
Name = name;
}
}
}