Browse Source

minor code cleanup

pull/693/head
Anton Firszov 8 years ago
parent
commit
34c0bbeee5
  1. 58
      src/ImageSharp/Formats/IImageFormat.cs
  2. 14
      src/ImageSharp/MetaData/ImageFrameMetaData.cs
  3. 10
      src/ImageSharp/MetaData/ImageMetaData.cs

58
src/ImageSharp/Formats/IImageFormat.cs

@ -6,26 +6,36 @@ using System.Collections.Generic;
namespace SixLabors.ImageSharp.Formats
{
/// <summary>
/// Defines the contract for an image format containing metadata with multiple frames.
/// Defines the contract for an image format.
/// </summary>
/// <typeparam name="TFormatMetaData">The type of format metadata.</typeparam>
/// <typeparam name="TFormatFrameMetaData">The type of format frame metadata.</typeparam>
public interface IImageFormat<TFormatMetaData, TFormatFrameMetaData> : IImageFormat<TFormatMetaData>
where TFormatMetaData : class
where TFormatFrameMetaData : class
public interface IImageFormat
{
/// <summary>
/// Creates a default instance of the format frame metadata.
/// Gets the name that describes this image format.
/// </summary>
/// <returns>The <typeparamref name="TFormatFrameMetaData"/>.</returns>
TFormatFrameMetaData CreateDefaultFormatFrameMetaData();
string Name { get; }
/// <summary>
/// Gets the default mimetype that the image foramt uses
/// </summary>
string DefaultMimeType { get; }
/// <summary>
/// Gets all the mimetypes that have been used by this image foramt.
/// </summary>
IEnumerable<string> MimeTypes { get; }
/// <summary>
/// Gets the file extensions this image format commonly uses.
/// </summary>
IEnumerable<string> FileExtensions { get; }
}
/// <summary>
/// Defines the contract for an image format containing metadata.
/// </summary>
/// <typeparam name="TFormatMetaData">The type of format metadata.</typeparam>
public interface IImageFormat<TFormatMetaData> : IImageFormat
public interface IImageFormat<out TFormatMetaData> : IImageFormat
where TFormatMetaData : class
{
/// <summary>
@ -36,28 +46,18 @@ namespace SixLabors.ImageSharp.Formats
}
/// <summary>
/// Defines the contract for an image format.
/// Defines the contract for an image format containing metadata with multiple frames.
/// </summary>
public interface IImageFormat
/// <typeparam name="TFormatMetaData">The type of format metadata.</typeparam>
/// <typeparam name="TFormatFrameMetaData">The type of format frame metadata.</typeparam>
public interface IImageFormat<out TFormatMetaData, out TFormatFrameMetaData> : IImageFormat<TFormatMetaData>
where TFormatMetaData : class
where TFormatFrameMetaData : class
{
/// <summary>
/// Gets the name that describes this image format.
/// </summary>
string Name { get; }
/// <summary>
/// Gets the default mimetype that the image foramt uses
/// </summary>
string DefaultMimeType { get; }
/// <summary>
/// Gets all the mimetypes that have been used by this image foramt.
/// </summary>
IEnumerable<string> MimeTypes { get; }
/// <summary>
/// Gets the file extensions this image format commonly uses.
/// Creates a default instance of the format frame metadata.
/// </summary>
IEnumerable<string> FileExtensions { get; }
/// <returns>The <typeparamref name="TFormatFrameMetaData"/>.</returns>
TFormatFrameMetaData CreateDefaultFormatFrameMetaData();
}
}

14
src/ImageSharp/MetaData/ImageFrameMetaData.cs

@ -12,7 +12,7 @@ namespace SixLabors.ImageSharp.MetaData
/// </summary>
public sealed class ImageFrameMetaData
{
private readonly Dictionary<IImageFormat, object> metaData = new Dictionary<IImageFormat, object>();
private readonly Dictionary<IImageFormat, object> formatMetaData = new Dictionary<IImageFormat, object>();
/// <summary>
/// Initializes a new instance of the <see cref="ImageFrameMetaData"/> class.
@ -32,9 +32,9 @@ namespace SixLabors.ImageSharp.MetaData
{
DebugGuard.NotNull(other, nameof(other));
foreach (KeyValuePair<IImageFormat, object> meta in other.metaData)
foreach (KeyValuePair<IImageFormat, object> meta in other.formatMetaData)
{
this.metaData.Add(meta.Key, meta.Value);
this.formatMetaData.Add(meta.Key, meta.Value);
}
}
@ -54,13 +54,15 @@ namespace SixLabors.ImageSharp.MetaData
/// <exception cref="ArgumentNullException">key is null.</exception>
/// <exception cref="ArgumentNullException">value is null.</exception>
/// <exception cref="ArgumentException">An element with the same key already exists in the <see cref="ImageMetaData"/>.</exception>
public void AddOrUpdateFormatMetaData<TFormatMetaData, TFormatFrameMetaData>(IImageFormat<TFormatMetaData, TFormatFrameMetaData> key, TFormatFrameMetaData value)
public void AddOrUpdateFormatMetaData<TFormatMetaData, TFormatFrameMetaData>(
IImageFormat<TFormatMetaData, TFormatFrameMetaData> key,
TFormatFrameMetaData value)
where TFormatMetaData : class
where TFormatFrameMetaData : class
{
// Don't think this needs to be threadsafe.
Guard.NotNull(value, nameof(value));
this.metaData[key] = value;
this.formatMetaData[key] = value;
}
/// <summary>
@ -76,7 +78,7 @@ namespace SixLabors.ImageSharp.MetaData
where TFormatMetaData : class
where TFormatFrameMetaData : class
{
if (this.metaData.TryGetValue(key, out object meta))
if (this.formatMetaData.TryGetValue(key, out object meta))
{
return (TFormatFrameMetaData)meta;
}

10
src/ImageSharp/MetaData/ImageMetaData.cs

@ -26,7 +26,7 @@ namespace SixLabors.ImageSharp.MetaData
/// </summary>
public const double DefaultVerticalResolution = 96;
private readonly Dictionary<IImageFormat, object> metaData = new Dictionary<IImageFormat, object>();
private readonly Dictionary<IImageFormat, object> formatMetaData = new Dictionary<IImageFormat, object>();
private double horizontalResolution;
private double verticalResolution;
@ -52,9 +52,9 @@ namespace SixLabors.ImageSharp.MetaData
this.VerticalResolution = other.VerticalResolution;
this.ResolutionUnits = other.ResolutionUnits;
foreach (KeyValuePair<IImageFormat, object> meta in other.metaData)
foreach (KeyValuePair<IImageFormat, object> meta in other.formatMetaData)
{
this.metaData.Add(meta.Key, meta.Value);
this.formatMetaData.Add(meta.Key, meta.Value);
}
foreach (ImageProperty property in other.Properties)
@ -145,7 +145,7 @@ namespace SixLabors.ImageSharp.MetaData
{
// Don't think this needs to be threadsafe.
Guard.NotNull(value, nameof(value));
this.metaData[key] = value;
this.formatMetaData[key] = value;
}
/// <summary>
@ -159,7 +159,7 @@ namespace SixLabors.ImageSharp.MetaData
public TFormatMetaData GetOrAddFormatMetaData<TFormatMetaData>(IImageFormat<TFormatMetaData> key)
where TFormatMetaData : class
{
if (this.metaData.TryGetValue(key, out object meta))
if (this.formatMetaData.TryGetValue(key, out object meta))
{
return (TFormatMetaData)meta;
}

Loading…
Cancel
Save