如何抛出像[ObsoleteAttribute]那样的编译器警告/错误。 [英] How to throw a compiler warning/error like [ObsoleteAttribute] does.

查看:107
本文介绍了如何抛出像[ObsoleteAttribute]那样的编译器警告/错误。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为这不可行,但我一直希望如此。



申请 [已废弃(你真的不应该再使用它了。)] 到一个成员,它会导致编译器生成警告或错误,然后出现在Visual Studio的错误列表中。



能够执行此操作会很棒在构建其他过时条件的组件时,甚至类似于: [实验(此方法仍在开发中,不应在生产环境中使用。)] 等。



任何人?



仅供参考: System.ObsoleteAttribute 密封

解决方案

不幸的是,没有魔法 ObsoleteAttribute [ ^ ]上课。编译器服务查找此属性并在对话框中显示警告。



但是,您可以自己发出警告,例如:



  public   void  MyMethod()
{
#warning此方法仍在开发中,不建议用于生产。
}





参见#warning [ ^ ]


I don't think this is possible, but I have always hoped it is.

When you apply [Obsolete("You really shouldn't use this anymore.")] to a member, it causes the compiler to generate a warning or error, which then appears in the Error List in Visual Studio.

It would be amazing to be able to do this when building components for conditions other obsolescence, even something like: [Experimental("This method is still in development and should not be used in production environments.")] and the like.

Anyone?

FYI: System.ObsoleteAttribute is sealed.

解决方案

Unfortunately there is no magic in the ObsoleteAttribute[^] class. The compiler service looks for this attribute and displays the warnings in the dialog box.

However, you can raise warnings yourself, like:

public void MyMethod()
{
#warning This method is still in development and is not recommended for production.
}



See #warning[^]


这篇关于如何抛出像[ObsoleteAttribute]那样的编译器警告/错误。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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