【发布时间】:2017-03-22 11:47:20
【问题描述】:
我遇到了一个方便问题,如果我希望某些东西只在特定平台上执行,编译器会停止检查和重构代码。所以在这种情况下,如果我在 Visual Studio 中将foo 重构为bar,它只会将foo = true 部分重构为bar = true,但foo = false 不会被更改。
bool foo;
#if UNITY_EDITOR
foo = true;
#else
foo = false;
#endif
为了避免这种情况,在某些情况下我将代码更改为
bool foo;
#if UNITY_EDITOR
foo = true;
return;
#endif
foo = false;
但这不仅更乏味,因为我必须确保在将某些内容分配给 foo 后我可以返回,我还会在 Unity 编辑器中收到有关无法访问代码的警告。
所以我的问题是:处理这个问题的最佳方法是什么?是否可以让 Visual Studio 也对当前平台未使用的代码进行代码检查和重构?
【问题讨论】:
标签: c# visual-studio unity3d preprocessor-directive