From ebb9daa02f9b7e51e12fa049c24c366d177ed94c Mon Sep 17 00:00:00 2001 From: Dirk Lemstra Date: Wed, 6 Sep 2017 23:14:09 +0200 Subject: [PATCH] Minor refactor and added Guard for null image. --- src/ImageSharp/Image/ImageFrameCollection.cs | 26 +++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/ImageSharp/Image/ImageFrameCollection.cs b/src/ImageSharp/Image/ImageFrameCollection.cs index bfd8e5e91..466e2ec39 100644 --- a/src/ImageSharp/Image/ImageFrameCollection.cs +++ b/src/ImageSharp/Image/ImageFrameCollection.cs @@ -91,17 +91,6 @@ namespace SixLabors.ImageSharp this.frames.Add(frame); } - private void ValidateFrameSize(ImageFrame frame) - { - if (this.Count != 0) - { - if (this.RootFrame.Width != frame.Width || this.RootFrame.Height != frame.Height) - { - throw new ArgumentException("Frame must have the same dimensions as the image", nameof(frame)); - } - } - } - /// /// Determines whether the contains the . /// @@ -122,7 +111,7 @@ namespace SixLabors.ImageSharp /// Cannot remove last frame public bool Remove(ImageFrame frame) { - if (this.frames.Count == 1 && this.frames.Contains(frame)) + if (this.Count == 1 && this.frames.Contains(frame)) { throw new InvalidOperationException("Cannot remove last frame"); } @@ -135,5 +124,18 @@ namespace SixLabors.ImageSharp /// IEnumerator IEnumerable.GetEnumerator() => ((IEnumerable)this.frames).GetEnumerator(); + + private void ValidateFrameSize(ImageFrame frame) + { + Guard.NotNull(frame, nameof(frame)); + + if (this.Count != 0) + { + if (this.RootFrame.Width != frame.Width || this.RootFrame.Height != frame.Height) + { + throw new ArgumentException("Frame must have the same dimensions as the image", nameof(frame)); + } + } + } } } \ No newline at end of file