[英]Named format placeholders in ReSharper annotations?
ReSharper has the fantastic StringFormatMethodAttribute
annotation which provides code analysis for format strings and their parameters. ReSharper 具有出色的StringFormatMethodAttribute
注释,它为格式字符串及其参数提供代码分析。 It can be added to any custom string format methods like this:它可以添加到任何自定义字符串格式方法中,如下所示:
[StringFormatMethod("format")]
void DebugFormat(string format, params object[] args);
This works well when using integer placeholders, eg:这在使用整数占位符时效果很好,例如:
x.DebugFormat("ReSharper is {0} for {1} placeholders", "great", "numbered");
However, some libraries (like Serilog and ASP.Net Core / Microsoft.Extensions.Logging ) offer named format placeholders which are used for (semantic | structured) logging and this seems to be something that ReSharper does not (yet) offer.但是,某些库(如Serilog和ASP.Net Core / Microsoft.Extensions.Logging )提供用于(语义 | 结构化)日志记录的命名格式占位符,而这似乎是 ReSharper(尚未)提供的。 For example, a line of code like this:比如像这样的一行代码:
x.DebugFormat("ReSharper is {Quality} for {Style} placeholders", "poor?", "named");
Results in the ReSharper code analysis warning导致 ReSharper 代码分析警告
Format item index must be a number starting 0 without leading or trailing whitespaces格式项索引必须是从 0 开始的数字,没有前导或尾随空格
Searching on ReSharper support, this site, and Google draws a blank.在 ReSharper 支持、本网站和 Google 上搜索,结果一片空白。 Has anyone found a way to get string format annotations working with named placeholders?有没有人找到一种方法来获取使用命名占位符的字符串格式注释?
Relevant JetBrains links:相关 JetBrains 链接:
I have implemented an R# extension for this.我为此实现了一个 R# 扩展。 Download it here from JetBrains. 在此处从 JetBrains 下载。
It is also hosted on GitHub .它也托管在 GitHub 上。
This extension highlights structured logging templates and contains some useful analyzers.这个扩展突出了结构化日志模板并包含一些有用的分析器。 Here is how the structured logging events look with the plugin installed:以下是安装了插件的结构化日志事件的外观:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.