Browse Source

Image<TPixel>.Frames now properly throws ObjectDisposedException after being disposed

pull/1629/head
Dmitry Pentin 5 years ago
parent
commit
7900b43d1d
  1. 19
      src/ImageSharp/Image{TPixel}.cs

19
src/ImageSharp/Image{TPixel}.cs

@ -25,6 +25,8 @@ namespace SixLabors.ImageSharp
{ {
private bool isDisposed; private bool isDisposed;
private ImageFrameCollection<TPixel> frames;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Image{TPixel}"/> class /// Initializes a new instance of the <see cref="Image{TPixel}"/> class
/// with the height and the width of the image. /// with the height and the width of the image.
@ -84,7 +86,7 @@ namespace SixLabors.ImageSharp
internal Image(Configuration configuration, int width, int height, ImageMetadata metadata) internal Image(Configuration configuration, int width, int height, ImageMetadata metadata)
: base(configuration, PixelTypeInfo.Create<TPixel>(), metadata, width, height) : base(configuration, PixelTypeInfo.Create<TPixel>(), metadata, width, height)
{ {
this.Frames = new ImageFrameCollection<TPixel>(this, width, height, default(TPixel)); this.frames = new ImageFrameCollection<TPixel>(this, width, height, default(TPixel));
} }
/// <summary> /// <summary>
@ -104,7 +106,7 @@ namespace SixLabors.ImageSharp
ImageMetadata metadata) ImageMetadata metadata)
: base(configuration, PixelTypeInfo.Create<TPixel>(), metadata, width, height) : base(configuration, PixelTypeInfo.Create<TPixel>(), metadata, width, height)
{ {
this.Frames = new ImageFrameCollection<TPixel>(this, width, height, memoryGroup); this.frames = new ImageFrameCollection<TPixel>(this, width, height, memoryGroup);
} }
/// <summary> /// <summary>
@ -124,7 +126,7 @@ namespace SixLabors.ImageSharp
ImageMetadata metadata) ImageMetadata metadata)
: base(configuration, PixelTypeInfo.Create<TPixel>(), metadata, width, height) : base(configuration, PixelTypeInfo.Create<TPixel>(), metadata, width, height)
{ {
this.Frames = new ImageFrameCollection<TPixel>(this, width, height, backgroundColor); this.frames = new ImageFrameCollection<TPixel>(this, width, height, backgroundColor);
} }
/// <summary> /// <summary>
@ -137,7 +139,7 @@ namespace SixLabors.ImageSharp
internal Image(Configuration configuration, ImageMetadata metadata, IEnumerable<ImageFrame<TPixel>> frames) internal Image(Configuration configuration, ImageMetadata metadata, IEnumerable<ImageFrame<TPixel>> frames)
: base(configuration, PixelTypeInfo.Create<TPixel>(), metadata, ValidateFramesAndGetSize(frames)) : base(configuration, PixelTypeInfo.Create<TPixel>(), metadata, ValidateFramesAndGetSize(frames))
{ {
this.Frames = new ImageFrameCollection<TPixel>(this, frames); this.frames = new ImageFrameCollection<TPixel>(this, frames);
} }
/// <inheritdoc /> /// <inheritdoc />
@ -146,7 +148,14 @@ namespace SixLabors.ImageSharp
/// <summary> /// <summary>
/// Gets the collection of image frames. /// Gets the collection of image frames.
/// </summary> /// </summary>
public new ImageFrameCollection<TPixel> Frames { get; } public new ImageFrameCollection<TPixel> Frames
{
get
{
this.EnsureNotDisposed();
return this.frames;
}
}
/// <summary> /// <summary>
/// Gets the root frame. /// Gets the root frame.

Loading…
Cancel
Save