ReSharper 2026.1 Help

代码检查:String.Format(format, ...) 仅接受字符串字面量和常量字符串

当格式参数不是字符串字面量、常量字符串或插值字符串时,此检查会报告 string.Format(...) 在由 Burst 编译器 编译的代码中的调用。

Burst 仅支持受限形式的 string.Format。 如果格式字符串来自可变字段、变量或其他非常量来源,此检查会发出警告。

示例

此示例中,格式字符串存储在静态字段中。 在 Burst 编译代码中不支持此操作。

using Unity.Burst; using Unity.Jobs; [BurstCompile] public struct ExampleJob : IJob { private static string format = "Value: {0}"; public void Execute() { // Reported: mutable format string is not supported string.Format(format, 12); } }
using Unity.Burst; using Unity.Jobs; [BurstCompile] public struct ExampleJob : IJob { public void Execute() { // Correct: Use a string literal directly string.Format("Value: {0}", 12); } }

快速修复

此检查不提供专用的快速修复。 手动修复时,将格式参数替换为字符串字面量或 const 字符串。

2026年 5月 8日