Browse Source

minor code cleanup

af/merge-core
Anton Firszov 8 years ago
parent
commit
d46e275072
  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 namespace SixLabors.ImageSharp.Formats
{ {
/// <summary> /// <summary>
/// Defines the contract for an image format containing metadata with multiple frames. /// Defines the contract for an image format.
/// </summary> /// </summary>
/// <typeparam name="TFormatMetaData">The type of format metadata.</typeparam> public interface IImageFormat
/// <typeparam name="TFormatFrameMetaData">The type of format frame metadata.</typeparam>
public interface IImageFormat<TFormatMetaData, TFormatFrameMetaData> : IImageFormat<TFormatMetaData>
where TFormatMetaData : class
where TFormatFrameMetaData : class
{ {
/// <summary> /// <summary>
/// Creates a default instance of the format frame metadata. /// Gets the name that describes this image format.
/// </summary> /// </summary>
/// <returns>The <typeparamref name="TFormatFrameMetaData"/>.</returns> string Name { get; }
TFormatFrameMetaData CreateDefaultFormatFrameMetaData();
/// <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> /// <summary>
/// Defines the contract for an image format containing metadata. /// Defines the contract for an image format containing metadata.
/// </summary> /// </summary>
/// <typeparam name="TFormatMetaData">The type of format metadata.</typeparam> /// <typeparam name="TFormatMetaData">The type of format metadata.</typeparam>
public interface IImageFormat<TFormatMetaData> : IImageFormat public interface IImageFormat<out TFormatMetaData> : IImageFormat
where TFormatMetaData : class where TFormatMetaData : class
{ {
/// <summary> /// <summary>
@ -36,28 +46,18 @@ namespace SixLabors.ImageSharp.Formats
} }
/// <summary> /// <summary>
/// Defines the contract for an image format. /// Defines the contract for an image format containing metadata with multiple frames.
/// </summary> /// </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> /// <summary>
/// Gets the name that describes this image format. /// Creates a default instance of the format frame metadata.
/// </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.
/// </summary> /// </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> /// </summary>
public sealed class ImageFrameMetaData 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> /// <summary>
/// Initializes a new instance of the <see cref="ImageFrameMetaData"/> class. /// Initializes a new instance of the <see cref="ImageFrameMetaData"/> class.
@ -32,9 +32,9 @@ namespace SixLabors.ImageSharp.MetaData
{ {
DebugGuard.NotNull(other, nameof(other)); 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">key is null.</exception>
/// <exception cref="ArgumentNullException">value 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> /// <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 TFormatMetaData : class
where TFormatFrameMetaData : class where TFormatFrameMetaData : class
{ {
// Don't think this needs to be threadsafe. // Don't think this needs to be threadsafe.
Guard.NotNull(value, nameof(value)); Guard.NotNull(value, nameof(value));
this.metaData[key] = value; this.formatMetaData[key] = value;
} }
/// <summary> /// <summary>
@ -76,7 +78,7 @@ namespace SixLabors.ImageSharp.MetaData
where TFormatMetaData : class where TFormatMetaData : class
where TFormatFrameMetaData : class where TFormatFrameMetaData : class
{ {
if (this.metaData.TryGetValue(key, out object meta)) if (this.formatMetaData.TryGetValue(key, out object meta))
{ {
return (TFormatFrameMetaData)meta; return (TFormatFrameMetaData)meta;
} }

10
src/ImageSharp/MetaData/ImageMetaData.cs

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

Loading…
Cancel
Save