如何在C#中有意地标记代码部分为警告?

huangapple go评论69阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年1月9日 01:13:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/75049825.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定