ReSharper 2026.1 Help

代码检查:某些 SharedStatic`1.GetOrCreate 重载会导致编译器错误

此检查会报告在由 Burst 编译器编译的代码中,使用带有 SharedStatic<T>.GetOrCreate 重载并带有 System.Type 参数的情况。

这些重载在 C# 中可用,但在 Burst 中可能导致编译器错误。 检查建议改用通用的 GetOrCreate<...>() 重载。

示例

在此示例中, GetOrCreate 方法以 typeof 表达式调用。 在 Burst 中不被支持,会被标记。

using Unity.Burst; using Unity.Jobs; [BurstCompile] public struct ExampleJob : IJob { public void Execute() { // Reported: typeof is not supported in GetOrCreate var shared = SharedStatic<int>.GetOrCreate(typeof(double)); } }
using Unity.Burst; using Unity.Jobs; [BurstCompile] public struct ExampleJob : IJob { public void Execute() { // Correct: Use the generic overload var shared = SharedStatic<int>.GetOrCreate<double>(); } }

快速修复

此检查不提供专用的快速修复。 请手动切换为通用的 SharedStatic<T>.GetOrCreate 重载来修复。 对于两个类型参数,请使用 GetOrCreate<TContext, TSubContext>() 来替代 GetOrCreate(typeof(...), typeof(...))

2026年 5月 8日