如何在 C#/Visual-Studio/Unity3d 的 lambda 范围内观察(即调试)extra-lambda 变量?

How to watch (i.e. debug) extra-lambda variable inside lambda scope in C#/Visual-Studio/Unity3d?

在 Unity 中使用 Visual Studio Professional 2015 时,我注意到当我单步执行 lambda 表达式的主体时,我无法查看 declared/assigned 之外但正在执行的变量阅读 lambda 表达式的内部。

    private IEnumerator DoTheThing(string filter)
    {
        TextureDownload texDl = new TextureDownload();
        texDl.OnCompleted += () =>
        {
            _log.Log("Mesh texture " + texDl.GetType() + ":" + texDl.GetHashCode());
            textures.Add(texDl);
        };
        yield break;
    }

我收到错误

The identifier texDl is not in the scope

显然变量在此范围内是可访问的,因为 lambda 函数正在使用它。

是否有任何远程 easy/convenient 方法来观察此类变量的值?

原来这是

的变体

Mono/Unity 协程和 lambda 表达式存在问题;

The coroutine itself is an implicit closure as well which moves all local variable to a seperate class as member variables. That means it's impossible to create a "real" local variable inside a generator method. That's why the explicit local variable declaration doesn't work.

http://answers.unity3d.com/questions/974036/c-lambda-call-in-for-loop-references-to-last-objec.html