Add Meziantou.Polyfill

This commit is contained in:
YoshiRulz 2025-06-02 10:10:51 +10:00
parent 071423fe8b
commit bb7e5bc02c
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
55 changed files with 7 additions and 148 deletions

View File

@ -9,6 +9,7 @@
<PackageVersion Include="Magick.NET-Q8-AnyCPU" Version="13.9.0" />
<PackageVersion Include="Menees.Analyzers" Version="3.2.2" />
<PackageVersion Include="Meziantou.Analyzer" Version="2.0.163" />
<PackageVersion Include="Meziantou.Polyfill" Version="1.0.49" />
<PackageVersion Include="Microsoft.Bcl.HashCode" Version="6.0.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.BannedApiAnalyzers" Version="3.3.4" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.8.0" />

View File

@ -7,7 +7,6 @@ using Vortice.Direct3D11;
using Vortice.DXGI;
using BizHawk.Common.CollectionExtensions;
using BizHawk.Common.StringExtensions;
using static SDL2.SDL;

View File

@ -5,7 +5,6 @@ using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using BizHawk.Common;
using BizHawk.Common.CollectionExtensions;
using static BizHawk.Common.RawInputImports;
using static BizHawk.Common.WmImports;

View File

@ -4,7 +4,6 @@ using System.Collections.Generic;
using System.Runtime.InteropServices;
using BizHawk.Common;
using BizHawk.Common.CollectionExtensions;
using static BizHawk.Common.XInput2Imports;
using static BizHawk.Common.XlibImports;

View File

@ -4,7 +4,6 @@ using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using BizHawk.Common;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES;
using BizHawk.Emulation.Cores.Consoles.Sega.gpgx;

View File

@ -1,7 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using BizHawk.Common;
using BizHawk.Common.CollectionExtensions;
namespace BizHawk.Client.Common

View File

@ -1,6 +1,5 @@
using System.Collections.Generic;
using BizHawk.Common;
using BizHawk.Emulation.Common;
namespace BizHawk.Client.Common

View File

@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Linq;
#if NET5_0_OR_GREATER
using KeyCollectionType = System.Collections.Generic.IReadOnlySet<string>;
@ -18,11 +17,7 @@ namespace BizHawk.Client.Common
get
{
ICollection<string> keys = _movieSession.UserBag.Keys;
#if NET5_0_OR_GREATER
return (keys as KeyCollectionType) ?? keys.ToHashSet();
#else
return (keys as KeyCollectionType) ?? keys.ToList();
#endif
}
}

View File

@ -10,7 +10,6 @@ using System.Numerics;
using System.Text.RegularExpressions;
using BizHawk.Bizware.Graphics;
using BizHawk.Common;
using BizHawk.Common.StringExtensions;
using BizHawk.Client.Common.FilterManager;

View File

