Browse Source

Remove Nullable disable from MetaData.Profiles

#2231
pull/2330/head
Stefan Nikolei 3 years ago
parent
commit
5078f1e1df
  1. 3
      src/ImageSharp/Formats/Gif/MetadataExtensions.cs
  2. 15
      src/ImageSharp/Metadata/ImageFrameMetadata.cs
  3. 20
      src/ImageSharp/Metadata/Profiles/IPTC/IptcProfile.cs
  4. 10
      src/ImageSharp/Metadata/Profiles/IPTC/IptcValue.cs
  5. 13
      src/ImageSharp/Metadata/Profiles/XMP/XmpProfile.cs

3
src/ImageSharp/Formats/Gif/MetadataExtensions.cs

@ -1,6 +1,7 @@
// Copyright (c) Six Labors. // Copyright (c) Six Labors.
// Licensed under the Six Labors Split License. // Licensed under the Six Labors Split License.
using System.Diagnostics.CodeAnalysis;
using SixLabors.ImageSharp.Formats.Gif; using SixLabors.ImageSharp.Formats.Gif;
using SixLabors.ImageSharp.Metadata; using SixLabors.ImageSharp.Metadata;
@ -37,5 +38,5 @@ public static partial class MetadataExtensions
/// <returns> /// <returns>
/// <see langword="true"/> if the gif frame metadata exists; otherwise, <see langword="false"/>. /// <see langword="true"/> if the gif frame metadata exists; otherwise, <see langword="false"/>.
/// </returns> /// </returns>
public static bool TryGetGifMetadata(this ImageFrameMetadata source, out GifFrameMetadata metadata) => source.TryGetFormatMetadata(GifFormat.Instance, out metadata); public static bool TryGetGifMetadata(this ImageFrameMetadata source, [NotNullWhen(true)] out GifFrameMetadata? metadata) => source.TryGetFormatMetadata(GifFormat.Instance, out metadata);
} }

15
src/ImageSharp/Metadata/ImageFrameMetadata.cs

