Exemplo n.º 1
0
        public static T FindFirstChild <T>(this _View view, Func <T, bool> selector = null, int?childLevelLimit = null, bool includeCurrent = true)
            where T : _View
        {
            Func <_View, bool> viewSelector;

            if (selector == null)
            {
                viewSelector = v => v is T;
            }
            else
            {
                viewSelector = v =>
                {
                    var t = v as T;
                    return(t != null && selector(t));
                };
            }

            if (includeCurrent &&
                viewSelector(view))
            {
                return((T)view);
            }

            var maxDepth = childLevelLimit.HasValue
                                ? childLevelLimit.Value
                                : int.MaxValue;

            return((T)(view.FindSubviews(viewSelector, maxDepth).FirstOrDefault()));
        }