代码检查:无法在文本参数中访问静态符号。
某些框架使用字符串字面量来引用字段、属性或方法等代码符号。 静态成员并不总是可以用于需要实例成员的位置。 当被引用的符号是静态的但目标上下文需要实例成员时,此检查会报告基于字符串的符号引用。
示例
class Person
{
public static string FullName => "John Smith";
}
// The string is expected to point to an instance member.
[SomeFrameworkAttribute("FullName")]
class Example
{
}
class Person
{
public string FullName => "John Smith";
}
[SomeFrameworkAttribute("FullName")]
class Example
{
}
2026年 5月 8日