Browse Source

Minor refactor and added Guard for null image.

pull/326/head
Dirk Lemstra 9 years ago
parent
commit
53e1741ab5
  1. 26
      src/ImageSharp/Image/ImageFrameCollection.cs

26
src/ImageSharp/Image/ImageFrameCollection.cs

@ -91,17 +91,6 @@ namespace SixLabors.ImageSharp
this.frames.Add(frame); this.frames.Add(frame);
} }
private void ValidateFrameSize(ImageFrame<TPixel> 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));
}
}
}
/// <summary> /// <summary>
/// Determines whether the <seealso cref="Image{TPixel}"/> contains the <paramref name="frame"/>. /// Determines whether the <seealso cref="Image{TPixel}"/> contains the <paramref name="frame"/>.
/// </summary> /// </summary>
@ -122,7 +111,7 @@ namespace SixLabors.ImageSharp
/// <exception cref="InvalidOperationException">Cannot remove last frame</exception> /// <exception cref="InvalidOperationException">Cannot remove last frame</exception>
public bool Remove(ImageFrame<TPixel> frame) public bool Remove(ImageFrame<TPixel> 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"); throw new InvalidOperationException("Cannot remove last frame");
} }
@ -135,5 +124,18 @@ namespace SixLabors.ImageSharp
/// <inheritdoc/> /// <inheritdoc/>
IEnumerator IEnumerable.GetEnumerator() => ((IEnumerable)this.frames).GetEnumerator(); IEnumerator IEnumerable.GetEnumerator() => ((IEnumerable)this.frames).GetEnumerator();
private void ValidateFrameSize(ImageFrame<TPixel> 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));
}
}
}
} }
} }
Loading…
Cancel
Save