制作第三方方法 [已过时] [英] Making a third-party method [Obsolete]

查看:17
本文介绍了制作第三方方法 [已过时]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我想将我的代码中的方法声明为已弃用/过时,我可以向其添加[Obsolete]属性并使编译器发出警告(或错误)无论何时使用该方法.

If I want to declare a method in my code as deprecated / obsolete, I can add the [Obsolete] attribute to it and make the compiler emit a warning (or error) whenever the method is used.

第三方方法(如System.Console.WriteLine)是否可以达到类似的效果?显然,我无法添加该属性,因为我无法控制代码.但也许 .NET 或 Visual Studio 中还有其他一些技巧?

Is it possible to achieve a similar effect for third-party methods (such as System.Console.WriteLine)? Obviously, I cannot add the attribute since I do not control the code. But maybe there is some other trick available in .NET or Visual Studio?

我最好寻找一种开箱即用"的解决方案,它不需要像编写自己的构建后脚本那样手动解析代码.

I'm preferably looking for an "out of the box" solution that does not require something like writing my own post-build script that manually parses the code.

推荐答案

借助 Visual Studio 2015,您可以创建实时代码分析器,为几乎所有内容提供自定义设计时检查.此处提供了一个很好的教程.这些通常作为解决方案的一部分存在,因此无论在哪里编译,它们都会跟进".

With Visual Studio 2015 you can create live Code Analyzers that can provide custom design-time checking for virtually anything. A good tutorial is available here. These usually live as part of the solution, so so they will "follow it around" no matter where it is compiled.

代码分析器可以引发编译时错误或警告,甚至可以显示 UI 以自动更正问题.它们可能非常强大,但根据您的需要,编写其中之一可能相当复杂.

Code analyzers can can raise compile time errors or warnings, and can even present a UI to automatically correct the issue. They can be VERY powerful, but writing one of these can be fairly complex depending on what you need.

A 类似功能存在于早期版本的 Visual Studio (2010+).它的集成度不高,但可能适合您.

A similar feature exists for previous versions of Visual Studio (2010+). It isn't as well integrated, but might work for you.

这篇关于制作第三方方法 [已过时]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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