A game framework written with osu! in mind.
1// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
2// See the LICENCE file in the repository root for full licence text.
3
4using System.Collections.Generic;
5using osu.Framework.Graphics;
6using osu.Framework.Graphics.Containers;
7
8namespace osu.Framework.Testing
9{
10 public static class TestingExtensions
11 {
12 /// <summary>
13 /// Find all children recursively of a specific type. As this is expensive and dangerous, it should only be used for testing purposes.
14 /// </summary>
15 public static IEnumerable<T> ChildrenOfType<T>(this Drawable drawable)
16 {
17 if (drawable is T match)
18 yield return match;
19
20 if (drawable is CompositeDrawable composite)
21 {
22 for (var i = 0; i < composite.InternalChildren.Count; i++)
23 {
24 var child = composite.InternalChildren[i];
25
26 foreach (var found in child.ChildrenOfType<T>())
27 yield return found;
28 }
29 }
30 }
31 }
32}