Fixed issues with seemingly incompatible language features in .NET 6

This commit is contained in:
DarthAffe committed 2023-09-23 19:46:30 +02:00
1 parent d5e17f7370
commit a89533aea7
12 files changed
+81 -13

No files matched your search

@@ -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>
@@ -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>
+10 -1
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; }
@@ -95,7 +104,7 @@ public sealed class CaptureZone<TColor> : ICaptureZone
/// <inheritdoc />
public bool IsUpdateRequested { get; private set; }
#endregion
#endregion
#region Events
+6 -1
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;
@@ -39,7 +44,7 @@ public readonly struct ColorABGR : IColor
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="ColorABGR"/> class.
/// </summary>
+6 -1
View File
@@ -13,10 +13,15 @@ namespace ScreenCapture.NET;
public readonly struct ColorARGB : IColor
{
#region Properties & Fields
/// <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;
+6 -1
View File
@@ -13,10 +13,15 @@ namespace ScreenCapture.NET;
public readonly struct ColorBGR : IColor
{
#region Properties & Fields
/// <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;
+7 -2
View File
@@ -13,10 +13,15 @@ namespace ScreenCapture.NET;
public readonly struct ColorBGRA : IColor
{
#region Properties & Fields
/// <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;
@@ -36,7 +41,7 @@ public readonly struct ColorBGRA : IColor
public byte A => _a;
// ReSharper restore ConvertToAutoPropertyWhenPossible
#endregion
#endregion
#region Constructors
+6 -1
View File
@@ -13,10 +13,15 @@ namespace ScreenCapture.NET;
public readonly struct ColorRGB : IColor
{
#region Properties & Fields
/// <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;
@@ -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;
+4
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
}
+26 -3
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
@@ -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>