add PolySharp as explicit dep, do some BizHawk.Common .NET6 cleanups
PolySharp was already an implicit dep due to some transitive dep from Vortice. This causes some problems in the test project, although it seems it's specific to the test project setup / one of the test project deps exposing internal classes rather than actually the fault of PolySharp (enabling PolySharpExcludeTypeForwardedToDeclarations works around it) PolySharp provides source generated internal IsExternalInit/Range/Index, allowing us to use init props and range/index operators, and since it's source generated and internal to each project, it should play nice with potential multi-targetting (keeping in mind the test project is an edge case that doesn't apply in general)
This commit is contained in:
parent
3fb30a2ca7
commit
ded668fe5a
src
BizHawk.Common
BizHawk.Common.csprojIsExternalInit.cs
MemoryBlock
PropertyGridConverters
ConstrainedFloatConverter.csConstrainedIntConverter.csConstrainedStringConverter.csDescribableEnumConverter.cs
Util.csBizHawk.Tests
|
@ -8,6 +8,7 @@
|
|||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Bcl.HashCode" Version="1.1.1" />
|
||||
<PackageReference Include="PolySharp" Version="1.14.1" />
|
||||
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
|
||||
<PackageReference Include="System.Memory" Version="4.5.5" />
|
||||
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.0.0" />
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
namespace System.Runtime.CompilerServices
|
||||
{
|
||||
public static class IsExternalInit {}
|
||||
}
|
|
@ -60,7 +60,11 @@ namespace BizHawk.Common
|
|||
private byte* CurrentPointer()
|
||||
=> (byte*)Z.SS(_ptr + _pos);
|
||||
|
||||
#if NET6_0
|
||||
public override int Read(Span<byte> buffer)
|
||||
#else
|
||||
public int Read(Span<byte> buffer)
|
||||
#endif
|
||||
{
|
||||
if (!_readable)
|
||||
{
|
||||
|
@ -106,7 +110,11 @@ namespace BizHawk.Common
|
|||
public override void SetLength(long value)
|
||||
=> throw new IOException();
|
||||
|
||||
#if NET6_0
|
||||
public override void Write(ReadOnlySpan<byte> buffer)
|
||||
#else
|
||||
public void Write(ReadOnlySpan<byte> buffer)
|
||||
#endif
|
||||
{
|
||||
if (!_writable)
|
||||
{
|
||||
|
|
|
@ -12,14 +12,14 @@ namespace BizHawk.Common
|
|||
/// </summary>
|
||||
public class ConstrainedFloatConverter : TypeConverter
|
||||
{
|
||||
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
|
||||
public override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType)
|
||||
{
|
||||
return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
|
||||
}
|
||||
|
||||
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
|
||||
public override object ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object? value)
|
||||
{
|
||||
var range = (RangeAttribute)context.Instance
|
||||
var range = (RangeAttribute)context!.Instance
|
||||
.GetType()
|
||||
.GetProperty(context.PropertyDescriptor!.Name)!
|
||||
.GetCustomAttributes()
|
||||
|
@ -40,7 +40,7 @@ namespace BizHawk.Common
|
|||
throw new FormatException($"Invalid value: {value}, {context.PropertyDescriptor.Name} must be a float.");
|
||||
}
|
||||
|
||||
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
|
||||
public override object ConvertTo(ITypeDescriptorContext? context, CultureInfo? culture, object? value, Type destinationType)
|
||||
{
|
||||
if (destinationType == null)
|
||||
{
|
||||
|
|
|
@ -12,14 +12,14 @@ namespace BizHawk.Common
|
|||
/// </summary>
|
||||
public class ConstrainedIntConverter : TypeConverter
|
||||
{
|
||||
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
|
||||
public override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType)
|
||||
{
|
||||
return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
|
||||
}
|
||||
|
||||
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
|
||||
public override object ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object? value)
|
||||
{
|
||||
var range = (RangeAttribute)context.Instance
|
||||
var range = (RangeAttribute)context!.Instance
|
||||
.GetType()
|
||||
.GetProperty(context.PropertyDescriptor!.Name)!
|
||||
.GetCustomAttributes()
|
||||
|
@ -40,7 +40,7 @@ namespace BizHawk.Common
|
|||
throw new FormatException($"Invalid value: {value}, {context.PropertyDescriptor.Name} must be an integer.");
|
||||
}
|
||||
|
||||
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
|
||||
public override object ConvertTo(ITypeDescriptorContext? context, CultureInfo? culture, object? value, Type destinationType)
|
||||
{
|
||||
if (destinationType == null)
|
||||
{
|
||||
|
|
|
@ -12,14 +12,14 @@ namespace BizHawk.Common
|
|||
/// </summary>
|
||||
public class ConstrainedStringConverter : TypeConverter
|
||||
{
|
||||
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
|
||||
public override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType)
|
||||
{
|
||||
return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
|
||||
}
|
||||
|
||||
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
|
||||
public override object ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object? value)
|
||||
{
|
||||
var maxLength = (MaxLengthAttribute)context.Instance
|
||||
var maxLength = (MaxLengthAttribute)context!.Instance
|
||||
.GetType()
|
||||
.GetProperty(context.PropertyDescriptor!.Name)!
|
||||
.GetCustomAttributes()
|
||||
|
|
|
@ -16,11 +16,11 @@ namespace BizHawk.Common
|
|||
enumType = type;
|
||||
}
|
||||
|
||||
public override bool CanConvertFrom(ITypeDescriptorContext context, Type srcType) => srcType == typeof(string);
|
||||
public override bool CanConvertFrom(ITypeDescriptorContext? context, Type srcType) => srcType == typeof(string);
|
||||
|
||||
public override bool CanConvertTo(ITypeDescriptorContext context, Type destType) => destType == typeof(string);
|
||||
public override bool CanConvertTo(ITypeDescriptorContext? context, Type? destType) => destType == typeof(string);
|
||||
|
||||
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
|
||||
public override object ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object? value)
|
||||
{
|
||||
var valueStr = value?.ToString() ?? throw new ArgumentNullException(paramName: nameof(value));
|
||||
return Enum.Parse(
|
||||
|
@ -31,7 +31,7 @@ namespace BizHawk.Common
|
|||
);
|
||||
}
|
||||
|
||||
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destType)
|
||||
public override object ConvertTo(ITypeDescriptorContext? context, CultureInfo? culture, object? value, Type destType)
|
||||
{
|
||||
var fieldName = Enum.GetName(enumType, value ?? throw new ArgumentNullException(paramName: nameof(value)));
|
||||
if (fieldName != null)
|
||||
|
@ -47,14 +47,14 @@ namespace BizHawk.Common
|
|||
return value.ToString();
|
||||
}
|
||||
|
||||
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) => new(
|
||||
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext? context) => new(
|
||||
enumType.GetFields(BindingFlags.Public | BindingFlags.Static)
|
||||
.Select(fi => fi.GetValue(null))
|
||||
.ToList()
|
||||
);
|
||||
|
||||
public override bool GetStandardValuesExclusive(ITypeDescriptorContext context) => true;
|
||||
public override bool GetStandardValuesExclusive(ITypeDescriptorContext? context) => true;
|
||||
|
||||
public override bool GetStandardValuesSupported(ITypeDescriptorContext context) => true;
|
||||
public override bool GetStandardValuesSupported(ITypeDescriptorContext? context) => true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,9 @@ using System.IO;
|
|||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
#if NET6_0
|
||||
using System.Runtime.CompilerServices;
|
||||
#endif
|
||||
using System.Threading;
|
||||
|
||||
namespace BizHawk.Common
|
||||
|
@ -79,7 +82,7 @@ namespace BizHawk.Common
|
|||
}
|
||||
|
||||
#if NET6_0
|
||||
public static string DescribeIsNull<T>(T? obj, [CallerArgumentExpression("obj")] string expr = default)
|
||||
public static string DescribeIsNull<T>(T? obj, [CallerArgumentExpression("obj")] string? expr = default)
|
||||
#else
|
||||
public static string DescribeIsNull<T>(T? obj, string expr)
|
||||
#endif
|
||||
|
@ -87,7 +90,7 @@ namespace BizHawk.Common
|
|||
=> $"{expr} is {(obj is null ? "null" : "not null")}";
|
||||
|
||||
#if NET6_0
|
||||
public static string DescribeIsNullValT<T>(T? boxed, [CallerArgumentExpression("boxed")] string expr = default)
|
||||
public static string DescribeIsNullValT<T>(T? boxed, [CallerArgumentExpression("boxed")] string? expr = default)
|
||||
#else
|
||||
public static string DescribeIsNullValT<T>(T? boxed, string expr)
|
||||
#endif
|
||||
|
|
|
@ -22,6 +22,10 @@
|
|||
<None Include="$(ProjectDir)../../Assets/dll/libbizhash.*" CopyToOutputDirectory="PreserveNewest" />
|
||||
<None Include="$(ProjectDir)../../Assets/dll/libzstd.*" CopyToOutputDirectory="PreserveNewest" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup>
|
||||
<!-- Works around weird issue with IsExternalInit specifically, cause is likely related to https://github.com/Sergio0694/PolySharp/issues/48? -->
|
||||
<PolySharpExcludeTypeForwardedToDeclarations>true</PolySharpExcludeTypeForwardedToDeclarations>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="data/**/*" />
|
||||
</ItemGroup>
|
||||
|
|
Loading…
Reference in New Issue