Naming Method
ID |
csharp.naming_method |
Severity |
info |
Remediation Complexity |
trivial |
Remediation Risk |
medium |
Remediation Effort |
low |
Resource |
Naming Convention |
Language |
CSharp |
Tags |
naming |
Description
Reports C# method names that do not follow the PascalCase convention. A method
name must start with an uppercase letter, unless the name contains an underscore
that is not purely leading or trailing — that shape is a deliberate naming scheme
(an event handler, a framework wire-by-name hook) and is exempt from the casing
check. A leading or trailing underscore is always reported.
Rationale
The .NET design guidelines specify PascalCase for method names. Consistent
casing is one of the strongest readability signals in a codebase, and tooling,
frameworks and other developers all rely on that expectation. A method called
computeTotal stands out as foreign and slows down everyone reading the code.
Casing is not enforced when a name already contains an underscore that is not
purely leading or trailing. object_EventName-shaped names (Button_Click,
Application_Start) are the common case this exempts — the underscore is the
framework or platform’s naming contract, not a violation of it.
public class Service
{
public void Compute() { } // OK
public void compute() { } // FLAW — starts lowercase, no underscore
public void do_work() { } // OK — underscore exempts camel casing
public void Button_Click(object sender, EventArgs e) { } // OK — compliant by exception
public void _leading() { } // FLAW — leading underscore
public void trailing_() { } // FLAW — trailing underscore
}