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

Try to fix some nullability warnings #7

Merged
merged 1 commit into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void TestSplitSingleFragment()
Assert.Single(fragments);
Assert.True(fragments.First().Bytes.SequenceEqual(fileBytes));
Assert.NotNull(fragments.First().Segment);
Assert.Equal(JpegSegmentType.App1, fragments.First().Segment.Type);
Assert.Equal(JpegSegmentType.App1, fragments.First().Segment!.Type);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public sealed class JpegMetadataWriterTest
public void TestUpdateJpegFragments_Replace()
{
// substitute the original with re-encoded Xmp content
List<JpegFragment> originalFragments = null;
List<JpegFragment>? originalFragments = null;
using (var stream = TestDataUtil.OpenRead("Data/xmpWriting_PictureWithMicrosoftXmp.jpg"))
originalFragments = JpegFragmentWriter.SplitFragments(new SequentialStreamReader(stream));
IXmpMeta xmp = XmpMetaFactory.ParseFromString(File.ReadAllText("Data/xmpWriting_XmpContent.xmp"));
Expand Down Expand Up @@ -79,7 +79,7 @@ public void TestUpdateJpegFragments_Replace()
public void TestUpdateJpegFragments_FailsOnUnknownMetadataObject()
{
// substitute the original with re-encoded Xmp content
List<JpegFragment> originalFragments = null;
List<JpegFragment>? originalFragments = null;
using (var stream = TestDataUtil.OpenRead("Data/xmpWriting_PictureWithMicrosoftXmp.jpg"))
originalFragments = JpegFragmentWriter.SplitFragments(new SequentialStreamReader(stream));
IXmpMeta xmp = XmpMetaFactory.ParseFromString(File.ReadAllText("Data/xmpWriting_XmpContent.xmp"));
Expand Down
4 changes: 2 additions & 2 deletions JpegXmpWritePluginMDE.Tests/Formats/Xmp/XmpWriterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void TestWritePreambleToXmpBytes()
public void TestUpdateFragments_Replace()
{
// substitute the original with re-encoded Xmp content
List<JpegFragment> originalFragments = null;
List<JpegFragment>? originalFragments = null;
using (var stream = TestDataUtil.OpenRead("Data/xmpWriting_PictureWithMicrosoftXmp.jpg"))
originalFragments = JpegFragmentWriter.SplitFragments(new SequentialStreamReader(stream));
IXmpMeta xmp = XmpMetaFactory.ParseFromString(File.ReadAllText("Data/xmpWriting_XmpContent.xmp"));
Expand Down Expand Up @@ -89,7 +89,7 @@ public void TestUpdateFragments_Replace()
public void TestUpdateFragments_Insert()
{
// substitute the original with re-encoded Xmp content
List<JpegFragment> originalFragments = null;
List<JpegFragment>? originalFragments = null;
using (var stream = TestDataUtil.OpenRead("Data/xmpWriting_PictureWithoutXmp.jpg"))
originalFragments = JpegFragmentWriter.SplitFragments(new SequentialStreamReader(stream));
IXmpMeta xmp = XmpMetaFactory.ParseFromString(File.ReadAllText("Data/xmpWriting_XmpContent.xmp"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using JetBrains.Annotations;
using MetadataExtractor.Formats.Jpeg;
using System;
using System.Collections.Generic;
using System.Text;
using MetadataExtractor.Formats.Jpeg;

namespace JpegXmpWritePluginMDE.MetadataExtractor.Formats.Jpeg
{
Expand All @@ -21,21 +17,19 @@ public sealed class JpegFragment
/// <summary>
/// JpegSegment interpretation of this fragment.
/// </summary>
[CanBeNull]
public JpegSegmentPlugin Segment { get; }
public JpegSegmentPlugin? Segment { get; }

/// <summary>
/// All bytes that make up the JpegFragment. (Includes potential JpegSegment marker + size)
/// </summary>
[NotNull]
public byte[] Bytes { get; }

/// <summary>
/// Create a JpegFragment from the fragment bytes.
/// </summary>
/// <param name="bytes">All bytes that make up the fragment.</param>
/// <param name="segment">Optional JpegSegment interpretation of this fragment.</param>
public JpegFragment([NotNull] byte[] bytes, [CanBeNull] JpegSegmentPlugin segment = null)
public JpegFragment(byte[] bytes, JpegSegmentPlugin? segment = null)
{
Bytes = bytes;
Segment = segment;
Expand All @@ -44,7 +38,7 @@ public JpegFragment([NotNull] byte[] bytes, [CanBeNull] JpegSegmentPlugin segmen
public override string ToString()
{
if (IsSegment)
return $"{Bytes.Length} bytes ({Segment.Type})";
return $"{Bytes.Length} bytes ({Segment!.Type})";
else
return $"{Bytes.Length} bytes";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public List<JpegFragment> UpdateFragments([NotNull] FragmentList fragments, [Not

if (!wroteData && currentFragment.IsSegment)
{
JpegSegmentType currentType = currentFragment.Segment.Type;
JpegSegmentType currentType = currentFragment.Segment!.Type;

// if this is an existing App1 XMP fragment, overwrite it with the new fragment
if (currentType == JpegSegmentType.App1 && currentFragment.Segment.Bytes.Length > XmpReader.JpegSegmentPreamble.Length)
Expand Down
Loading