Fix target-gated `#if`s to cover every applicable TFM

This commit is contained in:
YoshiRulz 2024-06-06 13:26:07 +10:00
parent 7691f2f724
commit e468d6ee76
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
11 changed files with 37 additions and 28 deletions

View File

@ -2,19 +2,26 @@
using System.Collections.Generic;
using System.Linq;
#if NET5_0_OR_GREATER
using KeyCollectionType = System.Collections.Generic.IReadOnlySet<string>;
#else
using KeyCollectionType = System.Collections.Generic.IReadOnlyCollection<string>;
#endif
namespace BizHawk.Client.Common
{
public sealed class UserDataApi : IUserDataApi
{
private readonly IMovieSession _movieSession;
#if NET6_0
public IReadOnlySet<string> Keys
=> throw new NotImplementedException();
#else
public IReadOnlyCollection<string> Keys
=> _movieSession.UserBag.Keys.ToList();
#endif
public KeyCollectionType Keys
{
get
{
ICollection<string> keys = _movieSession.UserBag.Keys;
return (keys as KeyCollectionType) ?? keys.ToList();
}
}
public UserDataApi(IMovieSession movieSession) => _movieSession = movieSession;

View File

@ -4,7 +4,7 @@ namespace BizHawk.Client.Common
{
public interface IUserDataApi : IExternalApi
{
#if NET6_0
#if NET5_0_OR_GREATER
IReadOnlySet<string> Keys { get; }
#else
IReadOnlyCollection<string> Keys { get; }

View File

@ -100,7 +100,7 @@ namespace BizHawk.Client.Common
else if (key.IsAxis)
{
var commaIndex = mnemonic.IndexOf(',', iterator);
#if NET6_0_OR_GREATER
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP2_1_OR_GREATER
var val = int.Parse(mnemonic.AsSpan(start: iterator, length: commaIndex - iterator));
#else
var axisValueString = mnemonic.Substring(startIndex: iterator, length: commaIndex - iterator);

View File

@ -149,7 +149,7 @@ namespace BizHawk.Client.Common
/// </param>
public void InsertRange(int index, IEnumerable<Watch> collection)
{
#if NET6_0
#if NET6_0_OR_GREATER
if (collection.TryGetNonEnumeratedCount(out var n) && n is 0) return;
#else
if (collection is ICollection<Watch> hasCount && hasCount.Count is 0) return;

View File

@ -146,7 +146,7 @@ namespace BizHawk.Common.CollectionExtensions
? countable.Count == n
: collection.Take(n + 1).Count() == n;
#if !NET6_0
#if !(NETSTANDARD2_1_OR_GREATER || NETCOREAPP2_0_OR_GREATER)
/// <summary>
/// Returns the value at <paramref name="key"/>.
/// If the key is not present, returns default(TValue).

View File

@ -60,7 +60,7 @@ namespace BizHawk.Common
private byte* CurrentPointer()
=> (byte*)Z.SS(_ptr + _pos);
#if NET6_0
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP2_1_OR_GREATER
public override int Read(Span<byte> buffer)
#else
public int Read(Span<byte> buffer)
@ -110,7 +110,7 @@ namespace BizHawk.Common
public override void SetLength(long value)
=> throw new IOException();
#if NET6_0
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP2_1_OR_GREATER
public override void Write(ReadOnlySpan<byte> buffer)
#else
public void Write(ReadOnlySpan<byte> buffer)

View File

@ -5,7 +5,7 @@ using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Reflection;
#if NET6_0
#if NETCOREAPP3_0_OR_GREATER
using System.Runtime.CompilerServices;
#endif
using System.Threading;
@ -81,7 +81,7 @@ namespace BizHawk.Common
return a.All(kvp => b.TryGetValue(kvp.Key, out var bVal) && comparer.Equals(kvp.Value, bVal));
}
#if NET6_0
#if NETCOREAPP3_0_OR_GREATER
public static string DescribeIsNull<T>(T? obj, [CallerArgumentExpression("obj")] string? expr = default)
#else
public static string DescribeIsNull<T>(T? obj, string expr)
@ -89,7 +89,7 @@ namespace BizHawk.Common
where T : class
=> $"{expr} is {(obj is null ? "null" : "not null")}";
#if NET6_0
#if NETCOREAPP3_0_OR_GREATER
public static string DescribeIsNullValT<T>(T? boxed, [CallerArgumentExpression("boxed")] string? expr = default)
#else
public static string DescribeIsNullValT<T>(T? boxed, string expr)

View File

@ -19,7 +19,7 @@ namespace BizHawk.Common
public /*static readonly*/const string EmptyFile = "D41D8CD98F00B204E9800998ECF8427E";
#if NET6_0
#if NET5_0_OR_GREATER
public static byte[] Compute(ReadOnlySpan<byte> data)
=> MD5.HashData(data);
#else

View File

@ -25,17 +25,9 @@ namespace BizHawk.Common
public /*static readonly*/const string Zero = "0000000000000000000000000000000000000000";
#if NET6_0
#if NET5_0_OR_GREATER
public static byte[] Compute(ReadOnlySpan<byte> data)
=> SHA1.HashData(data);
public static byte[] ComputeConcat(ReadOnlySpan<byte> dataA, ReadOnlySpan<byte> dataB)
{
using var impl = IncrementalHash.CreateHash(HashAlgorithmName.SHA1);
impl.AppendData(dataA);
impl.AppendData(dataB);
return impl.GetHashAndReset();
}
#else
private static unsafe byte[] UnmanagedImpl(byte[] buffer)
{
@ -88,7 +80,17 @@ namespace BizHawk.Common
public static byte[] Compute(ReadOnlySpan<byte> data)
=> Compute(data.ToArray());
#endif
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP2_1_OR_GREATER
public static byte[] ComputeConcat(ReadOnlySpan<byte> dataA, ReadOnlySpan<byte> dataB)
{
using var impl = IncrementalHash.CreateHash(HashAlgorithmName.SHA1);
impl.AppendData(dataA);
impl.AppendData(dataB);
return impl.GetHashAndReset();
}
#else
public static byte[] ComputeConcat(ReadOnlySpan<byte> dataA, ReadOnlySpan<byte> dataB)
=> ComputeConcat(dataA.ToArray(), dataB.ToArray());
#endif

View File

@ -19,7 +19,7 @@ namespace BizHawk.Common
public /*static readonly*/const string EmptyFile = "E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855";
#if NET6_0
#if NET5_0_OR_GREATER
public static byte[] Compute(ReadOnlySpan<byte> data)
=> SHA256.HashData(data);
#else

View File

@ -20,7 +20,7 @@ namespace BizHawk.Tests.Client.Common.config
private const string ZWINDER_SER = @"{""CurrentUseCompression"":false,""CurrentBufferSize"":256,""CurrentTargetFrameLength"":500,""CurrentStoreType"":0,""RecentUseCompression"":false,""RecentBufferSize"":128,""RecentTargetFrameLength"":2000,""RecentStoreType"":0,""GapsUseCompression"":false,""GapsBufferSize"":64,""GapsTargetFrameLength"":125,""GapsStoreType"":0,""AncientStateInterval"":5000,""AncientStoreType"":0}";
#if NET6_0
#if NET5_0_OR_GREATER
private static readonly IReadOnlySet<Type> KnownGoodFromStdlib = new HashSet<Type>
#else
private static readonly ICollection<Type> KnownGoodFromStdlib = new HashSet<Type>