forked from SharpGenTools/SharpGenTools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModelTestExtensions.cs
More file actions
28 lines (23 loc) · 989 Bytes
/
Copy pathModelTestExtensions.cs
File metadata and controls
28 lines (23 loc) · 989 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
using System.Collections.Generic;
using System.Linq;
using SharpGen.CppModel;
using SharpGen.Model;
namespace SharpGen.UnitTests
{
internal static class ModelTestExtensions
{
public static T FindFirst<T>(this CppElement element, string path) where T : CppElement =>
element.Find<T>(path).FirstOrDefault();
public static IEnumerable<T> Find<T>(this CppElement element, string path) where T : CppElement =>
new CppElementFinder(element).Find<T>(path);
public static IEnumerable<CsBase> EnumerateDescendants(this CsBase element, bool withAdditionalItems = true)
{
yield return element;
IEnumerable<CsBase> items = element.Items;
if (withAdditionalItems)
items = items.Concat(element.AdditionalItems);
foreach (var descendant in items.SelectMany(x => EnumerateDescendants(x, withAdditionalItems)))
yield return descendant;
}
}
}