forked from axuno/SmartFormat
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXmlSource.cs
More file actions
35 lines (28 loc) · 977 Bytes
/
Copy pathXmlSource.cs
File metadata and controls
35 lines (28 loc) · 977 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//
// Copyright SmartFormat Project maintainers and contributors.
// Licensed under the MIT license.
using System.Linq;
using System.Xml.Linq;
using SmartFormat.Core.Extensions;
namespace SmartFormat.Extensions;
/// <summary>
/// Class to evaluate sources of type <see cref="XElement"/>.
/// Include this source, if this type shall be used.
/// </summary>
public class XmlSource : Source
{
/// <inheritdoc />
public override bool TryEvaluateSelector(ISelectorInfo selectorInfo)
{
if (selectorInfo.CurrentValue is not XElement element) return false;
var selector = selectorInfo.SelectorText;
// Find elements that match a selector
var selectorMatchedElements =
element.Elements()
.Where(x => x.Name.LocalName == selector)
.ToList();
if (selectorMatchedElements.Count == 0) return false;
selectorInfo.Result = selectorMatchedElements;
return true;
}
}