Skip to content

Latest commit

 

History

History
51 lines (37 loc) · 1.2 KB

SA1410.md

File metadata and controls

51 lines (37 loc) · 1.2 KB

SA1410

TypeName SA1410RemoveDelegateParenthesisWhenPossible
CheckId SA1410
Category Maintainability Rules

Cause

A call to a C# anonymous method does not contain any method parameters, yet the statement still includes parenthesis.

Rule description

When an anonymous method does not contain any method parameters, the parenthesis around the parameters are optional.

A violation of this rule occurs when the parenthesis are present on an anonymous method call which takes no method parameters. For example:

this.Method(delegate() { return 2; });

The parenthesis are unnecessary and should be removed:

this.Method(delegate { return 2; });

How to fix violations

Remove the unnecessary parenthesis after the delegate keyword.

How to suppress violations

[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1410:RemoveDelegateParenthesisWhenPossible", Justification = "Reviewed.")]
#pragma warning disable SA1410 // RemoveDelegateParenthesisWhenPossible
#pragma warning restore SA1410 // RemoveDelegateParenthesisWhenPossible