Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Nullable disable from MetaData.Profiles #2330

Merged
merged 7 commits into from
Feb 5, 2023
3 changes: 2 additions & 1 deletion src/ImageSharp/Formats/Gif/MetadataExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.

using System.Diagnostics.CodeAnalysis;
using SixLabors.ImageSharp.Formats.Gif;
using SixLabors.ImageSharp.Metadata;

Expand Down Expand Up @@ -37,5 +38,5 @@ public static partial class MetadataExtensions
/// <returns>
/// <see langword="true"/> if the gif frame metadata exists; otherwise, <see langword="false"/>.
/// </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 changes: 7 additions & 8 deletions src/ImageSharp/Metadata/ImageFrameMetadata.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
#nullable disable

using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.Metadata.Profiles.Exif;
Expand Down Expand Up @@ -49,22 +48,22 @@ internal ImageFrameMetadata(ImageFrameMetadata other)
/// <summary>
/// Gets or sets the Exif profile.
/// </summary>
public ExifProfile ExifProfile { get; set; }
public ExifProfile? ExifProfile { get; set; }

/// <summary>
/// Gets or sets the XMP profile.
/// </summary>
public XmpProfile XmpProfile { get; set; }
public XmpProfile? XmpProfile { get; set; }

/// <summary>
/// Gets or sets the ICC profile.
/// </summary>
public IccProfile IccProfile { get; set; }
public IccProfile? IccProfile { get; set; }

/// <summary>
/// Gets or sets the iptc profile.
/// </summary>
public IptcProfile IptcProfile { get; set; }
public IptcProfile? IptcProfile { get; set; }

/// <inheritdoc/>
public ImageFrameMetadata DeepClone() => new(this);
Expand All @@ -83,7 +82,7 @@ public TFormatFrameMetadata GetFormatMetadata<TFormatMetadata, TFormatFrameMetad
where TFormatMetadata : class
where TFormatFrameMetadata : class, IDeepCloneable
{
if (this.formatMetadata.TryGetValue(key, out IDeepCloneable meta))
if (this.formatMetadata.TryGetValue(key, out IDeepCloneable? meta))
{
return (TFormatFrameMetadata)meta;
}
Expand All @@ -107,11 +106,11 @@ public TFormatFrameMetadata GetFormatMetadata<TFormatMetadata, TFormatFrameMetad
/// <returns>
/// <see langword="true"/> if the frame metadata exists for the specified key; otherwise, <see langword="false"/>.
/// </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 TFormatFrameMetadata : class, IDeepCloneable
{
if (this.formatMetadata.TryGetValue(key, out IDeepCloneable meta))
if (this.formatMetadata.TryGetValue(key, out IDeepCloneable? meta))
{
metadata = (TFormatFrameMetadata)meta;
return true;
Expand Down
20 changes: 9 additions & 11 deletions src/ImageSharp/Metadata/Profiles/IPTC/IptcProfile.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
#nullable disable

using System.Buffers.Binary;
using System.Collections.ObjectModel;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Text;
using SixLabors.ImageSharp.Metadata.Profiles.IPTC;
Expand All @@ -30,15 +30,15 @@ public sealed class IptcProfile : IDeepCloneable<IptcProfile>
/// Initializes a new instance of the <see cref="IptcProfile"/> class.
/// </summary>
public IptcProfile()
: this((byte[])null)
: this((byte[]?)null)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="IptcProfile"/> class.
/// </summary>
/// <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.Initialize();
Expand All @@ -53,14 +53,11 @@ private IptcProfile(IptcProfile other)
{
Guard.NotNull(other, nameof(other));

if (other.values != null)
{
this.values = new Collection<IptcValue>();
this.values = new Collection<IptcValue>();
stefannikolei marked this conversation as resolved.
Show resolved Hide resolved

foreach (IptcValue value in other.Values)
{
this.values.Add(value.DeepClone());
}
foreach (IptcValue value in other.Values)
{
this.values.Add(value.DeepClone());
}

if (other.Data != null)
Expand All @@ -78,7 +75,7 @@ private IptcProfile(IptcProfile other)
/// <summary>
/// Gets the byte data of the IPTC profile.
/// </summary>
public byte[] Data { get; private set; }
public byte[]? Data { get; private set; }

/// <summary>
/// Gets the values of this iptc profile.
Expand Down Expand Up @@ -310,6 +307,7 @@ private int WriteRecord(int offset, ReadOnlySpan<byte> recordData, IptcRecordNum
return offset;
}

[MemberNotNull(nameof(values))]
private void Initialize()
{
if (this.values != null)
Expand Down
10 changes: 3 additions & 7 deletions src/ImageSharp/Metadata/Profiles/IPTC/IptcValue.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
#nullable disable

using System.Text;

Expand All @@ -22,10 +21,7 @@ internal IptcValue(IptcValue other)
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.Strict = other.Strict;
Expand Down Expand Up @@ -133,7 +129,7 @@ public string Value
/// </summary>
/// <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>
public override bool Equals(object obj)
public override bool Equals(object? obj)
{
if (ReferenceEquals(this, obj))
{
Expand All @@ -148,7 +144,7 @@ public override bool Equals(object obj)
/// </summary>
/// <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>
public bool Equals(IptcValue other)
public bool Equals(IptcValue? other)
{
if (other is null)
{
Expand Down
13 changes: 7 additions & 6 deletions src/ImageSharp/Metadata/Profiles/XMP/XmpProfile.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
#nullable disable

using System.Diagnostics;
using System.Text;
using System.Xml.Linq;

Expand All @@ -17,15 +17,15 @@ public sealed class XmpProfile : IDeepCloneable<XmpProfile>
/// Initializes a new instance of the <see cref="XmpProfile"/> class.
/// </summary>
public XmpProfile()
: this((byte[])null)
: this((byte[]?)null)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="XmpProfile"/> class.
/// </summary>
/// <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>
/// Initializes a new instance of the <see cref="XmpProfile"/> class
Expand All @@ -42,15 +42,15 @@ private XmpProfile(XmpProfile other)
/// <summary>
/// Gets the XMP raw data byte array.
/// </summary>
internal byte[] Data { get; private set; }
internal byte[]? Data { get; private set; }

/// <summary>
/// Gets the raw XML document containing the XMP profile.
/// </summary>
/// <returns>The <see cref="XDocument"/></returns>
public XDocument GetDocument()
public XDocument? GetDocument()
{
byte[] byteArray = this.Data;
byte[]? byteArray = this.Data;
if (byteArray is null)
{
return null;
Expand All @@ -77,6 +77,7 @@ public XDocument GetDocument()
/// <returns>The <see cref="T:Byte[]"/></returns>
public byte[] ToByteArray()
{
Guard.NotNull(this.Data);
byte[] result = new byte[this.Data.Length];
this.Data.AsSpan().CopyTo(result);
return result;
Expand Down