diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c0f485..9b66907 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +### Added + - Added extension method for peeking queues + ## [9.3.0] - 2019-04-16 ### Added - Added SPlusUtils with ConvertToInt method taking LowWord/HighWord ushorts diff --git a/ICD.Common.Utils/Extensions/QueueExtensions.cs b/ICD.Common.Utils/Extensions/QueueExtensions.cs index b317b32..f8f379b 100644 --- a/ICD.Common.Utils/Extensions/QueueExtensions.cs +++ b/ICD.Common.Utils/Extensions/QueueExtensions.cs @@ -43,5 +43,26 @@ namespace ICD.Common.Utils.Extensions item = extends.Dequeue(); return true; } + + /// + /// Peeks the next item in the queue. Returns false if the queue is empty. + /// + /// + /// + /// + /// + public static bool Peek(this Queue extends, out T item) + { + if (extends == null) + throw new ArgumentNullException("extends"); + + item = default(T); + + if (extends.Count == 0) + return false; + + item = extends.Peek(); + return true; + } } }