@ -3,8 +3,6 @@
using System.Collections.Generic;
using System.Linq;
using BizHawk.Common.CollectionExtensions;
namespace BizHawk.Client.Common
{
public sealed class FilesystemFilterSet

View File

@ -1,7 +1,5 @@
using System.IO;
using BizHawk.Common.StringExtensions;
using Newtonsoft.Json;
//this file contains some cumbersome self-"serialization" in order to gain a modicum of control over what the serialized output looks like

View File

@ -1,8 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using BizHawk.Common;
namespace BizHawk.Client.Common
{
public class HotkeyInfo

View File

@ -1,7 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using BizHawk.Common;
using BizHawk.Common.CollectionExtensions;
using BizHawk.Emulation.Common;

View File

@ -1,7 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using BizHawk.Common.CollectionExtensions;
using BizHawk.Emulation.Common;
namespace BizHawk.Client.Common

View File

@ -3,8 +3,6 @@ using System.Drawing;
using System.Globalization;
using System.Linq;
using BizHawk.Common;
using NLua;
namespace BizHawk.Client.Common

View File

@ -2,7 +2,6 @@ using System.Collections.Generic;
using System.Globalization;
using System.IO;
using BizHawk.Common.StringExtensions;
using BizHawk.Emulation.Common;
namespace BizHawk.Client.Common

View File

@ -1,7 +1,6 @@
using System.IO;
using System.Linq;
using BizHawk.Common;
using BizHawk.Common.PathExtensions;
namespace BizHawk.Client.Common

View File

@ -1,8 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using BizHawk.Common;
using BizHawk.Common.CollectionExtensions;
using BizHawk.Emulation.Common;
namespace BizHawk.Client.Common

View File

@ -1,8 +1,6 @@
using System.Collections.Generic;
using System.Text;
using BizHawk.Common;
namespace BizHawk.Client.Common
{
public class Bk2Header : Dictionary<string, string>

View File

@ -1,5 +1,4 @@
using BizHawk.Common;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Cores;
namespace BizHawk.Client.Common.movie.import

View File

@ -1,7 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using BizHawk.Common.CollectionExtensions;
using BizHawk.Emulation.Common;
namespace BizHawk.Client.Common

View File

@ -1,5 +1,5 @@
using System.Collections.Generic;
using BizHawk.Common;
using BizHawk.Emulation.Common;
namespace BizHawk.Client.Common

View File

@ -1,8 +1,6 @@
using System.Collections.Generic;
using System.IO;
using BizHawk.Common.StringExtensions;
namespace BizHawk.Client.Common
{
internal class BkmMovie

View File

@ -1,7 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using BizHawk.Common.CollectionExtensions;
using BizHawk.Emulation.Common;
namespace BizHawk.Client.Common

View File

@ -1,7 +1,5 @@
using System.IO;
using BizHawk.Common.StringExtensions;
using Newtonsoft.Json;
namespace BizHawk.Client.Common

View File

@ -6,7 +6,6 @@ using System.Linq;
using System.Windows.Forms;
using BizHawk.Common;
using BizHawk.Common.StringExtensions;
using BizHawk.Emulation.Common;
using BizHawk.Client.Common;

View File

@ -4,7 +4,6 @@ using System.Threading;
using System.Windows.Forms;
using BizHawk.Bizware.Input;
using BizHawk.Common;
using BizHawk.Client.Common;
using BizHawk.Common.CollectionExtensions;

View File

@ -4,7 +4,6 @@ using System.Windows.Forms;
using BizHawk.Emulation.Common;
using BizHawk.Client.Common;
using BizHawk.Common;
namespace BizHawk.Client.EmuHawk
{

View File

@ -7,7 +7,6 @@ using System.Windows.Forms;
using BizHawk.Bizware.Input;
using BizHawk.Client.Common;
using BizHawk.Common;
using BizHawk.Common.CollectionExtensions;
using BizHawk.Emulation.Common;

View File

@ -2,8 +2,6 @@ using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using BizHawk.Common;
namespace BizHawk.Client.EmuHawk
{
public partial class FileExtensionPreferences : Form

View File

@ -2,7 +2,6 @@ using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using BizHawk.Common;
using BizHawk.Emulation.Common;
namespace BizHawk.Client.EmuHawk

View File

@ -5,7 +5,6 @@ using System.Windows.Forms;
using BizHawk.Bizware.Input;
using BizHawk.Client.Common;
using BizHawk.Common;
using BizHawk.Common.CollectionExtensions;
using BizHawk.Common.StringExtensions;

View File

@ -1,8 +1,6 @@
using System.Collections.Generic;
using System.Data;
using BizHawk.Common;
namespace BizHawk.Client.EmuHawk
{
public class DataTableDictionaryBind<TKey, TValue>

View File

@ -27,12 +27,7 @@ namespace BizHawk.Client.EmuHawk.ForDebugging
public DebugVSystemMenuItem(string sysID, params string[] extraSysIDs)
{
SysIDs = new[] { sysID }.Concat(extraSysIDs)
#if NET472_OR_GREATER || NETCOREAPP2_0_OR_GREATER
.ToHashSet();
#else // Meziantou.Polyfill covers `IEnumerable<>.ToHashSet` but we're not using that at time of writing --yoshi
.ToArray();
#endif
SysIDs = extraSysIDs.Prepend(sysID).ToHashSet();
Text = sysID;
}
}

View File

@ -7,7 +7,6 @@ using BizHawk.Emulation.Common;
using BizHawk.Client.Common;
using BizHawk.Client.EmuHawk.Properties;
using BizHawk.Client.EmuHawk.ToolExtensions;
using BizHawk.Common;
// TODO - select which memorydomains go out to the CDL file. will this cause a problem when re-importing it?
// perhaps missing domains shouldn't fail a check

View File

@ -2,7 +2,6 @@ using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using BizHawk.Common;
using BizHawk.Common.NumberExtensions;
using BizHawk.Emulation.Common;

View File

@ -8,7 +8,6 @@ using BizHawk.Common.NumberExtensions;
using BizHawk.Client.Common;
using BizHawk.Common;
using BizHawk.Common.CollectionExtensions;
using BizHawk.Common.StringExtensions;
namespace BizHawk.Client.EmuHawk
{

View File

@ -220,24 +220,6 @@ namespace BizHawk.Common.CollectionExtensions
? countable.Count == n
: collection.Take(n + 1).Count() == n;
#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).
/// backported from .NET Core 2.0
/// </summary>
public static TValue? GetValueOrDefault<TKey, TValue>(this IReadOnlyDictionary<TKey, TValue> dictionary, TKey key)
=> dictionary.TryGetValue(key, out var found) ? found : default;
/// <summary>
/// Returns the value at <paramref name="key"/>.
/// If the key is not present, returns <paramref name="defaultValue"/>.
/// backported from .NET Core 2.0
/// </summary>
public static TValue? GetValueOrDefault<TKey, TValue>(this IReadOnlyDictionary<TKey, TValue> dictionary, TKey key, TValue defaultValue)
=> dictionary.TryGetValue(key, out var found) ? found : defaultValue;
#endif
/// <summary>
/// Returns the value at <paramref name="key"/>.
/// If the key is not present, stores the result of <c>defaultValue(key)</c> in the dict, and then returns that.
@ -392,18 +374,6 @@ namespace BizHawk.Common.CollectionExtensions
return null;
}
#if !NET7_0_OR_GREATER
/// <remarks>shorthand for <c>this.OrderBy(static e => e)</c>, backported from .NET 7</remarks>
public static IOrderedEnumerable<T> Order<T>(this IEnumerable<T> source)
where T : IComparable<T>
=> source.OrderBy(ReturnSelf);
/// <remarks>shorthand for <c>this.OrderByDescending(static e => e)</c>, backported from .NET 7</remarks>
public static IOrderedEnumerable<T> OrderDescending<T>(this IEnumerable<T> source)
where T : IComparable<T>
=> source.OrderByDescending(ReturnSelf);
#endif
/// <returns><see langword="true"/> iff any removed</returns>
public static bool RemoveAll<T>(this ICollection<T> collection, T item)
{
@ -455,10 +425,6 @@ namespace BizHawk.Common.CollectionExtensions
return c - list.Count;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static T ReturnSelf<T>(this T self)
=> self;
public static bool ReversedSequenceEqual<T>(this ReadOnlySpan<T> a, ReadOnlySpan<T> b)
where T : IEquatable<T>
{

View File

@ -13,11 +13,6 @@ namespace BizHawk.Common.IOExtensions
public static Span<byte> GetBufferAsSpan(this MemoryStream ms)
=> ms.GetBuffer().AsSpan().Slice(start: 0, length: (int) ms.Length);
public static unsafe string GetString(this Encoding encoding, ReadOnlySpan<byte> bytes)
{
fixed (byte* p = bytes) return encoding.GetString(p, bytes.Length);
}
/// <remarks>does NOT seek to beginning</remarks>
public static byte[] ReadAllBytes(this Stream stream)
{

View File

@ -14,14 +14,6 @@ namespace BizHawk.Common.StringExtensions
return new(a);
}
#if !(NETSTANDARD2_1_OR_GREATER || NETCOREAPP2_1_OR_GREATER)
public static bool Contains(this string haystack, char needle)
=> haystack.IndexOf(needle) >= 0;
public static bool Contains(this string haystack, string needle, StringComparison comparisonType)
=> haystack.IndexOf(needle, comparisonType) != -1;
#endif
/// <inheritdoc cref="EqualsIgnoreCase"/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool ContainsIgnoreCase(this string haystack, string needle)
@ -35,11 +27,6 @@ namespace BizHawk.Common.StringExtensions
public static bool ContainsOrdinal(this string haystack, string needle)
=> haystack.Contains(needle); // already ordinal
#if !(NETSTANDARD2_1_OR_GREATER || NETCOREAPP2_1_OR_GREATER)
public static bool EndsWith(this string haystack, char needle)
=> haystack.Length >= 1 && haystack[^1] == needle;
#endif
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool EndsWithOrdinal(this string haystack, char needle)
=> haystack.EndsWith(needle); // already ordinal
@ -140,14 +127,6 @@ namespace BizHawk.Common.StringExtensions
/// </returns>
public static string RemoveSuffix(this string str, string suffix, string notFoundValue) => str.EndsWith(suffix, StringComparison.Ordinal) ? str.Substring(0, str.Length - suffix.Length) : notFoundValue;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool StartsWith(this ReadOnlySpan<char> str, char c)
=> str.Length >= 1 && str[0] == c;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool StartsWith(this string str, char c)
=> str.Length >= 1 && str[0] == c;
/// <inheritdoc cref="EqualsIgnoreCase"/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool StartsWithIgnoreCase(this string haystack, string needle)

View File

@ -66,14 +66,6 @@ namespace BizHawk.Common
return data;
}
#if !(NETSTANDARD2_1_OR_GREATER || NETCOREAPP2_0_OR_GREATER)
public static void Deconstruct<TKey, TValue>(this KeyValuePair<TKey, TValue> kvp, out TKey key, out TValue value)
{
key = kvp.Key;
value = kvp.Value;
}
#endif
/// <remarks>adapted from https://stackoverflow.com/a/3928856/7467292, values are compared using <see cref="EqualityComparer{T}.Default">EqualityComparer.Default</see></remarks>
public static bool DictionaryEqual<TKey, TValue>(IDictionary<TKey, TValue> a, IDictionary<TKey, TValue> b)
where TKey : notnull

View File

@ -1,7 +1,6 @@
using System.Collections.Generic;
using System.Diagnostics;
using BizHawk.Common;
using BizHawk.Common.StringExtensions;
namespace BizHawk.Emulation.Common

View File

@ -2,8 +2,6 @@ using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using BizHawk.Common;
namespace BizHawk.Emulation.Common
{
/// <summary>

View File

@ -3,7 +3,6 @@ using System.Collections.Immutable;
using System.Linq;
using System.Text.RegularExpressions;
using BizHawk.Common;
using BizHawk.Common.CollectionExtensions;
using BizHawk.Common.StringExtensions;

View File

@ -2,8 +2,6 @@
using System.Collections.Generic;
using BizHawk.Common;
namespace BizHawk.Emulation.Common
{
// the idea here is that various connected peripherals have their controls all merged

View File

@ -8,7 +8,6 @@ using System.Text;
using BizHawk.Common;
using BizHawk.Common.BufferExtensions;
using BizHawk.Common.IOExtensions;
using BizHawk.Common.NumberExtensions;
using BizHawk.Common.StringExtensions;

View File

@ -3,9 +3,6 @@
using System.Collections.Generic;
using System.IO;
using BizHawk.Common;
using BizHawk.Common.CollectionExtensions;
namespace BizHawk.Emulation.Common
{
/// <summary>

View File

@ -2,8 +2,6 @@ using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using BizHawk.Common.CollectionExtensions;
namespace BizHawk.Emulation.Common
{
/// <summary>

View File

@ -12,7 +12,6 @@ using BizHawk.BizInvoke;
using BizHawk.Common;
using BizHawk.Common.IOExtensions;
using BizHawk.Common.NumberExtensions;
using BizHawk.Common.StringExtensions;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Cores.Properties;
using BizHawk.Emulation.Cores.Waterbox;

View File

@ -2,7 +2,7 @@ using System.IO;
using System.Globalization;
using System.Collections.Generic;
using System.Linq;
using BizHawk.Common;
using BizHawk.Common.StringExtensions;
//check out ccd2iso linux program?

View File

@ -26,9 +26,6 @@ namespace BizHawk.Tests.Client.Common.Movie
public static void Write(this BinaryWriter bw, ReadOnlySpan<byte> buf)
=> bw.Write(buf.ToArray());
public static void Write(this Stream stream, ReadOnlySpan<byte> buf)
=> stream.Write(buf.ToArray(), offset: 0, count: buf.Length);
}
#endif

View File

@ -2,7 +2,6 @@
using System.Linq;
using BizHawk.Client.Common;
using BizHawk.Common;
using BizHawk.Emulation.Cores;
namespace BizHawk.Tests.Client.Common.config

View File

@ -3,9 +3,6 @@ using System.Drawing;
using System.Reflection;
using BizHawk.Client.Common;
#if !(NETSTANDARD2_1_OR_GREATER || NETCOREAPP2_0_OR_GREATER)
using BizHawk.Common;
#endif
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

View File

@ -1,9 +1,6 @@
using System.Collections.Generic;
using System.Linq;
#if !NET7_0_OR_GREATER
using BizHawk.Common.CollectionExtensions;
#endif
using BizHawk.Common.StringExtensions;
using BizHawk.Emulation.Common;

View File

@ -8,6 +8,7 @@
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<DebugType>embedded</DebugType>
<DefineConstants>$(DefineConstants);AVI_SUPPORT</DefineConstants>
<MeziantouPolyfill_ExcludedPolyfills>T:System.Diagnostics.CodeAnalysis.ExperimentalAttribute|T:System.Diagnostics.CodeAnalysis.SetsRequiredMembersAttribute|T:System.Diagnostics.CodeAnalysis.StringSyntaxAttribute|T:System.Diagnostics.CodeAnalysis.UnscopedRefAttribute|T:System.Index|T:System.Range|T:System.Runtime.CompilerServices.CallerArgumentExpressionAttribute|T:System.Runtime.CompilerServices.CollectionBuilderAttribute|T:System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute|T:System.Runtime.CompilerServices.InterpolatedStringHandlerArgumentAttribute|T:System.Runtime.CompilerServices.InterpolatedStringHandlerAttribute|T:System.Runtime.CompilerServices.IsExternalInit|T:System.Runtime.CompilerServices.ModuleInitializerAttribute|T:System.Runtime.CompilerServices.OverloadResolutionPriorityAttribute|T:System.Runtime.CompilerServices.RequiredMemberAttribute|T:System.Runtime.CompilerServices.SkipLocalsInitAttribute|T:System.Runtime.Versioning.RequiresPreviewFeaturesAttribute</MeziantouPolyfill_ExcludedPolyfills> <!-- these collide with PolySharp -->
<NeutralLanguage>en-US</NeutralLanguage>
<NoWarn>$(NoWarn);CS1573;NU1702</NoWarn>
<Product>BizHawk</Product>
@ -18,6 +19,7 @@
<PathMap>$(SolutionDir)=/</PathMap>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Meziantou.Polyfill" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.BannedApiAnalyzers" PrivateAssets="all" />
<Analyzer Include="$(MSBuildProjectDirectory)/../../References/BizHawk.SrcGen.ReflectionCache.dll" />
<AdditionalFiles Include="$(MSBuildThisFileDirectory)/BannedSymbols.BannedApiAnalyzers.txt" />