コード例 #1
0
        public static T FirstOrDefault <T>(this ITreeNode <T> @this, Func <T, bool> predicate, TreeTraverseOrder order, T @default)
        {
            T result = @default;

            TreeExtensions.TryFindFirstParentFirst(@this, predicate, order, ref result);

            return(result);
        }
コード例 #2
0
        private static bool TryFindFirstParentFirst <T>(ITreeNode <T> root, Func <T, bool> predicate, TreeTraverseOrder order, ref T result)
        {
            if (predicate(root.Data))
            {
                result = root.Data;
                return(true);
            }

            ITreeNode <T> child = root.FirstChild;

            while (child != null)
            {
                if (TreeExtensions.TryFindFirstParentFirst(child, predicate, order, ref result))
                {
                    return(true);
                }

                child = child.NextSibling;
            }

            return(false);
        }