I created an helper method to return a List of UIElements where the returned  elements have to match with one of the Types which I pass to the method. First I used this method to get all the children of one type:public static IEnumerable<T> FindVisualChildren<T>(DependencyObject dependencyObj) where T : DependencyObject{    if (dependencyObj != null)    {        for (int i = 0; i < VisualTreeHelper.GetChildrenCount(dependencyObj); i++)        {            DependencyObject child = VisualTreeHelper.GetChild(dependencyObj, i);            if (child != null && child is T)            {                yield return (T)child;            }            foreach (T childOfChild in FindVisualChildren<T>(child))            {                yield return childOfChild;            }        }    }}I called this method like: var textBoxes = UIHelper.FindVisualChildren<TextBox>(currentView);But I need to find find elements of multiple types, so I rewrote the helper method to accept a List of Types.public static IEnumerable<UIElement> FindVisualChildrenOfMultipleTypes(List<Type> types, DependencyObject dependencyObj){    if (dependencyObj != null)    {        for (int i = 0; i < VisualTreeHelper.GetChildrenCount(dependencyObj); i++)        {            DependencyObject child = VisualTreeHelper.GetChild(dependencyObj, i);            if (child != null && types.Contains(child.GetType()))            {                yield return child as UIElement;            }            foreach (var childOfChild in FindVisualChildrenOfMultipleTypes(types, child))            {                yield return childOfChild;            }        }    }}Called like:List<Type> types= new List<Type>(){    typeof(CheckBox),    typeof(RadioButton),    typeof(TextBox)};var children = UIHelper.FindVisualChildrenOfMultipleTypes(types, currentView);This works, but I think there a some improvements possible. For example the signature of my method, I think Generics can be used in the method signature, but I'm not very experienced with Generics, so advice on this would be nice. I'm also wondering if the performance of the method can be improved.
Helper method to find VisualChildren of multiple Types
c#;performance;wpf