From 34c0bbeee50c8fb43b610f6191848394214f5ea5 Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Tue, 11 Sep 2018 00:31:35 +0200 Subject: [PATCH] minor code cleanup --- src/ImageSharp/Formats/IImageFormat.cs | 58 +++++++++---------- src/ImageSharp/MetaData/ImageFrameMetaData.cs | 14 +++-- src/ImageSharp/MetaData/ImageMetaData.cs | 10 ++-- 3 files changed, 42 insertions(+), 40 deletions(-) diff --git a/src/ImageSharp/Formats/IImageFormat.cs b/src/ImageSharp/Formats/IImageFormat.cs index 9720352750..94191c1493 100644 --- a/src/ImageSharp/Formats/IImageFormat.cs +++ b/src/ImageSharp/Formats/IImageFormat.cs @@ -6,26 +6,36 @@ using System.Collections.Generic; namespace SixLabors.ImageSharp.Formats { /// - /// Defines the contract for an image format containing metadata with multiple frames. + /// Defines the contract for an image format. /// - /// The type of format metadata. - /// The type of format frame metadata. - public interface IImageFormat : IImageFormat - where TFormatMetaData : class - where TFormatFrameMetaData : class + public interface IImageFormat { /// - /// Creates a default instance of the format frame metadata. + /// Gets the name that describes this image format. /// - /// The . - TFormatFrameMetaData CreateDefaultFormatFrameMetaData(); + string Name { get; } + + /// + /// Gets the default mimetype that the image foramt uses + /// + string DefaultMimeType { get; } + + /// + /// Gets all the mimetypes that have been used by this image foramt. + /// + IEnumerable MimeTypes { get; } + + /// + /// Gets the file extensions this image format commonly uses. + /// + IEnumerable FileExtensions { get; } } /// /// Defines the contract for an image format containing metadata. /// /// The type of format metadata. - public interface IImageFormat : IImageFormat + public interface IImageFormat : IImageFormat where TFormatMetaData : class { /// @@ -36,28 +46,18 @@ namespace SixLabors.ImageSharp.Formats } /// - /// Defines the contract for an image format. + /// Defines the contract for an image format containing metadata with multiple frames. /// - public interface IImageFormat + /// The type of format metadata. + /// The type of format frame metadata. + public interface IImageFormat : IImageFormat + where TFormatMetaData : class + where TFormatFrameMetaData : class { /// - /// Gets the name that describes this image format. - /// - string Name { get; } - - /// - /// Gets the default mimetype that the image foramt uses - /// - string DefaultMimeType { get; } - - /// - /// Gets all the mimetypes that have been used by this image foramt. - /// - IEnumerable MimeTypes { get; } - - /// - /// Gets the file extensions this image format commonly uses. + /// Creates a default instance of the format frame metadata. /// - IEnumerable FileExtensions { get; } + /// The . + TFormatFrameMetaData CreateDefaultFormatFrameMetaData(); } } \ No newline at end of file diff --git a/src/ImageSharp/MetaData/ImageFrameMetaData.cs b/src/ImageSharp/MetaData/ImageFrameMetaData.cs index 07d4bdb05e..908a0e6246 100644 --- a/src/ImageSharp/MetaData/ImageFrameMetaData.cs +++ b/src/ImageSharp/MetaData/ImageFrameMetaData.cs @@ -12,7 +12,7 @@ namespace SixLabors.ImageSharp.MetaData /// public sealed class ImageFrameMetaData { - private readonly Dictionary metaData = new Dictionary(); + private readonly Dictionary formatMetaData = new Dictionary(); /// /// Initializes a new instance of the class. @@ -32,9 +32,9 @@ namespace SixLabors.ImageSharp.MetaData { DebugGuard.NotNull(other, nameof(other)); - foreach (KeyValuePair meta in other.metaData) + foreach (KeyValuePair 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 /// key is null. /// value is null. /// An element with the same key already exists in the . - public void AddOrUpdateFormatMetaData(IImageFormat key, TFormatFrameMetaData value) + public void AddOrUpdateFormatMetaData( + IImageFormat 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; } /// @@ -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; } diff --git a/src/ImageSharp/MetaData/ImageMetaData.cs b/src/ImageSharp/MetaData/ImageMetaData.cs index aa084728ca..74c00cf8a5 100644 --- a/src/ImageSharp/MetaData/ImageMetaData.cs +++ b/src/ImageSharp/MetaData/ImageMetaData.cs @@ -26,7 +26,7 @@ namespace SixLabors.ImageSharp.MetaData /// public const double DefaultVerticalResolution = 96; - private readonly Dictionary metaData = new Dictionary(); + private readonly Dictionary formatMetaData = new Dictionary(); private double horizontalResolution; private double verticalResolution; @@ -52,9 +52,9 @@ namespace SixLabors.ImageSharp.MetaData this.VerticalResolution = other.VerticalResolution; this.ResolutionUnits = other.ResolutionUnits; - foreach (KeyValuePair meta in other.metaData) + foreach (KeyValuePair 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; } /// @@ -159,7 +159,7 @@ namespace SixLabors.ImageSharp.MetaData public TFormatMetaData GetOrAddFormatMetaData(IImageFormat key) where TFormatMetaData : class { - if (this.metaData.TryGetValue(key, out object meta)) + if (this.formatMetaData.TryGetValue(key, out object meta)) { return (TFormatMetaData)meta; }