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

查看:11
本文介绍了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天全站免登陆