Browse Source

workaround for inconsistent covariance of value-typed arrays

pull/1760/head
Ildar Khayrutdinov 5 years ago
parent
commit
e13122cab1
  1. 37
      src/ImageSharp/Metadata/Profiles/Exif/Values/ExifLong8Array.cs
  2. 20
      src/ImageSharp/Metadata/Profiles/Exif/Values/ExifNumberArray.cs

37
src/ImageSharp/Metadata/Profiles/Exif/Values/ExifLong8Array.cs

@ -51,25 +51,46 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Exif
switch (value)
{
case int val:
return this.SetSingle((ulong)val);
return this.SetSingle((ulong)Numerics.Clamp(val, 0, int.MaxValue));
case uint val:
return this.SetSingle((ulong)val);
case short val:
return this.SetSingle((ulong)val);
return this.SetSingle((ulong)Numerics.Clamp(val, 0, short.MaxValue));
case ushort val:
return this.SetSingle((ulong)val);
case long[] array:
{
if (value.GetType().Equals(typeof(ulong[])))
{
return this.SetArray((ulong[])value);
}
return this.SetArray(array);
case ulong[] array:
return this.SetArray(array);
}
case int[] array:
{
if (value.GetType().Equals(typeof(uint[])))
{
return this.SetArray((uint[])value);
}
return this.SetArray(array);
case uint[] array:
return this.SetArray(array);
}
case short[] array:
{
if (value.GetType().Equals(typeof(ushort[])))
{
return this.SetArray((ushort[])value);
}
return this.SetArray(array);
case ushort[] array:
return this.SetArray(array);
}
}
return false;

20
src/ImageSharp/Metadata/Profiles/Exif/Values/ExifNumberArray.cs

@ -54,13 +54,25 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Exif
case ushort val:
return this.SetSingle(val);
case int[] array:
{
// workaround for inconsistent covariance of value-typed arrays
if (value.GetType().Equals(typeof(uint[])))
{
return this.SetArray((uint[])value);
}
return this.SetArray(array);
case uint[] array:
return this.SetArray(array);
}
case short[] array:
{
if (value.GetType().Equals(typeof(ushort[])))
{
return this.SetArray((ushort[])value);
}
return this.SetArray(array);
case ushort[] array:
return this.SetArray(array);
}
}
return false;

Loading…
Cancel
Save