diff --git a/src/ImageSharp/Bootstrapper.cs b/src/ImageSharp/Bootstrapper.cs
index a30d206b0..d970f6e55 100644
--- a/src/ImageSharp/Bootstrapper.cs
+++ b/src/ImageSharp/Bootstrapper.cs
@@ -16,63 +16,48 @@ namespace ImageSharp
///
/// Provides initialization code which allows extending the library.
///
- public class Bootstrapper
+ public static class Bootstrapper
{
- ///
- /// A singleton of the class.
- ///
- private static readonly Bootstrapper Instance = new Bootstrapper();
-
///
/// The list of supported .
///
- private readonly List imageFormats;
-
- ///
- /// The parallel options for processing tasks in parallel.
- ///
- private readonly ParallelOptions parallelOptions;
+ private static readonly List ImageFormatsList;
///
/// An object that can be used to synchronize access to the .
///
- private readonly object syncRoot = new object();
-
- ///
- /// The maximum header size of all formats.
- ///
- private int maxHeaderSize;
+ private static readonly object SyncRoot = new object();
///
- /// Prevents a default instance of the class from being created.
+ /// Initializes static members of the class.
///
- private Bootstrapper()
+ static Bootstrapper()
{
- this.imageFormats = new List
+ ImageFormatsList = new List
{
new BmpFormat(),
new JpegFormat(),
new PngFormat(),
new GifFormat()
};
- this.SetMaxHeaderSize();
- this.parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount };
+ SetMaxHeaderSize();
+ ParallelOptions = new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount };
}
///
/// Gets the collection of supported
///
- public static IReadOnlyCollection ImageFormats => new ReadOnlyCollection(Instance.imageFormats);
+ public static IReadOnlyCollection ImageFormats => new ReadOnlyCollection(ImageFormatsList);
///
/// Gets the global parallel options for processing tasks in parallel.
///
- public static ParallelOptions ParallelOptions => Instance.parallelOptions;
+ public static ParallelOptions ParallelOptions { get; }
///
/// Gets the maximum header size of all formats.
///
- internal static int MaxHeaderSize => Instance.maxHeaderSize;
+ internal static int MaxHeaderSize { get; private set; }
///
/// Adds a new to the collection of supported image formats.
@@ -87,22 +72,22 @@ namespace ImageSharp
Guard.NotNullOrEmpty(format.Extension, nameof(format), "The extension should not be null or empty.");
Guard.NotNullOrEmpty(format.SupportedExtensions, nameof(format), "The supported extensions not be null or empty.");
- Instance.AddImageFormatLocked(format);
+ AddImageFormatLocked(format);
}
- private void AddImageFormatLocked(IImageFormat format)
+ private static void AddImageFormatLocked(IImageFormat format)
{
- lock (this.syncRoot)
+ lock (SyncRoot)
{
- this.GuardDuplicate(format);
+ GuardDuplicate(format);
- this.imageFormats.Add(format);
+ ImageFormatsList.Add(format);
- this.SetMaxHeaderSize();
+ SetMaxHeaderSize();
}
}
- private void GuardDuplicate(IImageFormat format)
+ private static void GuardDuplicate(IImageFormat format)
{
if (!format.SupportedExtensions.Contains(format.Extension, StringComparer.OrdinalIgnoreCase))
{
@@ -114,7 +99,7 @@ namespace ImageSharp
throw new ArgumentException("The supported extensions should not contain empty values.", nameof(format));
}
- foreach (var imageFormat in this.imageFormats)
+ foreach (var imageFormat in ImageFormatsList)
{
if (imageFormat.Extension.Equals(format.Extension, StringComparison.OrdinalIgnoreCase))
{
@@ -128,9 +113,9 @@ namespace ImageSharp
}
}
- private void SetMaxHeaderSize()
+ private static void SetMaxHeaderSize()
{
- this.maxHeaderSize = imageFormats.Max(x => x.HeaderSize);
+ MaxHeaderSize = ImageFormatsList.Max(x => x.HeaderSize);
}
}
}