Recursive func framework for C#