From 01d2f42cdd823225eca69658825a1f278392f55c Mon Sep 17 00:00:00 2001 From: Dirk Lemstra Date: Sun, 19 Feb 2017 15:01:44 +0100 Subject: [PATCH] Nicer initialization of the options. --- src/ImageSharp.Formats.Gif/GifDecoderOptions.cs | 9 +-------- src/ImageSharp.Formats.Png/PngDecoderOptions.cs | 9 +-------- src/ImageSharp/Formats/DecoderOptions.cs | 15 +++------------ src/ImageSharp/Formats/EncoderOptions.cs | 15 +++------------ 4 files changed, 8 insertions(+), 40 deletions(-) diff --git a/src/ImageSharp.Formats.Gif/GifDecoderOptions.cs b/src/ImageSharp.Formats.Gif/GifDecoderOptions.cs index e2506db708..ff8ad19df8 100644 --- a/src/ImageSharp.Formats.Gif/GifDecoderOptions.cs +++ b/src/ImageSharp.Formats.Gif/GifDecoderOptions.cs @@ -19,7 +19,6 @@ namespace ImageSharp.Formats /// public GifDecoderOptions() { - this.InitializeWithDefaults(); } /// @@ -29,13 +28,12 @@ namespace ImageSharp.Formats private GifDecoderOptions(IDecoderOptions options) : base(options) { - this.InitializeWithDefaults(); } /// /// Gets or sets the encoding that should be used when reading comments. /// - public Encoding TextEncoding { get; set; } + public Encoding TextEncoding { get; set; } = DefaultEncoding; /// /// Converts the options to a instance with a cast @@ -53,10 +51,5 @@ namespace ImageSharp.Formats return new GifDecoderOptions(options); } - - private void InitializeWithDefaults() - { - this.TextEncoding = DefaultEncoding; - } } } diff --git a/src/ImageSharp.Formats.Png/PngDecoderOptions.cs b/src/ImageSharp.Formats.Png/PngDecoderOptions.cs index 07c0c2739e..8630cd1b09 100644 --- a/src/ImageSharp.Formats.Png/PngDecoderOptions.cs +++ b/src/ImageSharp.Formats.Png/PngDecoderOptions.cs @@ -19,7 +19,6 @@ namespace ImageSharp.Formats /// public PngDecoderOptions() { - this.InitializeWithDefaults(); } /// @@ -29,13 +28,12 @@ namespace ImageSharp.Formats private PngDecoderOptions(IDecoderOptions options) : base(options) { - this.InitializeWithDefaults(); } /// /// Gets or sets the encoding that should be used when reading text chunks. /// - public Encoding TextEncoding { get; set; } + public Encoding TextEncoding { get; set; } = DefaultEncoding; /// /// Converts the options to a instance with a cast @@ -53,10 +51,5 @@ namespace ImageSharp.Formats return new PngDecoderOptions(options); } - - private void InitializeWithDefaults() - { - this.TextEncoding = DefaultEncoding; - } } } diff --git a/src/ImageSharp/Formats/DecoderOptions.cs b/src/ImageSharp/Formats/DecoderOptions.cs index 4755ddcb66..5257b07b39 100644 --- a/src/ImageSharp/Formats/DecoderOptions.cs +++ b/src/ImageSharp/Formats/DecoderOptions.cs @@ -15,7 +15,6 @@ namespace ImageSharp /// public DecoderOptions() { - this.InitializeWithDefaults(); } /// @@ -24,23 +23,15 @@ namespace ImageSharp /// The decoder options protected DecoderOptions(IDecoderOptions options) { - if (options == null) + if (options != null) { - this.InitializeWithDefaults(); - return; + this.IgnoreMetadata = options.IgnoreMetadata; } - - this.IgnoreMetadata = options.IgnoreMetadata; } /// /// Gets or sets a value indicating whether the metadata should be ignored when the image is being decoded. /// - public bool IgnoreMetadata { get; set; } - - private void InitializeWithDefaults() - { - this.IgnoreMetadata = false; - } + public bool IgnoreMetadata { get; set; } = false; } } diff --git a/src/ImageSharp/Formats/EncoderOptions.cs b/src/ImageSharp/Formats/EncoderOptions.cs index 1f92927f14..27a7e9781d 100644 --- a/src/ImageSharp/Formats/EncoderOptions.cs +++ b/src/ImageSharp/Formats/EncoderOptions.cs @@ -15,7 +15,6 @@ namespace ImageSharp /// public EncoderOptions() { - this.InitializeWithDefaults(); } /// @@ -24,23 +23,15 @@ namespace ImageSharp /// The encoder options protected EncoderOptions(IEncoderOptions options) { - if (options == null) + if (options != null) { - this.InitializeWithDefaults(); - return; + this.IgnoreMetadata = options.IgnoreMetadata; } - - this.IgnoreMetadata = options.IgnoreMetadata; } /// /// Gets or sets a value indicating whether the metadata should be ignored when the image is being encoded. /// - public bool IgnoreMetadata { get; set; } - - private void InitializeWithDefaults() - { - this.IgnoreMetadata = false; - } + public bool IgnoreMetadata { get; set; } = false; } }