public static List <T> FindChildrenOfType <T>(DataboundContainterAsset asset) where T : DataboundAsset { List <T> results = new List <T>(); if (asset.Children.Value != null) { foreach (DataboundAsset databoundAsset in asset.Children.Value) { if ((databoundAsset as T) != null) { results.Add((T)databoundAsset); } if (databoundAsset is DataboundContainterAsset databoundContainterAsset) { List <T> foundInChildren = FindChildrenOfType <T>(databoundContainterAsset); if (foundInChildren != null) { results.AddRange(foundInChildren); } } } } return(results); }
public static T FindChildOfType <T>(DataboundContainterAsset asset) where T : DataboundAsset { if (asset.Children.Value != null) { if (asset.Children.Value.FirstOrDefault(x => x is T) is T found) { return(found); } foreach (DataboundContainterAsset databoundAsset in asset.Children.Value.Where(x => x is DataboundContainterAsset)) { T foundInChildren = FindChildOfType <T>(databoundAsset); if (foundInChildren != null) { return(foundInChildren); } } } return(null); }