public static IEnumerable<IScope> EnumerateTowardsGlobal(this IScope scope) { yield return scope; while (!(scope is GlobalScope)) { scope = scope.GetEnclosingScope(); yield return scope; } }