// WPFExtensionLibrary.cs
// Copyright (c) 2016 Bentley Systems, Incorporated. All Rights Reserved.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("Haestad.Framework.UI.Integration.Test, PublicKey=" +
    "002400000480000094000000060200000024000052534131000400000100010025b2f82c499245" +
    "27a7853779cf30993d30cf63f0dea189775ddb4d071be50d54e5f910b20cab403f08c5343a38a4" +
    "1ddfb8452cace2996428f4fbf666e622dc3d0f982bc347fe94309e5448d6d22675d8655abee826" +
    "27104632ecf481097c91571411bb1d224f8fe9227638dfcf844e47f78fce62332c705b3c0fea0e" +
    "d4bd46bd"
    )]

namespace Haestad.Framework.UI.Integration
{
    /// <summary>
    /// Class provides generic WPF extension methods.
    /// </summary>
    internal static class WPFExtensionLibrary
    {
        internal static T GetChildOfType<T>(this DependencyObject dependencyObject)
            where T : DependencyObject
        {
            if (dependencyObject == null)
                return null;

            for (int i = 0; i < VisualTreeHelper.GetChildrenCount(dependencyObject); ++i)
            {
                var child = VisualTreeHelper.GetChild(dependencyObject, i);

                var result = (child as T) ?? GetChildOfType<T>(child);
                if (result != null)
                    return result;
            }
            return null;
        }
    }
}