@ -1,6 +1,5 @@
// Copyright (c) Six Labors. // Copyright (c) Six Labors.
// Licensed under the Six Labors Split License. // Licensed under the Six Labors Split License.
#nullable disable
using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.Metadata.Profiles.Exif; using SixLabors.ImageSharp.Metadata.Profiles.Exif;
@ -49,22 +48,22 @@ public sealed class ImageFrameMetadata : IDeepCloneable<ImageFrameMetadata>
/// <summary> /// <summary>
/// Gets or sets the Exif profile. /// Gets or sets the Exif profile.
/// </summary> /// </summary>
public ExifProfile ExifProfile { get; set; } public ExifProfile? ExifProfile { get; set; }
/// <summary> /// <summary>
/// Gets or sets the XMP profile. /// Gets or sets the XMP profile.
/// </summary> /// </summary>
public XmpProfile XmpProfile { get; set; } public XmpProfile? XmpProfile { get; set; }
/// <summary> /// <summary>
/// Gets or sets the ICC profile. /// Gets or sets the ICC profile.
/// </summary> /// </summary>
public IccProfile IccProfile { get; set; } public IccProfile? IccProfile { get; set; }
/// <summary> /// <summary>
/// Gets or sets the iptc profile. /// Gets or sets the iptc profile.
/// </summary> /// </summary>
public IptcProfile IptcProfile { get; set; } public IptcProfile? IptcProfile { get; set; }
/// <inheritdoc/> /// <inheritdoc/>
public ImageFrameMetadata DeepClone() => new(this); public ImageFrameMetadata DeepClone() => new(this);
@ -83,7 +82,7 @@ public sealed class ImageFrameMetadata : IDeepCloneable<ImageFrameMetadata>
where TFormatMetadata : class where TFormatMetadata : class
where TFormatFrameMetadata : class, IDeepCloneable where TFormatFrameMetadata : class, IDeepCloneable
{ {
if (this.formatMetadata.TryGetValue(key, out IDeepCloneable meta)) if (this.formatMetadata.TryGetValue(key, out IDeepCloneable? meta))
{ {
return (TFormatFrameMetadata)meta; return (TFormatFrameMetadata)meta;
} }
@ -107,11 +106,11 @@ public sealed class ImageFrameMetadata : IDeepCloneable<ImageFrameMetadata>
/// <returns> /// <returns>
/// <see langword="true"/> if the frame metadata exists for the specified key; otherwise, <see langword="false"/>. /// <see langword="true"/> if the frame metadata exists for the specified key; otherwise, <see langword="false"/>.
/// </returns> /// </returns>
public bool TryGetFormatMetadata<TFormatMetadata, TFormatFrameMetadata>(IImageFormat<TFormatMetadata, TFormatFrameMetadata> key, out TFormatFrameMetadata metadata) public bool TryGetFormatMetadata<TFormatMetadata, TFormatFrameMetadata>(IImageFormat<TFormatMetadata, TFormatFrameMetadata> key, out TFormatFrameMetadata? metadata)
where TFormatMetadata : class where TFormatMetadata : class
where TFormatFrameMetadata : class, IDeepCloneable where TFormatFrameMetadata : class, IDeepCloneable
{ {
if (this.formatMetadata.TryGetValue(key, out IDeepCloneable meta)) if (this.formatMetadata.TryGetValue(key, out IDeepCloneable? meta))
{ {
metadata = (TFormatFrameMetadata)meta; metadata = (TFormatFrameMetadata)meta;
return true; return true;

20
src/ImageSharp/Metadata/Profiles/IPTC/IptcProfile.cs

@ -1,9 +1,9 @@
// Copyright (c) Six Labors. // Copyright (c) Six Labors.
// Licensed under the Six Labors Split License. // Licensed under the Six Labors Split License.
#nullable disable
using System.Buffers.Binary; using System.Buffers.Binary;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Diagnostics.CodeAnalysis;
using System.Globalization; using System.Globalization;
using System.Text; using System.Text;
using SixLabors.ImageSharp.Metadata.Profiles.IPTC; using SixLabors.ImageSharp.Metadata.Profiles.IPTC;
@ -30,7 +30,7 @@ public sealed class IptcProfile : IDeepCloneable<IptcProfile>
/// Initializes a new instance of the <see cref="IptcProfile"/> class. /// Initializes a new instance of the <see cref="IptcProfile"/> class.
/// </summary> /// </summary>
public IptcProfile() public IptcProfile()
: this((byte[])null) : this((byte[]?)null)
{ {
} }
@ -38,7 +38,7 @@ public sealed class IptcProfile : IDeepCloneable<IptcProfile>
/// Initializes a new instance of the <see cref="IptcProfile"/> class. /// Initializes a new instance of the <see cref="IptcProfile"/> class.
/// </summary> /// </summary>
/// <param name="data">The byte array to read the iptc profile from.</param> /// <param name="data">The byte array to read the iptc profile from.</param>
public IptcProfile(byte[] data) public IptcProfile(byte[]? data)
{ {
this.Data = data; this.Data = data;
this.Initialize(); this.Initialize();
@ -53,14 +53,11 @@ public sealed class IptcProfile : IDeepCloneable<IptcProfile>
{ {
Guard.NotNull(other, nameof(other)); Guard.NotNull(other, nameof(other));
if (other.values != null) this.values = new Collection<IptcValue>();
{
this.values = new Collection<IptcValue>();
foreach (IptcValue value in other.Values) foreach (IptcValue value in other.Values)
{ {
this.values.Add(value.DeepClone()); this.values.Add(value.DeepClone());
}
} }
if (other.Data != null) if (other.Data != null)
@ -78,7 +75,7 @@ public sealed class IptcProfile : IDeepCloneable<IptcProfile>
/// <summary> /// <summary>
/// Gets the byte data of the IPTC profile. /// Gets the byte data of the IPTC profile.
/// </summary> /// </summary>
public byte[] Data { get; private set; } public byte[]? Data { get; private set; }
/// <summary> /// <summary>
/// Gets the values of this iptc profile. /// Gets the values of this iptc profile.
@ -310,6 +307,7 @@ public sealed class IptcProfile : IDeepCloneable<IptcProfile>
return offset; return offset;
} }
[MemberNotNull(nameof(values))]
private void Initialize() private void Initialize()
{ {
if (this.values != null) if (this.values != null)

10
src/ImageSharp/Metadata/Profiles/IPTC/IptcValue.cs

@ -1,6 +1,5 @@
// Copyright (c) Six Labors. // Copyright (c) Six Labors.
// Licensed under the Six Labors Split License. // Licensed under the Six Labors Split License.
#nullable disable
using System.Text; using System.Text;
@ -22,10 +21,7 @@ public sealed class IptcValue : IDeepCloneable<IptcValue>
other.data.AsSpan().CopyTo(this.data); other.data.AsSpan().CopyTo(this.data);
} }
if (other.Encoding != null) this.encoding = (Encoding)other.Encoding.Clone();
{
this.Encoding = (Encoding)other.Encoding.Clone();
}
this.Tag = other.Tag; this.Tag = other.Tag;
this.Strict = other.Strict; this.Strict = other.Strict;
@ -133,7 +129,7 @@ public sealed class IptcValue : IDeepCloneable<IptcValue>
/// </summary> /// </summary>
/// <param name="obj">The object to compare this <see cref="IptcValue"/> with.</param> /// <param name="obj">The object to compare this <see cref="IptcValue"/> with.</param>
/// <returns>True when the specified object is equal to the current <see cref="IptcValue"/>.</returns> /// <returns>True when the specified object is equal to the current <see cref="IptcValue"/>.</returns>
public override bool Equals(object obj) public override bool Equals(object? obj)
{ {
if (ReferenceEquals(this, obj)) if (ReferenceEquals(this, obj))
{ {
@ -148,7 +144,7 @@ public sealed class IptcValue : IDeepCloneable<IptcValue>
/// </summary> /// </summary>
/// <param name="other">The iptc value to compare this <see cref="IptcValue"/> with.</param> /// <param name="other">The iptc value to compare this <see cref="IptcValue"/> with.</param>
/// <returns>True when the specified iptc value is equal to the current <see cref="IptcValue"/>.</returns> /// <returns>True when the specified iptc value is equal to the current <see cref="IptcValue"/>.</returns>
public bool Equals(IptcValue other) public bool Equals(IptcValue? other)
{ {
if (other is null) if (other is null)
{ {

13
src/ImageSharp/Metadata/Profiles/XMP/XmpProfile.cs

@ -1,7 +1,7 @@
// Copyright (c) Six Labors. // Copyright (c) Six Labors.
// Licensed under the Six Labors Split License. // Licensed under the Six Labors Split License.
#nullable disable
using System.Diagnostics;
using System.Text; using System.Text;
using System.Xml.Linq; using System.Xml.Linq;
@ -17,7 +17,7 @@ public sealed class XmpProfile : IDeepCloneable<XmpProfile>
/// Initializes a new instance of the <see cref="XmpProfile"/> class. /// Initializes a new instance of the <see cref="XmpProfile"/> class.
/// </summary> /// </summary>
public XmpProfile() public XmpProfile()
: this((byte[])null) : this((byte[]?)null)
{ {
} }
@ -25,7 +25,7 @@ public sealed class XmpProfile : IDeepCloneable<XmpProfile>
/// Initializes a new instance of the <see cref="XmpProfile"/> class. /// Initializes a new instance of the <see cref="XmpProfile"/> class.
/// </summary> /// </summary>
/// <param name="data">The UTF8 encoded byte array to read the XMP profile from.</param> /// <param name="data">The UTF8 encoded byte array to read the XMP profile from.</param>
public XmpProfile(byte[] data) => this.Data = data; public XmpProfile(byte[]? data) => this.Data = data;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="XmpProfile"/> class /// Initializes a new instance of the <see cref="XmpProfile"/> class
@ -42,15 +42,15 @@ public sealed class XmpProfile : IDeepCloneable<XmpProfile>
/// <summary> /// <summary>
/// Gets the XMP raw data byte array. /// Gets the XMP raw data byte array.
/// </summary> /// </summary>
internal byte[] Data { get; private set; } internal byte[]? Data { get; private set; }
/// <summary> /// <summary>
/// Gets the raw XML document containing the XMP profile. /// Gets the raw XML document containing the XMP profile.
/// </summary> /// </summary>
/// <returns>The <see cref="XDocument"/></returns> /// <returns>The <see cref="XDocument"/></returns>
public XDocument GetDocument() public XDocument? GetDocument()
{ {
byte[] byteArray = this.Data; byte[]? byteArray = this.Data;
if (byteArray is null) if (byteArray is null)
{ {
return null; return null;
@ -77,6 +77,7 @@ public sealed class XmpProfile : IDeepCloneable<XmpProfile>
/// <returns>The <see cref="T:Byte[]"/></returns> /// <returns>The <see cref="T:Byte[]"/></returns>
public byte[] ToByteArray() public byte[] ToByteArray()
{ {
Guard.NotNull(this.Data);
byte[] result = new byte[this.Data.Length]; byte[] result = new byte[this.Data.Length];
this.Data.AsSpan().CopyTo(result); this.Data.AsSpan().CopyTo(result);
return result; return result;

Loading…
Cancel
Save