Browse Source

replaced Configuration copy constructor with a ShallowCopy method.

af/merge-core
Vicente Penades 8 years ago
parent
commit
ce62a947d9
  1. 42
      src/ImageSharp/Configuration.cs
  2. 6
      tests/ImageSharp.Tests/ConfigurationTests.cs

42
src/ImageSharp/Configuration.cs

@ -33,24 +33,6 @@ namespace SixLabors.ImageSharp
{
}
/// <summary>
/// Initializes a new instance of the <see cref="Configuration"/> class.
/// </summary>
/// <param name="configuration">A configuration instance to be copied</param>
public Configuration(Configuration configuration)
{
this.ParallelOptions = configuration.ParallelOptions;
this.ImageFormatsManager = configuration.ImageFormatsManager;
this.MemoryManager = configuration.MemoryManager;
this.ImageOperationsProvider = configuration.ImageOperationsProvider;
#if !NETSTANDARD1_1
this.FileSystem = configuration.FileSystem;
#endif
this.ReadOrigin = configuration.ReadOrigin;
}
/// <summary>
/// Initializes a new instance of the <see cref="Configuration" /> class.
/// </summary>
@ -74,7 +56,7 @@ namespace SixLabors.ImageSharp
/// <summary>
/// Gets the global parallel options for processing tasks in parallel.
/// </summary>
public ParallelOptions ParallelOptions { get; } = new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount };
public ParallelOptions ParallelOptions { get; private set; } = new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount };
/// <summary>
/// Gets the currently registered <see cref="IImageFormat"/>s.
@ -138,6 +120,28 @@ namespace SixLabors.ImageSharp
configuration.Configure(this);
}
/// <summary>
/// Creates a shallow copy of the <see cref="Configuration"/>
/// </summary>
/// <returns>A new configuration instance</returns>
public Configuration ShallowCopy()
{
Configuration cfg = new Configuration();
cfg.ParallelOptions = this.ParallelOptions;
cfg.ImageFormatsManager = this.ImageFormatsManager;
cfg.MemoryManager = this.MemoryManager;
cfg.ImageOperationsProvider = this.ImageOperationsProvider;
#if !NETSTANDARD1_1
cfg.FileSystem = this.FileSystem;
#endif
cfg.ReadOrigin = this.ReadOrigin;
return cfg;
}
/// <summary>
/// Registers a new format provider.
/// </summary>

6
tests/ImageSharp.Tests/ConfigurationTests.cs

@ -22,8 +22,10 @@ namespace SixLabors.ImageSharp.Tests
public Configuration DefaultConfiguration { get; private set; }
public ConfigurationTests()
{
this.DefaultConfiguration = Configuration.CreateDefaultInstance();
{
// the shallow copy of configuration should behave exactly like the default configuration,
// so by using the copy, we test both the default and the copy.
this.DefaultConfiguration = Configuration.CreateDefaultInstance().ShallowCopy();
this.ConfigurationEmpty = new Configuration();
}

Loading…
Cancel
Save