[英]Making a third-party method [Obsolete]
如果我想在我的代码中将一个方法声明为已弃用/过时,我可以向它添加[Obsolete]
属性,并使编译器在使用该方法时发出警告(或错误)。
对于第三方方法(例如System.Console.WriteLine
)是否可以实现类似的效果? 显然,我无法添加该属性,因为我无法控制代码。 但也许 .NET 或 Visual Studio 中还有其他一些技巧?
我最好寻找一种“开箱即用”的解决方案,它不需要像编写我自己的手动解析代码的构建后脚本之类的东西。
ReSharper 用户的另一个选择: ExternalAnnotations 。
以下是为 Selenium 的WebDriver.dll
添加注释的示例:
*.csproj
旁边创建ExternalAnnotations
文件夹。WebDriver.xml
: <?xml version="1.0" encoding="utf-8" ?> <assembly name="WebDriver"> <member name="M:OpenQA.Selenium.INavigation.GoToUrl(System.String)"> <attribute ctor="M:System.ObsoleteAttribute.#ctor(System.String,System.Boolean)"> <argument>Use different overload of this method.</argument> <argument>true</argument> </attribute> </member>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.