Skip to content

Commit

Permalink
Do not create lambdas + apply MSVS suggestion regarding pattern match…
Browse files Browse the repository at this point in the history
…ing + add braces
  • Loading branch information
MartyIX committed Mar 26, 2024
1 parent 1b3612b commit 39b7ec6
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions src/Controls/src/Core/EnumerableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,52 +8,54 @@ static class EnumerableExtensions
public static bool HasChildGesturesFor<T>(this IEnumerable<GestureElement>? elements, Func<T, bool>? predicate = null) where T : GestureRecognizer
{
if (elements is null)
{
return false;

if (predicate is null)
predicate = x => true;
}

foreach (var element in elements)
{
foreach (var item in element.GestureRecognizers)
{
var gesture = item as T;
if (gesture != null && predicate(gesture))
if (item is T gesture && (predicate is null || predicate(gesture)))
{
return true;
}
}
}

return false;
}

public static IEnumerable<T> GetChildGesturesFor<T>(this IEnumerable<GestureElement>? elements, Func<T, bool>? predicate = null) where T : GestureRecognizer
{
if (elements is null)
{
yield break;

if (predicate is null)
predicate = x => true;
}

foreach (var element in elements)
{
foreach (var item in element.GestureRecognizers)
{
var gesture = item as T;
if (gesture != null && predicate(gesture))
if (item is T gesture && (predicate is null || predicate(gesture)))
{
yield return gesture;
}
}
}
}

/// <remarks>The method makes a defensive copy of the gestures.</remarks>
public static IEnumerable<T> GetGesturesFor<T>(this IEnumerable<IGestureRecognizer>? gestures, Func<T, bool>? predicate = null) where T : GestureRecognizer
{
if (gestures is null)
{
yield break;

if (predicate is null)
predicate = x => true;
}

foreach (IGestureRecognizer item in new List<IGestureRecognizer>(gestures))
{
var gesture = item as T;
if (gesture != null && predicate(gesture))
if (item is T gesture && (predicate is null || predicate(gesture)))
{
yield return gesture;
}
Expand All @@ -67,11 +69,9 @@ public static bool HasAnyGesturesFor<T>(this IEnumerable<IGestureRecognizer>? ge
return false;
}

predicate ??= x => true;

foreach (IGestureRecognizer item in gestures)
{
if (item is T gesture && predicate(gesture))
if (item is T gesture && (predicate is null || predicate(gesture)))
{
return true;
}
Expand Down

0 comments on commit 39b7ec6

Please sign in to comment.