diff --git a/ChartTools/Chords/Phrase.cs b/ChartTools/Chords/Phrase.cs index 92050139..70fccb20 100644 --- a/ChartTools/Chords/Phrase.cs +++ b/ChartTools/Chords/Phrase.cs @@ -4,7 +4,7 @@ namespace ChartTools.Lyrics; public class Phrase : TrackObjectBase, IChord, ILongTrackObject { - public List Syllables { get; } = new(); + public List Syllables { get; } = []; IReadOnlyCollection IChord.Notes => Syllables; /// diff --git a/ChartTools/Exceptions/DesynchronizedAnchorException.cs b/ChartTools/Exceptions/DesynchronizedAnchorException.cs index 9e7d5cb1..468b1998 100644 --- a/ChartTools/Exceptions/DesynchronizedAnchorException.cs +++ b/ChartTools/Exceptions/DesynchronizedAnchorException.cs @@ -3,10 +3,9 @@ /// /// Exception thrown when an invalid operation is performed on a desynchronized anchored . /// -public class DesynchronizedAnchorException : Exception +public class DesynchronizedAnchorException(TimeSpan anchor, string message) : Exception(message) { - public TimeSpan Anchor { get; } + public TimeSpan Anchor { get; } = anchor; public DesynchronizedAnchorException(TimeSpan anchor) : this(anchor, $"Invalid operation performed with desynchronized anchored tempo at {anchor}.") { } - public DesynchronizedAnchorException(TimeSpan anchor, string message) : base(message) => Anchor = anchor; } diff --git a/ChartTools/Extensions/Collections/Alternating/OrderedAlternatingEnumerable.cs b/ChartTools/Extensions/Collections/Alternating/OrderedAlternatingEnumerable.cs index 0b1c6110..0d394bb1 100644 --- a/ChartTools/Extensions/Collections/Alternating/OrderedAlternatingEnumerable.cs +++ b/ChartTools/Extensions/Collections/Alternating/OrderedAlternatingEnumerable.cs @@ -29,10 +29,9 @@ public class OrderedAlternatingEnumerable : IEnumerable where TKey : /// public OrderedAlternatingEnumerable(Func keyGetter, params IEnumerable?[] enumerables) { - if (keyGetter is null) - throw new ArgumentNullException(nameof(keyGetter)); - if (enumerables is null) - throw new ArgumentNullException(nameof(enumerables)); + ArgumentNullException.ThrowIfNull(keyGetter); + ArgumentNullException.ThrowIfNull(enumerables); + if (enumerables.Length == 0) throw new ArgumentException("No enumerables provided."); @@ -48,13 +47,15 @@ public OrderedAlternatingEnumerable(Func keyGetter, params IEnumerable< /// /// Enumerator that yields items from a set of enumerators in order using a key /// - private class Enumerator : IInitializable, IEnumerator + /// Method that retrieves the key from an item + /// Enumerators to alternate between + private class Enumerator(Func keyGetter, params IEnumerator[] enumerators) : IInitializable, IEnumerator { - private IEnumerator[] Enumerators { get; } + private IEnumerator[] Enumerators { get; } = enumerators.NonNull().ToArray(); /// /// Method that retrieves the key from an item /// - private Func KeyGetter { get; } + private Func KeyGetter { get; } = keyGetter; /// public bool Initialized { get; private set; } @@ -66,19 +67,8 @@ private class Enumerator : IInitializable, IEnumerator /// /// for indexes where MoveNext previously returned /// - readonly bool[] endsReached; + readonly bool[] endsReached = new bool[enumerators.Length]; - /// - /// Creates a new instance of . - /// - /// Method that retrieves the key from an item - /// Enumerators to alternate between - public Enumerator(Func keyGetter, params IEnumerator[] enumerators) - { - Enumerators = enumerators.NonNull().ToArray(); - KeyGetter = keyGetter; - endsReached = new bool[enumerators.Length]; - } ~Enumerator() => Dispose(false); /// diff --git a/ChartTools/Extensions/Collections/Alternating/SerialAlternatingEnumerable.cs b/ChartTools/Extensions/Collections/Alternating/SerialAlternatingEnumerable.cs index d730c482..1a5988c5 100644 --- a/ChartTools/Extensions/Collections/Alternating/SerialAlternatingEnumerable.cs +++ b/ChartTools/Extensions/Collections/Alternating/SerialAlternatingEnumerable.cs @@ -21,8 +21,8 @@ public class SerialAlternatingEnumerable : IEnumerable /// public SerialAlternatingEnumerable(params IEnumerable?[] enumerables) { - if (enumerables is null) - throw new ArgumentNullException(nameof(enumerables)); + ArgumentNullException.ThrowIfNull(enumerables); + if (enumerables.Length == 0) throw new ArgumentException("No enumerables provided."); @@ -37,12 +37,15 @@ public SerialAlternatingEnumerable(params IEnumerable?[] enumerables) /// /// Enumerator that yields items by alternating through a set of enumerators /// - private class Enumerator : IEnumerator + /// Enumerators to alternate between + /// + /// + private class Enumerator(params IEnumerator[] enumerators) : IEnumerator { /// /// Enumerators to alternate between /// - private IEnumerator[] Enumerators { get; } + private IEnumerator[] Enumerators { get; } = enumerators.NonNull().ToArray(); /// /// Position of the next enumerator to pull from /// @@ -55,14 +58,6 @@ private class Enumerator : IEnumerator /// object? IEnumerator.Current => Current; - /// - /// Creates an instance of - /// - /// Enumerators to alternate between - /// - /// - public Enumerator(params IEnumerator[] enumerators) => Enumerators = enumerators.NonNull().ToArray(); - /// public void Dispose() { diff --git a/ChartTools/TrackObjects/TrackObjectBase.cs b/ChartTools/TrackObjects/TrackObjectBase.cs index a572237c..aa1b174d 100644 --- a/ChartTools/TrackObjects/TrackObjectBase.cs +++ b/ChartTools/TrackObjects/TrackObjectBase.cs @@ -1,9 +1,8 @@ namespace ChartTools; -public abstract class TrackObjectBase : ITrackObject +public abstract class TrackObjectBase(uint position) : ITrackObject { - public virtual uint Position { get; set; } + public virtual uint Position { get; set; } = position; public TrackObjectBase() : this(0) { } - public TrackObjectBase(uint position) => Position = position; }