Fixed issues with seemingly incompatible language features in .NET 6

This commit is contained in:
Darth Affe 2023-09-23 19:46:30 +02:00
parent d5e17f7370
commit a89533aea7
12 changed files with 81 additions and 13 deletions

View File

@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net7.0-windows;net6.0-windows</TargetFrameworks>
<TargetFrameworks>net7.0;net6.0</TargetFrameworks>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>

View File

@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net7.0-windows;net6.0-windows</TargetFrameworks>
<TargetFrameworks>net7.0;net6.0</TargetFrameworks>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>

View File

@ -20,12 +20,21 @@ public sealed class CaptureZone<TColor> : ICaptureZone
/// <inheritdoc />
public Display Display { get; }
#if NET7_0_OR_GREATER
/// <inheritdoc />
public ColorFormat ColorFormat
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => TColor.ColorFormat;
}
#else
/// <inheritdoc />
public ColorFormat ColorFormat
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => default(TColor).Net6ColorFormat;
}
#endif
/// <inheritdoc />
public int X { get; internal set; }

View File

@ -17,6 +17,11 @@ public readonly struct ColorABGR : IColor
/// <inheritdoc />
public static ColorFormat ColorFormat => ColorFormat.ABGR;
#if !NET7_0_OR_GREATER
/// <inheritdoc />
public ColorFormat Net6ColorFormat => ColorFormat;
#endif
private readonly byte _a;
private readonly byte _b;
private readonly byte _g;

View File

@ -17,6 +17,11 @@ public readonly struct ColorARGB : IColor
/// <inheritdoc />
public static ColorFormat ColorFormat => ColorFormat.ARGB;
#if !NET7_0_OR_GREATER
/// <inheritdoc />
public ColorFormat Net6ColorFormat => ColorFormat;
#endif
private readonly byte _a;
private readonly byte _r;
private readonly byte _g;

View File

@ -17,6 +17,11 @@ public readonly struct ColorBGR : IColor
/// <inheritdoc />
public static ColorFormat ColorFormat => ColorFormat.BGR;
#if !NET7_0_OR_GREATER
/// <inheritdoc />
public ColorFormat Net6ColorFormat => ColorFormat;
#endif
private readonly byte _b;
private readonly byte _g;
private readonly byte _r;

View File

@ -17,6 +17,11 @@ public readonly struct ColorBGRA : IColor
/// <inheritdoc />
public static ColorFormat ColorFormat => ColorFormat.BGRA;
#if !NET7_0_OR_GREATER
/// <inheritdoc />
public ColorFormat Net6ColorFormat => ColorFormat;
#endif
private readonly byte _b;
private readonly byte _g;
private readonly byte _r;

View File

@ -17,6 +17,11 @@ public readonly struct ColorRGB : IColor
/// <inheritdoc />
public static ColorFormat ColorFormat => ColorFormat.RGB;
#if !NET7_0_OR_GREATER
/// <inheritdoc />
public ColorFormat Net6ColorFormat => ColorFormat;
#endif
private readonly byte _r;
private readonly byte _g;
private readonly byte _b;

View File

@ -17,6 +17,11 @@ public readonly struct ColorRGBA : IColor
/// <inheritdoc />
public static ColorFormat ColorFormat => ColorFormat.RGBA;
#if !NET7_0_OR_GREATER
/// <inheritdoc />
public ColorFormat Net6ColorFormat => ColorFormat;
#endif
private readonly byte _r;
private readonly byte _g;
private readonly byte _b;

View File

@ -27,8 +27,12 @@ public interface IColor
/// </summary>
byte A { get; }
#if NET7_0_OR_GREATER
/// <summary>
/// Gets the color-format of this color.
/// </summary>
public static virtual ColorFormat ColorFormat => throw new NotSupportedException();
#else
public ColorFormat Net6ColorFormat { get; }
#endif
}

View File

@ -18,8 +18,21 @@ public sealed class Image<TColor> : IImage
private readonly int _y;
private readonly int _stride;
#if NET7_0_OR_GREATER
/// <inheritdoc />
public ColorFormat ColorFormat => TColor.ColorFormat;
public ColorFormat ColorFormat
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => TColor.ColorFormat;
}
#else
/// <inheritdoc />
public ColorFormat ColorFormat
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => default(TColor).Net6ColorFormat;
}
#endif
/// <inheritdoc />
public int Width { get; }
@ -28,7 +41,7 @@ public sealed class Image<TColor> : IImage
public int Height { get; }
/// <inheritdoc />
public int SizeInBytes => Width * Height * TColor.ColorFormat.BytesPerPixel;
public int SizeInBytes => Width * Height * ColorFormat.BytesPerPixel;
#endregion
@ -96,7 +109,7 @@ public sealed class Image<TColor> : IImage
if (destination == null) throw new ArgumentNullException(nameof(destination));
if (destination.Length < SizeInBytes) throw new ArgumentException("The destination is too small to fit this image.", nameof(destination));
int targetStride = Width * TColor.ColorFormat.BytesPerPixel;
int targetStride = Width * ColorFormat.BytesPerPixel;
IImage.IImageRows rows = Rows;
Span<byte> target = destination;
foreach (IImage.IImageRow row in rows)
@ -211,8 +224,13 @@ public sealed class Image<TColor> : IImage
/// <inheritdoc />
public int Length => _length;
#if NET7_0_OR_GREATER
/// <inheritdoc />
public int SizeInBytes => Length * TColor.ColorFormat.BytesPerPixel;
#else
/// <inheritdoc />
public int SizeInBytes => Length * default(TColor).Net6ColorFormat.BytesPerPixel;
#endif
#endregion
@ -349,8 +367,13 @@ public sealed class Image<TColor> : IImage
/// <inheritdoc />
public int Length => _length;
#if NET7_0_OR_GREATER
/// <inheritdoc />
public int SizeInBytes => Length * TColor.ColorFormat.BytesPerPixel;
#else
/// <inheritdoc />
public int SizeInBytes => Length * default(TColor).Net6ColorFormat.BytesPerPixel;
#endif
#endregion

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFrameworks>net7.0;net6.0</TargetFrameworks>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>