代码检查:捕获的按引用传递类的字段引用可能导致运行时异常。
从 MarshalByRefObject 派生的类型的字段通过引用传递是不安全的。 即使代码看起来有效,这样做在运行时也可能失败。 此检查会报告引用了按引用传递类字段的 ref、 out 或 in 参数。
示例
using System;
class DataHolder : MarshalByRefObject
{
public int Value;
}
class Example
{
void Update(ref int x) { }
void Test(DataHolder holder)
{
Update(ref holder.Value);
}
}
using System;
class DataHolder : MarshalByRefObject
{
public int Value;
}
class Example
{
void Update(ref int x) { }
void Test(DataHolder holder)
{
var value = holder.Value;
Update(ref value);
}
}
2026年 5月 8日