Use Polyfill package to simplify net462 support

This commit is contained in:
Ben Olden-Cooligan 2024-04-01 18:09:47 -07:00
parent 426330ea13
commit 9a2537c840
37 changed files with 18 additions and 638 deletions

View File

@ -1,5 +0,0 @@
// https://sergiopedri.medium.com/enabling-and-using-c-9-features-on-older-and-unsupported-runtimes-ce384d8debb
// ReSharper disable once CheckNamespace
namespace System.Runtime.CompilerServices;
internal static class IsExternalInit {}

View File

@ -1,61 +0,0 @@
// https://sergiopedri.medium.com/enabling-and-using-c-9-features-on-older-and-unsupported-runtimes-ce384d8debb
// ReSharper disable once CheckNamespace
namespace System.Runtime.CompilerServices
{
internal static class IsExternalInit
{
}
/// <summary>Specifies that a type has required members or that a member is required.</summary>
[AttributeUsage(
AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Field | AttributeTargets.Property,
AllowMultiple = false, Inherited = false)]
internal sealed class RequiredMemberAttribute : Attribute
{
}
/// <summary>
/// Indicates that compiler support for a particular feature is required for the location where this attribute is applied.
/// </summary>
[AttributeUsage(AttributeTargets.All, AllowMultiple = true, Inherited = false)]
internal sealed class CompilerFeatureRequiredAttribute : Attribute
{
public CompilerFeatureRequiredAttribute(string featureName)
{
FeatureName = featureName;
}
/// <summary>
/// The name of the compiler feature.
/// </summary>
public string FeatureName { get; }
/// <summary>
/// If true, the compiler can choose to allow access to the location where this attribute is applied if it does not understand <see cref="FeatureName"/>.
/// </summary>
public bool IsOptional { get; init; }
/// <summary>
/// The <see cref="FeatureName"/> used for the ref structs C# feature.
/// </summary>
public const string RefStructs = nameof(RefStructs);
/// <summary>
/// The <see cref="FeatureName"/> used for the required members C# feature.
/// </summary>
public const string RequiredMembers = nameof(RequiredMembers);
}
}
namespace System.Diagnostics.CodeAnalysis
{
/// <summary>
/// Specifies that this constructor sets all required members for the current type, and callers
/// do not need to set any required members themselves.
/// </summary>
[AttributeUsage(AttributeTargets.Constructor, AllowMultiple = false, Inherited = false)]
internal sealed class SetsRequiredMembersAttribute : Attribute
{
}
}

View File

@ -16,7 +16,6 @@
<ItemGroup>
<PackageReference Include="EmbedIO" Version="3.5.2" />
<PackageReference Include="Nullable" Version="1.3.1" PrivateAssets="all" />
</ItemGroup>
<ItemGroup>

View File

@ -1,61 +0,0 @@
// https://sergiopedri.medium.com/enabling-and-using-c-9-features-on-older-and-unsupported-runtimes-ce384d8debb
// ReSharper disable once CheckNamespace
namespace System.Runtime.CompilerServices
{
internal static class IsExternalInit
{
}
/// <summary>Specifies that a type has required members or that a member is required.</summary>
[AttributeUsage(
AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Field | AttributeTargets.Property,
AllowMultiple = false, Inherited = false)]
internal sealed class RequiredMemberAttribute : Attribute
{
}
/// <summary>
/// Indicates that compiler support for a particular feature is required for the location where this attribute is applied.
/// </summary>
[AttributeUsage(AttributeTargets.All, AllowMultiple = true, Inherited = false)]
internal sealed class CompilerFeatureRequiredAttribute : Attribute
{
public CompilerFeatureRequiredAttribute(string featureName)
{
FeatureName = featureName;
}
/// <summary>
/// The name of the compiler feature.
/// </summary>
public string FeatureName { get; }
/// <summary>
/// If true, the compiler can choose to allow access to the location where this attribute is applied if it does not understand <see cref="FeatureName"/>.
/// </summary>
public bool IsOptional { get; init; }
/// <summary>
/// The <see cref="FeatureName"/> used for the ref structs C# feature.
/// </summary>
public const string RefStructs = nameof(RefStructs);
/// <summary>
/// The <see cref="FeatureName"/> used for the required members C# feature.
/// </summary>
public const string RequiredMembers = nameof(RequiredMembers);
}
}
namespace System.Diagnostics.CodeAnalysis
{
/// <summary>
/// Specifies that this constructor sets all required members for the current type, and callers
/// do not need to set any required members themselves.
/// </summary>
[AttributeUsage(AttributeTargets.Constructor, AllowMultiple = false, Inherited = false)]
internal sealed class SetsRequiredMembersAttribute : Attribute
{
}
}

