/// <summary> /// Checks whether a given <see cref="ITreeProgram{TOutput}" /> is a sub-program of another /// <see cref="ITreeProgram{TOutput}" />. /// A sub-program is an program that is a descendant of a given program. /// </summary> /// <param name="program">The program we want to know if it is a sub-program.</param> /// <param name="other">The program for which to look for a descendant equal to the given program.</param> /// <returns><c>true</c>, if the program is a descendant of the other program, <c>false</c> otherwise.</returns> /// <typeparam name="TOutput">The type of program output.</typeparam> public static bool IsSubProgramOf <TOutput>(this ITreeProgram <TOutput> program, ITreeProgram <TOutput> other) { // checks prog if (program == null || other == null || program.Length >= other.Length || other.Input?.Count == 0) { return(false); } // search the descendants for the given program return(other.Input != null && other.Input.Any(child => program.Equals(child) || program.IsSubProgramOf(child))); }