-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bypass incautious accessors (really fixes #33)
- Loading branch information
Showing
4 changed files
with
41 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Collections.Generic; | ||
|
||
namespace Astrogator { | ||
|
||
/// <summary> | ||
/// Going to extra effort to be lazy | ||
/// </summary> | ||
public static class EnumerableExtensions | ||
{ | ||
|
||
/// <summary> | ||
/// Return the first element in a sequence matching a predicate, | ||
/// or the the first element at all if none match. | ||
/// </summary> | ||
/// <typeparam name="T">The type of elements in the sequence</typeparam> | ||
/// <param name="source">The sequence to scan, may be checked twice</param> | ||
/// <param name="predicate">The predicate to check per element</param> | ||
/// <returns></returns> | ||
public static T FirstOrDefaultOrFirst<T>(this IEnumerable<T> source, Func<T, bool> predicate) | ||
where T : class | ||
=> source.FirstOrDefault(predicate) ?? source.FirstOrDefault(); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters