Code inspection: Use 'nameof' expression to reference name in part of the string literal
This inspection reports string literals where only part of the text is a hard-coded member or type name that can be replaced with nameof(...). This is useful when the string contains extra text around the symbol name, such as in attributes or formatted strings.
Example
[TestCaseSource(typeof(TestCaseGenerator), "Generate")]
public void Test1() { }
[TestCaseSource(typeof(TestCaseGenerator), nameof(TestCaseGenerator.Generate))]
public void Test1() { }
Quick-fix
Using nameof(...) for the symbol part keeps the string in sync when the referenced symbol is renamed.
30 March 2026