View File

@ -11,6 +11,7 @@
<ProjectReference Include="..\NAPS2.Escl\NAPS2.Escl.csproj" />
<PackageReference Include="LibUsbDotNet" Version="3.0.102-alpha" />
<PackageReference Include="Polyfill" Version="4.2.0" />
</ItemGroup>
</Project>

View File

@ -1,61 +0,0 @@
// https://sergiopedri.medium.com/enabling-and-using-c-9-features-on-older-and-unsupported-runtimes-ce384d8debb
// ReSharper disable once CheckNamespace
namespace System.Runtime.CompilerServices
{
internal static class IsExternalInit
{
}
/// <summary>Specifies that a type has required members or that a member is required.</summary>
[AttributeUsage(
AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Field | AttributeTargets.Property,
AllowMultiple = false, Inherited = false)]
internal sealed class RequiredMemberAttribute : Attribute
{
}
/// <summary>
/// Indicates that compiler support for a particular feature is required for the location where this attribute is applied.
/// </summary>
[AttributeUsage(AttributeTargets.All, AllowMultiple = true, Inherited = false)]
internal sealed class CompilerFeatureRequiredAttribute : Attribute
{
public CompilerFeatureRequiredAttribute(string featureName)
{
FeatureName = featureName;
}
/// <summary>
/// The name of the compiler feature.
/// </summary>
public string FeatureName { get; }
/// <summary>
/// If true, the compiler can choose to allow access to the location where this attribute is applied if it does not understand <see cref="FeatureName"/>.
/// </summary>
public bool IsOptional { get; init; }
/// <summary>
/// The <see cref="FeatureName"/> used for the ref structs C# feature.
/// </summary>
public const string RefStructs = nameof(RefStructs);
/// <summary>
/// The <see cref="FeatureName"/> used for the required members C# feature.
/// </summary>
public const string RequiredMembers = nameof(RequiredMembers);
}
}
namespace System.Diagnostics.CodeAnalysis
{
/// <summary>
/// Specifies that this constructor sets all required members for the current type, and callers
/// do not need to set any required members themselves.
/// </summary>
[AttributeUsage(AttributeTargets.Constructor, AllowMultiple = false, Inherited = false)]
internal sealed class SetsRequiredMembersAttribute : Attribute
{
}
}

View File

@ -18,8 +18,10 @@
<ItemGroup>
<PackageReference Include="NAPS2.Mdns" Version="1.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
<PackageReference Include="Polyfill" Version="4.2.0" />
<PackageReference Include="StandardSocketsHttpHandler" Version="2.2.0.8" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
</ItemGroup>
<ItemGroup>

View File

