我正在优化一个用 C# 开发的 exe 文件。我已经更改了一些提高性能的代码,但是当我尝试将代码签入到 SVN 源代码控制时,我的团队告诉我可以签入我的代码,但我必须通过启用和禁用功能来隐藏我的代码。
例如:
IF Code Hide == True
execute original Code
else
execute new code.
对于我所做的每一项更改,我该如何做到这一点?我是否需要在我更改代码的所有地方都写一个 if-else 语句?请建议我该怎么做。
我正在优化一个用 C# 开发的 exe 文件。我已经更改了一些提高性能的代码,但是当我尝试将代码签入到 SVN 源代码控制时,我的团队告诉我可以签入我的代码,但我必须通过启用和禁用功能来隐藏我的代码。
例如:
IF Code Hide == True
execute original Code
else
execute new code.
对于我所做的每一项更改,我该如何做到这一点?我是否需要在我更改代码的所有地方都写一个 if-else 语句?请建议我该怎么做。
您应该利用 SVN 的源代码控制功能。如果您使用更改创建一个分支,您可以更改代码,您的团队可以在闲暇时在您的代码和他们的代码之间切换。如果他们对您的代码感到满意,他们可以将您的代码合并到主分支中。
The most straight forward way is unfortunately to write if-else statements all over the place.
It is possible to solve this by clever code design, like using the Template method pattern and instantiate either a "normal" or "extended" version of the code, but that usually requires a lot of refactoring of your existing code.