C#中:如果在源代码中使用某些方法在Visual Studio自定义警告 [英] C#: Create custom warning in Visual Studio if certain method is used in source code

查看:73
本文介绍了C#中:如果在源代码中使用某些方法在Visual Studio自定义警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法输出在调试器的警告,如果在代码中使用某种方法?我有一对夫妇的应该只有在特殊情况下使用细腻的方法,所以我想有某种报警输出,如果他们实际上是在任何地方的项目叫。

Is there a way to output a warning in the debugger if a certain method is used in the code? I have a couple of delicate methods that should only be used in exceptional cases, so I'd like to have some kind of warning output if they are actually called anywhere in the project.

这可能吗?

推荐答案

您应该考虑使用的 过时属性。它允许你标记不应该被使用的方法。它有两个可选参数的消息,并指示是否应该编译失败或引发警告标志。

You should consider using the Obsolete attribute. It allows you to mark a method which should not be used. It takes two optional parameters a message and a flag indicating if the complier should fail or raise a warning.

这篇关于C#中:如果在源代码中使用某些方法在Visual Studio自定义警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