Skip to content

Latest commit

 

History

History
73 lines (49 loc) · 1.53 KB

RCS1077.md

File metadata and controls

73 lines (49 loc) · 1.53 KB

RCS1077: Simplify LINQ method chain

Property Value
Id RCS1077
Category Simplification
Default Severity Info
Enabled by Default
Supports Fade-Out -
Supports Fade-Out Analyzer -

Examples

Code with Diagnostic

bool x = items.Where(f => string.IsNullOrEmpty(f)).Any(); // RCS1077

Code with Fix

bool x = items.Any(f => string.IsNullOrEmpty(f));

Code with Diagnostic

IEnumerable<Foo> x = items.Where(f => f is Foo).Cast<Foo>(); // RCS1077

Code with Fix

IEnumerable<Foo> x = items.OfType<Foo>();

Code with Diagnostic

bool x = items.Where((f) => !string.IsNullOrEmpty(f)).Any(f => f.StartsWith("a")); // RCS1077

Code with Fix

bool x = items.Any((f) => !string.IsNullOrEmpty(f) && f.StartsWith("a"));

How to Suppress

SuppressMessageAttribute

[assembly: SuppressMessage("Simplification", "RCS1077:Simplify LINQ method chain.", Justification = "<Pending>")]

#pragma

#pragma warning disable RCS1077 // Simplify LINQ method chain.
#pragma warning restore RCS1077 // Simplify LINQ method chain.

Ruleset

(Generated with DotMarkdown)