代码检查:无法在文本实参中访问 static 符号。
某些框架使用字符串文字来引用代码符号,例如字段、属性或方法。 static 成员并不总是能够用于需要实例成员的地方。 当引用的符号为 static 但目标上下文需要实例成员时,此检查会报告基于字符串的符号引用。
示例
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日