Permalink
707b719 Jun 13, 2018
1 contributor

Users who have contributed to this file

201 lines (136 sloc) 2.64 KB

RCS1077: Optimize LINQ method call

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

Examples

Code with Diagnostic

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

Code with Fix

bool x = items.Any(f => Foo(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) => Foo1(f)).Any(f => Foo2(f)); // RCS1077

Code with Fix

bool x = items.Any((f) => Foo1(f) && Foo2(f));

Code with Diagnostic

IEnumerable<object> x = items.Select(f => (object)f); // RCS1077

Code with Fix

IEnumerable<object> x = items.Cast<object>();

Code with Diagnostic

bool x = items.FirstOrDefault((f) => Foo(f)) != null; // RCS1077

Code with Fix

bool x = items.Any((f) => Foo(f));

Code with Diagnostic

bool x = items.FirstOrDefault() != null; // RCS1077

Code with Fix

bool x = items.Any();

Code with Diagnostic

var x = list.ElementAt(1); // RCS1077

Code with Fix

var x = list[1];

Code with Diagnostic

var x = list.First(); // RCS1077

Code with Fix

var x = list[0];

Code with Diagnostic

if (enumerable.Count() != 0) // RCS1077
{
}

Code with Fix

if (enumerable.Any())
{
}

Code with Diagnostic

if (list.Count() == 1) // RCS1077
{
}

Code with Fix

if (list.Count == 1)
{
}

Code with Diagnostic

var stack = new Stack<object>();
// ...
object x = stack.First(); // RCS1077

Code with Fix

var stack = new Stack<object>();
// ...
object x = items.Peek();

Code with Diagnostic

var queue = new Queue<object>();
// ...
object x = stack.First(); // RCS1077

Code with Fix

var queue = new Queue<object>();
// ...
object x = items.Peek();

See Also

(Generated with DotMarkdown)