英文:
How to mark a code section with a warning purposely in C#?
问题
有没有可能例如使用#pragma在VS IDE中发出自定义警告?我需要它一段时间,因为这段代码中有两个类包含完全相同的数据,但继承自完全不同的类(Attribute,EventArgs)。因此,如果一个人修改了前一个类而没有修改后一个类,整个系统将停止工作。
只要没有解决方案,我想发出这个自定义警告,以便每个尝试启动新构建的人都必须同意他们已经注意到了这种代码异味。
英文:
is it possible to for example use #pragma to raise a custom warning within the VS IDE? I'd need it for a while because there are two classes in this code that contain the very same data but derive from very different classes (Attribute, EventArgs). So if one modified the former class without modifying the latter, the whole system would stop working.
As long as there is no solution, I'd like to raise this custom warning so that everybody trying to start a new build must agree on that they recognized the code smell.
答案1
得分: 3
看起来你正在寻找 #warning
指令。
#warning
指令是一个预处理器指令,用于在编译时生成警告消息。当你修改某个方法时,需要注意这个警告,如果修改了方法,还必须修改其他相关部分。
你可以查看更多关于 #warning
指令的信息 这里。
英文:
It seems you are looking #warning directive
#warning careful with this method, if modified you have to modify this and that.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论