C#8 可空类型 (?) 与 ReSharper 可空性注释
我正在开发一个 ABP 项目,注意到 ReSharper 自动将可空类型(如 string?
)格式化为 [CanBeNull] string
。
与 C# 8 功能相比,使用 ReSharper Annotations 是否还有任何优势?
I'm working on an ABP project and noticed that ReSharper auto-formats a nullable type like string?
to [CanBeNull] string
.
Is there still any benefit to using ReSharper Annotations over C# 8 features?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
属性
[CanBeNull]
等是 ReSharper 实现可空性注释的方式。这可能是我的观点,但展望未来,我相信这些已经过时了。如果您使用 C# 8 可空类型,这些属性也会令人困惑和冲突。只需从项目中删除 ReSharperAnnotations.cs
文件并更改代码以使用新的?
语法。此外,您可能希望启用 ReSharper 配置选项“使用可以为空的注释而不是属性”。我不确定是否还有更多类似的选项,但我从未见过您上面描述的自动替换。
The attributes
[CanBeNull]
etc. were ReSharper's way of implementing nullability annotations. This may be my opinion, but going forward, I believe these are obsolete. If you use C# 8 nullable types, these attributes are confusing and conflicting, too. Just delete the ReSharperAnnotations.cs
file from your project and change the code to use the new?
syntax.Additionally, you might want to enable the ReSharper configuration option "Use nullable annotation instead of an attribute". I'm not sure whether there are more similar options, but I have never seen an automatic replacement as you describe it above.