抑制 vb.net 中工厂方法的过时警告
是否可以防止由返回过时类实例的静态工厂方法引起的编译器警告?
例如,如果通过静态方法 (Create) 创建过时类 (Foo) 的实例,则工厂方法会导致编译器警告。
<Obsolete()> _
Public Class Foo
Public Shared Function Create() As Foo
' Instantiate and return
End Function
End Class
在 C# 中,可以使用“#pragma warning...”来抑制警告,但我认为 VB.Net 中不存在这种情况。由于业务需求,迁移到 C# 不是一个选择。
Is it possible to prevent compiler warning caused by a static factory method returning an instance of an obsolete class?
For example if an instance of an obsolete class (Foo) is created through a static method (Create) a compiler warning is caused by the factory method.
<Obsolete()> _
Public Class Foo
Public Shared Function Create() As Foo
' Instantiate and return
End Function
End Class
In C# the warning could be suppressed using "#pragma warning..." but I don't think that this exists within VB.Net. Migrating to C# is not an option due to business requirements.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你必须用记事本打开 .vbproj 文件,搜索 NoWarn-Tag 并在其中添加错误 ID(618 应该是过时警告):
I think you have to open the .vbproj-file with notepad, search the NoWarn-Tag and add the error-id there(618 should be obsolete-warning):