简体   繁体   English

在运行时更改代码

[英]Change code during runtime

There is an old video of Notch debugging and testing his code and while doing so he simply pauses his game, makes his code modifications, and resume his game with the new changes. Notch上有一个古老的视频,用于调试和测试他的代码,在这样做的同时,他只是暂停游戏,修改代码,并使用新的更改恢复游戏。

I found this old post explaining how he does it , but I'm wondering if there is an equivalent to Visual Studio 2012. 我发现这篇旧文章解释了他的工作方式 ,但是我想知道是否有与Visual Studio 2012等效的文章。

I know that you can enable Edit and Continue but this is a lot more restricted in the sense that you can't edit anything you want and you need to set a breakpoint. 我知道您可以启用“编辑并继续”功能,但是从某种意义上来说,它受到了更多限制,因为您无法编辑所需的任何内容,并且需要设置断点。 So Edit and Continue is not quite what I'm looking for. 因此,“编辑并继续”并不是我想要的。

I know that you can enable Edit and Continue but this is a lot more restricted in the sense that you can't edit anything you want … 我知道您可以启用“编辑并继续”功能,但是从某种意义上说,您将无法进行任何操作,因此受到更多限制……

Yes, there are some things that you can't edit with Edit and Continue. 是的,有些事情您无法使用“编辑并继续”进行编辑。 But that's the best you can do with the current tools, I don't think there is a way around that. 但这是使用当前工具可以做到的最好的选择,我认为没有办法解决。

… and you need to set a breakpoint …,您需要设置一个断点

No, you don't. 不,你没有。 You can use the “pause” button in VS (real name Break All), edit your code and then let it continue executing. 您可以使用VS中的“暂停”按钮(实名Break All),编辑代码,然后继续执行。

.NET's edit and continue is nowhere near as good as that provided by Visual C++, Visual Basic or any dynamic (ie script) languages which is a pity. .NET的编辑和继续功能远不及Visual C ++,Visual Basic或任何动态(即脚本)语言所提供的那样好。

If you can live with the limitations (having to break execution, no 64-bit support unless you are v4.5.1+, no lambda/linq changes, changing active statements, and a few others) then you should be ok to do pretty much the same. 如果您可以忍受这些限制 (必须中断执行,除非您是v4.5.1 +,否则必须提供64位支持,请不要对lambda / linq进行任何更改,更改活动语句等),那么您应该可以做很多事情相同。 I find though, that I always end up wanting to change something that's unsupported :( 但是我发现,我总是最终想要更改不受支持的内容:(

The big alternative is to use unit tests - in that, if you have enough tests you do not need to go debugging into your code at all. 最大的选择是使用单元测试-在这种情况下,如果您有足够的测试,则根本不需要调试代码。 I think its debatable whether you save more time or not, and maybe it depends on the programmer style which suits you better. 我认为是否节省更多时间值得商think,也许这取决于更适合您的程序员风格。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM