我尝试在我们产品的几个程序集上运行FxCop,但我得到了很多“Specify IFormatProvider”规则的匹配项。
事实上,其中一些是合法的,但它也匹配这样的代码:
Logger.DebugFormat("Appending file {0}", fileName);
这可以写成
Logger.DebugFormat(CultureInfo.InvariantCulture, "Appending file {0}", fileName);
第二个变量的可读性要差得多。
那么,是否真的建议始终指定IFormatProvider,还是仅仅是规则中使用启发式算法的限制?
Logger.DebugFormat(CulturedText.Format("Appending file {0}", fileName));
。 - Peter O.