use-lambda
What it does
Section titled “What it does”Reports an anonymous method (delegate (x) { ... }) where a lambda can be written. The fix is offered when the anonymous method has a parameter list and no comment before its body; delegate { } without a parameter list converts to delegate types with any parameters, so it has no fix.
Why it matters
Section titled “Why it matters”Lambdas are the short and usual form, and they bind the same way for the common cases. One form for all code avoids the extra keyword and makes the file read the same.
Example
Section titled “Example”... int a, b;... void F(object o, int i) { var f = delegate (int x) { return x; };... }...... int a, b;... void F(object o, int i) { var f = (int x) => { return x; };... }...Configuration
Section titled “Configuration”csharp: lint: rules: use-lambda: warn # off (default), warn, errorEnabled by the presets: csharp/stylecop, csharp/roslynator.
Suppress one line with sudsy-disable-next-line use-lambda in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools; Sudsy reports what each upstream rule reports.
| Tool | Rule | Match |
|---|---|---|
| Roslynator | RCS1048 |
full |
| StyleCop | SA1130 |
full |