@ -3,9 +3,7 @@ using System.Drawing.Imaging;
namespace NAPS2.Images.Gdi;
#if NET6_0_OR_GREATER
[System.Runtime.Versioning.SupportedOSPlatform("windows7.0")]
#endif
public static class GdiExtensions
{
public static Bitmap RenderToBitmap(this IRenderableImage image)

View File

@ -7,9 +7,7 @@ namespace NAPS2.Images.Gdi;
/// <summary>
/// An implementation of IMemoryImage that wraps a GDI+ image (System.Drawing.Bitmap).
/// </summary>
#if NET6_0_OR_GREATER
[System.Runtime.Versioning.SupportedOSPlatform("windows7.0")]
#endif
public class GdiImage : IMemoryImage
{
public GdiImage(Bitmap bitmap)

View File

@ -4,9 +4,7 @@ using NAPS2.Util;
namespace NAPS2.Images.Gdi;
#if NET6_0_OR_GREATER
[System.Runtime.Versioning.SupportedOSPlatform("windows7.0")]
#endif
public class GdiImageContext : ImageContext
{
private readonly GdiImageTransformer _imageTransformer;

View File

@ -4,9 +4,7 @@ using NAPS2.Images.Bitwise;
namespace NAPS2.Images.Gdi;
#if NET6_0_OR_GREATER
[System.Runtime.Versioning.SupportedOSPlatform("windows7.0")]
#endif
public class GdiImageLockState : ImageLockState
{
public static GdiImageLockState Create(Bitmap bitmap, LockMode lockMode, out BitwiseImageData imageData)

View File

@ -4,9 +4,7 @@ using System.Drawing.Imaging;
namespace NAPS2.Images.Gdi;
#if NET6_0_OR_GREATER
[System.Runtime.Versioning.SupportedOSPlatform("windows7.0")]
#endif
public class GdiImageTransformer : AbstractImageTransformer<GdiImage>
{
public GdiImageTransformer(ImageContext imageContext) : base(imageContext)

View File

@ -7,9 +7,7 @@ namespace NAPS2.Images.Gdi;
/// <summary>
/// Ensures that bitmaps use a standard pixel format/palette.
/// </summary>
#if NET6_0_OR_GREATER
[System.Runtime.Versioning.SupportedOSPlatform("windows7.0")]
#endif
internal static class GdiPixelFormatFixer
{
public static bool MaybeFixPixelFormat(ref Bitmap bitmap)

View File

@ -4,9 +4,7 @@ using NAPS2.Util;
namespace NAPS2.Images.Gdi;
#if NET6_0_OR_GREATER
[System.Runtime.Versioning.SupportedOSPlatform("windows7.0")]
#endif
internal class GdiTiffWriter : ITiffWriter
{
public bool SaveTiff(IList<IMemoryImage> images, string path,

View File

@ -1,5 +0,0 @@
// https://sergiopedri.medium.com/enabling-and-using-c-9-features-on-older-and-unsupported-runtimes-ce384d8debb
// ReSharper disable once CheckNamespace
namespace System.Runtime.CompilerServices;
public static class IsExternalInit {}

View File

@ -1,4 +1,5 @@
using System.Collections.Immutable;
using System.Diagnostics.CodeAnalysis;
using NAPS2.Util;
namespace NAPS2.Images;
@ -46,8 +47,8 @@ public abstract class ImageContext
ImageType = imageType;
}
// TODO: Add NotNullWhen attribute?
private bool MaybeRenderPdf(ImageFileStorage fileStorage, IPdfRenderer? pdfRenderer, out IMemoryImage? renderedPdf)
private bool MaybeRenderPdf(ImageFileStorage fileStorage, IPdfRenderer? pdfRenderer,
[NotNullWhen(true)] out IMemoryImage? renderedPdf)
{
if (Path.GetExtension(fileStorage.FullPath).ToLowerInvariant() == ".pdf")
{
@ -63,7 +64,8 @@ public abstract class ImageContext
return false;
}
private bool MaybeRenderPdf(ImageMemoryStorage memoryStorage, IPdfRenderer? pdfRenderer, out IMemoryImage? renderedPdf)
private bool MaybeRenderPdf(ImageMemoryStorage memoryStorage, IPdfRenderer? pdfRenderer,
[NotNullWhen(true)] out IMemoryImage? renderedPdf)
{
if (memoryStorage.TypeHint == ".pdf")
{
@ -250,13 +252,13 @@ public abstract class ImageContext
case ImageFileStorage fileStorage:
if (MaybeRenderPdf(fileStorage, pdfRenderer, out var renderedPdf))
{
return renderedPdf!;
return renderedPdf;
}
return Load(fileStorage.FullPath);
case ImageMemoryStorage memoryStorage:
if (MaybeRenderPdf(memoryStorage, pdfRenderer, out var renderedMemoryPdf))
{
return renderedMemoryPdf!;
return renderedMemoryPdf;
}
return Load(memoryStorage.Stream);
case IMemoryImage image:

View File

@ -1,5 +0,0 @@
// https://sergiopedri.medium.com/enabling-and-using-c-9-features-on-older-and-unsupported-runtimes-ce384d8debb
// ReSharper disable once CheckNamespace
namespace System.Runtime.CompilerServices;
public static class IsExternalInit {}

View File

@ -18,8 +18,8 @@
<ItemGroup>
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="8.0.0" />
<PackageReference Include="Polyfill" Version="4.2.0" />
<PackageReference Include="System.Collections.Immutable" Version="8.0.0" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
<PackageReference Include="ZXing.Net" Version="0.16.9" />
<ProjectReference Include="..\NAPS2.Internals\NAPS2.Internals.csproj" />

View File

@ -15,7 +15,9 @@
<ItemGroup>
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="8.0.0" />
<PackageReference Include="Polyfill" Version="4.2.0" />
<PackageReference Include="System.Collections.Immutable" Version="8.0.0" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
</ItemGroup>
<Import Project="..\NAPS2.Setup\targets\CommonTargets.targets" />

View File

@ -1,61 +0,0 @@
// https://sergiopedri.medium.com/enabling-and-using-c-9-features-on-older-and-unsupported-runtimes-ce384d8debb
// ReSharper disable once CheckNamespace
namespace System.Runtime.CompilerServices
{
internal static class IsExternalInit
{
}
/// <summary>Specifies that a type has required members or that a member is required.</summary>
[AttributeUsage(
AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Field | AttributeTargets.Property,
AllowMultiple = false, Inherited = false)]
internal sealed class RequiredMemberAttribute : Attribute
{
}
/// <summary>
/// Indicates that compiler support for a particular feature is required for the location where this attribute is applied.
/// </summary>
[AttributeUsage(AttributeTargets.All, AllowMultiple = true, Inherited = false)]
internal sealed class CompilerFeatureRequiredAttribute : Attribute
{
public CompilerFeatureRequiredAttribute(string featureName)
{
FeatureName = featureName;
}
/// <summary>
/// The name of the compiler feature.
/// </summary>
public string FeatureName { get; }
/// <summary>
/// If true, the compiler can choose to allow access to the location where this attribute is applied if it does not understand <see cref="FeatureName"/>.
/// </summary>
public bool IsOptional { get; init; }
/// <summary>
/// The <see cref="FeatureName"/> used for the ref structs C# feature.
/// </summary>
public const string RefStructs = nameof(RefStructs);
/// <summary>
/// The <see cref="FeatureName"/> used for the required members C# feature.
/// </summary>
public const string RequiredMembers = nameof(RequiredMembers);
}
}
namespace System.Diagnostics.CodeAnalysis
{
/// <summary>
/// Specifies that this constructor sets all required members for the current type, and callers
/// do not need to set any required members themselves.
/// </summary>
[AttributeUsage(AttributeTargets.Constructor, AllowMultiple = false, Inherited = false)]
internal sealed class SetsRequiredMembersAttribute : Attribute
{
}
}

View File

@ -1,87 +0,0 @@
// ReSharper disable once CheckNamespace
#if !NET6_0_OR_GREATER
namespace System
{
using System.Runtime.CompilerServices;
public readonly struct Index : IEquatable<Index>
{
private readonly int _value;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Index(int value, bool fromEnd = false)
{
if (value < 0)
{
throw new ArgumentOutOfRangeException();
}
if (fromEnd)
_value = ~value;
else
_value = value;
}
private Index(int value)
{
_value = value;
}
public static Index Start => new Index(0);
public static Index End => new Index(~0);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Index FromStart(int value)
{
if (value < 0)
{
throw new ArgumentOutOfRangeException();
}
return new Index(value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Index FromEnd(int value)
{
if (value < 0)
{
throw new ArgumentOutOfRangeException();
}
return new Index(~value);
}
public int Value
{
get
{
if (_value < 0)
return ~_value;
else
return _value;
}
}
public bool IsFromEnd => _value < 0;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int GetOffset(int length)
{
int offset = _value;
if (IsFromEnd)
{
offset += length + 1;
}
return offset;
}
public override bool Equals(object? value) => value is Index && _value == ((Index)value)._value;
public bool Equals(Index other) => _value == other._value;
public override int GetHashCode() => _value;
public static implicit operator Index(int value) => FromStart(value);
}
}
#endif

View File

@ -1,61 +0,0 @@
// https://sergiopedri.medium.com/enabling-and-using-c-9-features-on-older-and-unsupported-runtimes-ce384d8debb
// ReSharper disable once CheckNamespace
namespace System.Runtime.CompilerServices
{
internal static class IsExternalInit
{
}
/// <summary>Specifies that a type has required members or that a member is required.</summary>
[AttributeUsage(
AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Field | AttributeTargets.Property,
AllowMultiple = false, Inherited = false)]
internal sealed class RequiredMemberAttribute : Attribute
{
}
/// <summary>
/// Indicates that compiler support for a particular feature is required for the location where this attribute is applied.
/// </summary>
[AttributeUsage(AttributeTargets.All, AllowMultiple = true, Inherited = false)]
internal sealed class CompilerFeatureRequiredAttribute : Attribute
{
public CompilerFeatureRequiredAttribute(string featureName)
{
FeatureName = featureName;
}
/// <summary>
/// The name of the compiler feature.
/// </summary>
public string FeatureName { get; }
/// <summary>
/// If true, the compiler can choose to allow access to the location where this attribute is applied if it does not understand <see cref="FeatureName"/>.
/// </summary>
public bool IsOptional { get; init; }
/// <summary>
/// The <see cref="FeatureName"/> used for the ref structs C# feature.
/// </summary>
public const string RefStructs = nameof(RefStructs);
/// <summary>
/// The <see cref="FeatureName"/> used for the required members C# feature.
/// </summary>
public const string RequiredMembers = nameof(RequiredMembers);
}
}
namespace System.Diagnostics.CodeAnalysis
{
/// <summary>
/// Specifies that this constructor sets all required members for the current type, and callers
/// do not need to set any required members themselves.
/// </summary>
[AttributeUsage(AttributeTargets.Constructor, AllowMultiple = false, Inherited = false)]
internal sealed class SetsRequiredMembersAttribute : Attribute
{
}
}

View File

@ -1,5 +0,0 @@
// https://sergiopedri.medium.com/enabling-and-using-c-9-features-on-older-and-unsupported-runtimes-ce384d8debb
// ReSharper disable once CheckNamespace
namespace System.Runtime.CompilerServices;
internal static class IsExternalInit {}

View File

@ -16,6 +16,7 @@
<PackageReference Include="NAPS2.Pdfium.Binaries" Version="1.1.0" />
<PackageReference Include="NAPS2.Tesseract.Binaries" Version="1.2.0" />
<PackageReference Include="IsExternalInit" Version="1.0.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="NSubstitute" Version="5.0.0" />
<PackageReference Include="RichardSzalay.MockHttp" Version="7.0.0" />

View File

@ -1,61 +0,0 @@
// https://sergiopedri.medium.com/enabling-and-using-c-9-features-on-older-and-unsupported-runtimes-ce384d8debb
// ReSharper disable once CheckNamespace
namespace System.Runtime.CompilerServices
{
internal static class IsExternalInit
{
}
/// <summary>Specifies that a type has required members or that a member is required.</summary>
[AttributeUsage(
AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Field | AttributeTargets.Property,
AllowMultiple = false, Inherited = false)]
internal sealed class RequiredMemberAttribute : Attribute
{
}
/// <summary>
/// Indicates that compiler support for a particular feature is required for the location where this attribute is applied.
/// </summary>
[AttributeUsage(AttributeTargets.All, AllowMultiple = true, Inherited = false)]
internal sealed class CompilerFeatureRequiredAttribute : Attribute
{
public CompilerFeatureRequiredAttribute(string featureName)
{
FeatureName = featureName;
}
/// <summary>
/// The name of the compiler feature.
/// </summary>
public string FeatureName { get; }
/// <summary>
/// If true, the compiler can choose to allow access to the location where this attribute is applied if it does not understand <see cref="FeatureName"/>.
/// </summary>
public bool IsOptional { get; init; }
/// <summary>
/// The <see cref="FeatureName"/> used for the ref structs C# feature.
/// </summary>
public const string RefStructs = nameof(RefStructs);
/// <summary>
/// The <see cref="FeatureName"/> used for the required members C# feature.
/// </summary>
public const string RequiredMembers = nameof(RequiredMembers);
}
}
namespace System.Diagnostics.CodeAnalysis
{
/// <summary>
/// Specifies that this constructor sets all required members for the current type, and callers
/// do not need to set any required members themselves.
/// </summary>
[AttributeUsage(AttributeTargets.Constructor, AllowMultiple = false, Inherited = false)]
internal sealed class SetsRequiredMembersAttribute : Attribute
{
}
}

View File

@ -34,12 +34,13 @@
<PackageReference Include="Autofac" Version="8.0.0" />
<PackageReference Include="Ben.Demystifier" Version="0.4.1" />
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="Eto.Forms" Version="2.8.3" />
<PackageReference Include="Grpc.Tools" Version="2.62.0" PrivateAssets="all" />
<PackageReference Include="MimeKitLite" Version="4.4.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="NLog" Version="5.2.8" />
<PackageReference Include="Eto.Forms" Version="2.8.3" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.8" />
<PackageReference Include="Polyfill" Version="4.2.0" />
<PackageReference Include="System.Security.Cryptography.ProtectedData" Version="8.0.0" />
</ItemGroup>

View File

@ -43,9 +43,7 @@ public class StillImage
// TODO: Does it make sense to add IStillImage::(Un)RegisterLaunchApplication to NAPS2.Wia.Native?
// https://docs.microsoft.com/en-us/previous-versions/windows/hardware/drivers/ff543798(v=vs.85)
// Instead of modifying the registry directly.
#if NET6_0_OR_GREATER
[System.Runtime.Versioning.SupportedOSPlatform("windows7.0")]
#endif
public void Register()
{
var exe = AssemblyHelper.EntryFile;
@ -71,9 +69,7 @@ public class StillImage
key3.SetValue("Name", "NAPS2");
}
#if NET6_0_OR_GREATER
[System.Runtime.Versioning.SupportedOSPlatform("windows7.0")]
#endif
public void Unregister()
{
Registry.LocalMachine.DeleteSubKey(REGKEY_AUTOPLAY_HANDLER_NAPS2, false);

View File

@ -1,61 +0,0 @@
// https://sergiopedri.medium.com/enabling-and-using-c-9-features-on-older-and-unsupported-runtimes-ce384d8debb
// ReSharper disable once CheckNamespace
namespace System.Runtime.CompilerServices
{
internal static class IsExternalInit
{
}
/// <summary>Specifies that a type has required members or that a member is required.</summary>
[AttributeUsage(
AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Field | AttributeTargets.Property,
AllowMultiple = false, Inherited = false)]
internal sealed class RequiredMemberAttribute : Attribute
{
}
/// <summary>
/// Indicates that compiler support for a particular feature is required for the location where this attribute is applied.
/// </summary>
[AttributeUsage(AttributeTargets.All, AllowMultiple = true, Inherited = false)]
internal sealed class CompilerFeatureRequiredAttribute : Attribute
{
public CompilerFeatureRequiredAttribute(string featureName)
{
FeatureName = featureName;
}
/// <summary>
/// The name of the compiler feature.
/// </summary>
public string FeatureName { get; }
/// <summary>
/// If true, the compiler can choose to allow access to the location where this attribute is applied if it does not understand <see cref="FeatureName"/>.
/// </summary>
public bool IsOptional { get; init; }
/// <summary>
/// The <see cref="FeatureName"/> used for the ref structs C# feature.
/// </summary>
public const string RefStructs = nameof(RefStructs);
/// <summary>
/// The <see cref="FeatureName"/> used for the required members C# feature.
/// </summary>
public const string RequiredMembers = nameof(RequiredMembers);
}
}
namespace System.Diagnostics.CodeAnalysis
{
/// <summary>
/// Specifies that this constructor sets all required members for the current type, and callers
/// do not need to set any required members themselves.
/// </summary>
[AttributeUsage(AttributeTargets.Constructor, AllowMultiple = false, Inherited = false)]
internal sealed class SetsRequiredMembersAttribute : Attribute
{
}
}

View File

@ -7,9 +7,7 @@ using Xunit;
namespace NAPS2.Sdk.Tests.Images;
#if NET6_0_OR_GREATER
[System.Runtime.Versioning.SupportedOSPlatform("windows7.0")]
#endif
public class GdiImageTests
{
[Fact]

View File

@ -28,11 +28,12 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="NSubstitute" Version="5.0.0" />
<PackageReference Include="PdfAValidator" Version="2.1.109" />
<PackageReference Include="Polyfill" Version="4.2.0" />
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7" PrivateAssets="all" />
</ItemGroup>
<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
<_Parameter1>NAPS2.Lib.Tests</_Parameter1>

View File

@ -1,5 +0,0 @@
// https://sergiopedri.medium.com/enabling-and-using-c-9-features-on-older-and-unsupported-runtimes-ce384d8debb
// ReSharper disable once CheckNamespace
namespace System.Runtime.CompilerServices;
internal static class IsExternalInit {}

View File

@ -2,9 +2,7 @@
namespace NAPS2.ImportExport.Email.Mapi;
#if NET6_0_OR_GREATER
[System.Runtime.Versioning.SupportedOSPlatform("windows7.0")]
#endif
internal class MapiWrapper : IMapiWrapper
{
private readonly SystemEmailClients _systemEmailClients;

View File

@ -6,9 +6,7 @@ using NAPS2.Scan;
namespace NAPS2.ImportExport.Email.Mapi;
#if NET6_0_OR_GREATER
[System.Runtime.Versioning.SupportedOSPlatform("windows7.0")]
#endif
internal class SystemEmailClients
{
private const string DEFAULT_MAPI_DLL = "mapi32.dll";

View File

@ -37,7 +37,6 @@
<PackageReference Include="NAPS2.NTwain" Version="1.0.0" Condition="'$(TargetFramework)' != 'net8-macos10.15'" />
<PackageReference Include="NAPS2.PdfSharp" Version="1.0.1" />
<PackageReference Include="NAPS2.Wia" Version="2.0.3" Condition="'$(TargetFramework)' != 'net8-macos10.15'" />
<PackageReference Include="Nullable" Version="1.3.1" PrivateAssets="all" Condition="'$(TargetFramework)' == 'net462'" />
<PackageReference Include="SharpZipLib" Version="1.4.2" />
<PackageReference Include="SixLabors.Fonts" Version="1.0.1" />
<PackageReference Include="System.Collections.Immutable" Version="8.0.0" />

View File

@ -10,9 +10,7 @@ namespace NAPS2.Scan.Internal.Twain;
/// <summary>
/// A MessageLoopHook implementation that uses Win32 methods directly, with no dependencies on WinForms or WPF.
/// </summary>
#if NET6_0_OR_GREATER
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
#endif
internal class Win32MessageLoopHook : MessageLoopHook
{
private readonly ILogger _logger;

View File

@ -7,9 +7,7 @@ using NAPS2.Wia;
namespace NAPS2.Scan.Internal.Wia;
#if NET6_0_OR_GREATER
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
#endif
internal class WiaScanDriver : IScanDriver
{
private readonly ScanningContext _scanningContext;

View File

@ -1,61 +0,0 @@
// https://sergiopedri.medium.com/enabling-and-using-c-9-features-on-older-and-unsupported-runtimes-ce384d8debb
// ReSharper disable once CheckNamespace
namespace System.Runtime.CompilerServices
{
internal static class IsExternalInit
{
}
/// <summary>Specifies that a type has required members or that a member is required.</summary>
[AttributeUsage(
AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Field | AttributeTargets.Property,
AllowMultiple = false, Inherited = false)]
internal sealed class RequiredMemberAttribute : Attribute
{
}
/// <summary>
/// Indicates that compiler support for a particular feature is required for the location where this attribute is applied.
/// </summary>
[AttributeUsage(AttributeTargets.All, AllowMultiple = true, Inherited = false)]
internal sealed class CompilerFeatureRequiredAttribute : Attribute
{
public CompilerFeatureRequiredAttribute(string featureName)
{
FeatureName = featureName;
}
/// <summary>
/// The name of the compiler feature.
/// </summary>
public string FeatureName { get; }
/// <summary>
/// If true, the compiler can choose to allow access to the location where this attribute is applied if it does not understand <see cref="FeatureName"/>.
/// </summary>
public bool IsOptional { get; init; }
/// <summary>
/// The <see cref="FeatureName"/> used for the ref structs C# feature.
/// </summary>
public const string RefStructs = nameof(RefStructs);
/// <summary>
/// The <see cref="FeatureName"/> used for the required members C# feature.
/// </summary>
public const string RequiredMembers = nameof(RequiredMembers);
}
}
namespace System.Diagnostics.CodeAnalysis
{
/// <summary>
/// Specifies that this constructor sets all required members for the current type, and callers
/// do not need to set any required members themselves.
/// </summary>
[AttributeUsage(AttributeTargets.Constructor, AllowMultiple = false, Inherited = false)]
internal sealed class SetsRequiredMembersAttribute : Attribute
{
}
}