From 1b24cf12c3ff54998d2bda1648e40accaf8d9121 Mon Sep 17 00:00:00 2001 From: Scott Williams Date: Mon, 2 Jan 2017 10:12:01 +0000 Subject: [PATCH] move to static method --- src/ImageSharp/Configuration.cs | 42 ++++++++------------ tests/ImageSharp.Tests/ConfigurationTests.cs | 2 +- 2 files changed, 18 insertions(+), 26 deletions(-) diff --git a/src/ImageSharp/Configuration.cs b/src/ImageSharp/Configuration.cs index d339042d00..18ba49e4c1 100644 --- a/src/ImageSharp/Configuration.cs +++ b/src/ImageSharp/Configuration.cs @@ -21,7 +21,7 @@ namespace ImageSharp /// /// A lazily initialized configuration default instance. /// - private static readonly Lazy Lazy = new Lazy(() => new Configuration(true)); + private static readonly Lazy Lazy = new Lazy(() => CreateDefaultInstance()); /// /// An object that can be used to synchronize access to the . @@ -33,30 +33,6 @@ namespace ImageSharp /// private readonly List imageFormatsList = new List(); - /// - /// Initializes a new instance of the class. - /// - public Configuration() - : this(false) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// if set to true [autoload wellknown formats]. - internal Configuration(bool autoloadWellknownFormats) - { - if (autoloadWellknownFormats) - { - // lets try auto loading the known image formats - this.TryAddImageFormat("ImageSharp.Formats.PngFormat, ImageSharp.Formats.Png"); - this.TryAddImageFormat("ImageSharp.Formats.JpegFormat, ImageSharp.Formats.Jpeg"); - this.TryAddImageFormat("ImageSharp.Formats.GifFormat, ImageSharp.Formats.Gif"); - this.TryAddImageFormat("ImageSharp.Formats.BmpFormat, ImageSharp.Formats.Bmp"); - } - } - /// /// Gets the default instance. /// @@ -93,6 +69,22 @@ namespace ImageSharp this.AddImageFormatLocked(format); } + /// + /// Creates the default instance, with Png, Jpeg, Gif and Bmp preregisterd (if they have been referenced) + /// + /// The default configuration of + internal static Configuration CreateDefaultInstance() + { + Configuration config = new Configuration(); + + // lets try auto loading the known image formats + config.TryAddImageFormat("ImageSharp.Formats.PngFormat, ImageSharp.Formats.Png"); + config.TryAddImageFormat("ImageSharp.Formats.JpegFormat, ImageSharp.Formats.Jpeg"); + config.TryAddImageFormat("ImageSharp.Formats.GifFormat, ImageSharp.Formats.Gif"); + config.TryAddImageFormat("ImageSharp.Formats.BmpFormat, ImageSharp.Formats.Bmp"); + return config; + } + /// /// Tries the add image format. /// diff --git a/tests/ImageSharp.Tests/ConfigurationTests.cs b/tests/ImageSharp.Tests/ConfigurationTests.cs index d1618fd187..883d235673 100644 --- a/tests/ImageSharp.Tests/ConfigurationTests.cs +++ b/tests/ImageSharp.Tests/ConfigurationTests.cs @@ -21,7 +21,7 @@ namespace ImageSharp.Tests [Fact] public void IfAutoloadWellknwonFormatesIsTrueAllFormateAreLoaded() { - var configuration = new Configuration(true); + var configuration = Configuration.CreateDefaultInstance(); Assert.Equal(4, configuration.ImageFormats.Count); }