- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
ReSharpers StringFormatMethodAttribute
是跟踪执行字符串格式化的方法的参数的好方法。
所以我以这种方式实现了一个方法:
[StringFormatMethod("format")]
public string Format(string format, params object[] args)
{
// do formatting by custom formatters
}
这让我有能力做那样的事情
Format("Hello {0}!", world); // => Hello world!
Format("({0:D2} / {1:D2}", 2, 3); // => (02/03)
或在 Visual Basic 中
Format("Hello {0}!", visualBasic) ' => Hello Visual Basic!
如果我错过了一个参数或其位置,ReSharper 会警告我
Format("Hello {1}!", world);
// ^--- Non-existing argument in format string
Format("Hello {1}!", world, value);
// ^--- Argument is not used in format string
该方法使用了 ICustomFormatter
所以如果我直接这样做的话
string.Format(customFormatter, "The thread id is {0:D}", Thread.CurrentThread);
ReSharper 不会提示。
使用我的方法(但是在内部使用自定义格式)会使 ReSharper 发出警告并提示
Format("The thread id is {0:D}", Thread.CurrentThread);
// ^--- Formatting is specified,
// but argument is not IFormattable
我一般不想禁用此警告,只禁用格式问题部分,如果可能,只禁用我自己编写的方法。所以我的问题是,有没有办法,也许是通过另一个属性让 ReSharper 知道这个方法在内部使用自定义格式化程序?
最佳答案
正如您(从用户名猜测)了解到的那样from a post on the JetBrains developer forum通过 citizenmatt ,
Unfortunately, you can't disable this analysis. I've added a feature request, which you can vote for, track and add any extra details: https://youtrack.jetbrains.com/issue/RSRP-450291
关于c# - 如何为特殊方法抑制 "formatting is specified but argument is not iformattable"消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33290136/
IFormattable有没有好的引用实现?我打算至少定制一个 IFormatProvider对于我的对象,我想确保传递给 IFormattable.ToString(string, IFormatP
string listOfItemPrices = items.ToSemiColonList(item => string.Format("{0:C}", item.Price.ToString()
String.Format 和 IFormattable.ToString(format, value) 在尝试格式化为十六进制时提供不同的结果。使用 IFormattable.ToString(fo
我有一个处理字符串输入的函数。 public string Foo(string text) { // do stuff with text and /
我在将数字转换为 IFormattable、在其上调用 ToString(...) 并传递 from 0.000;-;0 的 FormatCode 时遇到问题,这意味着我想显示正数精确到小数点后三位,
我对 .NET 中不同形式的序列化缺乏一致性感到有点沮丧: DataContractSerializer - 使用新属性或旧的 [Serializable] 属性,但序列化程序本身并不像其他一些 WC
FormattableString 已在 C# 6.0 中引入。因为我们可以使用 string 对象使用相同的字符串格式,所以为什么需要使用 FormattableString 或 IFormatta
ReSharpers StringFormatMethodAttribute 是跟踪执行字符串格式化的方法的参数的好方法。 所以我以这种方式实现了一个方法: [StringFormatMethod("
IFormattable、IFormatProvider和ICustomFormatter有什么区别和联系,什么时候用?一个简单的实现示例也会非常好。 我并不是说什么时候在 .net 框架中使用它,而
第一次在 .net C# 中使用二进制格式 来自MSDN的代码是这样的: IFormatter formatter = new BinaryFormatter(); Stream stream =
我是一名优秀的程序员,十分优秀!