diff --git a/src/ImageSharp/Metadata/Profiles/IPTC/IptcProfile.cs b/src/ImageSharp/Metadata/Profiles/IPTC/IptcProfile.cs
index 119c6f2b50..f4b4f10432 100644
--- a/src/ImageSharp/Metadata/Profiles/IPTC/IptcProfile.cs
+++ b/src/ImageSharp/Metadata/Profiles/IPTC/IptcProfile.cs
@@ -79,42 +79,67 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Iptc
public IptcProfile DeepClone() => new IptcProfile(this);
///
- /// Returns the value with the specified tag.
+ /// Returns all value with the specified tag.
///
/// The tag of the iptc value.
- /// The value with the specified tag.
- public IptcValue GetValue(IptcTag tag)
+ /// The values found with the specified tag.
+ public List GetValues(IptcTag tag)
{
+ var values = new List();
foreach (IptcValue iptcValue in this.Values)
{
if (iptcValue.Tag == tag)
{
- return iptcValue;
+ values.Add(iptcValue);
}
}
- return null;
+ return values;
}
///
- /// Removes the value with the specified tag.
+ /// Removes all values with the specified tag.
///
- /// The tag of the iptc value.
+ /// The tag of the iptc value to remove.
/// True when the value was found and removed.
public bool RemoveValue(IptcTag tag)
{
this.Initialize();
- for (int i = 0; i < this.values.Count; i++)
+ bool removed = false;
+ for (int i = this.values.Count - 1; i >= 0; i--)
{
if (this.values[i].Tag == tag)
{
this.values.RemoveAt(i);
- return true;
+ removed = true;
+ }
+ }
+
+ return removed;
+ }
+
+ ///
+ /// Removes values with the specified tag and value.
+ ///
+ /// The tag of the iptc value to remove.
+ /// The value of the iptc item to remove.
+ /// True when the value was found and removed.
+ public bool RemoveValue(IptcTag tag, string value)
+ {
+ this.Initialize();
+
+ bool removed = false;
+ for (int i = this.values.Count - 1; i >= 0; i--)
+ {
+ if (this.values[i].Tag == tag && this.values[i].Value.Equals(value))
+ {
+ this.values.RemoveAt(i);
+ removed = true;
}
}
- return false;
+ return removed;
}
///
diff --git a/tests/ImageSharp.Tests/Metadata/Profiles/IPTC/IptcProfileTests.cs b/tests/ImageSharp.Tests/Metadata/Profiles/IPTC/IptcProfileTests.cs
index f15a0992d2..9f8f8088df 100644
--- a/tests/ImageSharp.Tests/Metadata/Profiles/IPTC/IptcProfileTests.cs
+++ b/tests/ImageSharp.Tests/Metadata/Profiles/IPTC/IptcProfileTests.cs
@@ -215,6 +215,55 @@ namespace SixLabors.ImageSharp.Tests.Metadata.Profiles.IPTC
ContainsIptcValue(values, tag, expectedValue);
}
+ [Fact]
+ public void IptcProfile_RemoveByTag_RemovesAllEntrys()
+ {
+ // arange
+ var profile = new IptcProfile();
+ profile.SetValue(IptcTag.Byline, "test");
+ profile.SetValue(IptcTag.Byline, "test2");
+
+ // act
+ var result = profile.RemoveValue(IptcTag.Byline);
+
+ // assert
+ Assert.True(result, "removed result should be true");
+ Assert.Empty(profile.Values);
+ }
+
+ [Fact]
+ public void IptcProfile_RemoveByTagAndValue_Works()
+ {
+ // arange
+ var profile = new IptcProfile();
+ profile.SetValue(IptcTag.Byline, "test");
+ profile.SetValue(IptcTag.Byline, "test2");
+
+ // act
+ var result = profile.RemoveValue(IptcTag.Byline, "test2");
+
+ // assert
+ Assert.True(result, "removed result should be true");
+ ContainsIptcValue(profile.Values, IptcTag.Byline, "test");
+ }
+
+ [Fact]
+ public void IptcProfile_GetValue_RetrievesAllEntrys()
+ {
+ // arange
+ var profile = new IptcProfile();
+ profile.SetValue(IptcTag.Byline, "test");
+ profile.SetValue(IptcTag.Byline, "test2");
+ profile.SetValue(IptcTag.Caption, "test");
+
+ // act
+ List result = profile.GetValues(IptcTag.Byline);
+
+ // assert
+ Assert.NotNull(result);
+ Assert.Equal(2, result.Count);
+ }
+
private static void ContainsIptcValue(IEnumerable values, IptcTag tag, string value)
{
Assert.True(values.Any(val => val.Tag == tag), $"Missing iptc tag {tag}");