More nullability
This commit is contained in:
parent
52203314ca
commit
cba0eada69
|
@ -1,6 +1,4 @@
|
|||
#nullable disable
|
||||
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
|
@ -16,7 +14,8 @@ namespace BizHawk.Common.CollectionExtensions
|
|||
return desc ? source.OrderByDescending(keySelector) : source.OrderBy(keySelector);
|
||||
}
|
||||
|
||||
public static int LowerBoundBinarySearch<T, TKey>(this IList<T> list, Func<T, TKey> keySelector, TKey key) where TKey : IComparable<TKey>
|
||||
public static int LowerBoundBinarySearch<T, TKey>(this IList<T> list, Func<T, TKey> keySelector, TKey key)
|
||||
where TKey : IComparable<TKey>
|
||||
{
|
||||
int min = 0;
|
||||
int max = list.Count;
|
||||
|
@ -73,7 +72,7 @@ namespace BizHawk.Common.CollectionExtensions
|
|||
/// <exception cref="InvalidOperationException"><paramref name="key"/> not found after mapping <paramref name="keySelector"/> over <paramref name="list"/></exception>
|
||||
/// <remarks>implementation from https://stackoverflow.com/a/1766369/7467292</remarks>
|
||||
public static T BinarySearch<T, TKey>(this IList<T> list, Func<T, TKey> keySelector, TKey key)
|
||||
where TKey : IComparable<TKey>
|
||||
where TKey : IComparable<TKey>
|
||||
{
|
||||
int min = 0;
|
||||
int max = list.Count;
|
||||
|
|
|
@ -1,7 +1,4 @@
|
|||
#nullable disable
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace BizHawk.Common.IOExtensions
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
#nullable disable
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
|
@ -21,7 +19,7 @@ namespace BizHawk.Common
|
|||
|
||||
private static readonly Lazy<ILinkedLibManager> _LinkedLibManager = new Lazy<ILinkedLibManager>(() => CurrentOS switch
|
||||
{
|
||||
DistinctOS.Linux => (ILinkedLibManager) new UnixMonoLLManager(),
|
||||
DistinctOS.Linux => new UnixMonoLLManager(),
|
||||
DistinctOS.macOS => new UnixMonoLLManager(),
|
||||
DistinctOS.Windows => new WindowsLLManager(),
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
|
@ -130,8 +128,8 @@ namespace BizHawk.Common
|
|||
/// <param name="checkStdout">stdout is discarded if false</param>
|
||||
/// <param name="checkStderr">stderr is discarded if false</param>
|
||||
/// <remarks>OS is implicit and needs to be checked at callsite. Returned <see cref="Process"/> has not been started.</remarks>
|
||||
public static Process ConstructSubshell(string cmd, string args, bool checkStdout = true, bool checkStderr = false) =>
|
||||
new Process {
|
||||
public static Process ConstructSubshell(string cmd, string args, bool checkStdout = true, bool checkStderr = false)
|
||||
=> new Process {
|
||||
StartInfo = new ProcessStartInfo {
|
||||
Arguments = args,
|
||||
CreateNoWindow = true,
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
#nullable disable
|
||||
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Reflection.Emit;
|
||||
|
@ -13,18 +11,26 @@ namespace BizHawk.Common
|
|||
{
|
||||
private sealed class DefaultValueSetter
|
||||
{
|
||||
public Action<object, object[]> SetDefaultValues;
|
||||
public object[] DefaultValues;
|
||||
public readonly Action<object, object[]> SetDefaultValues;
|
||||
|
||||
public readonly object[] DefaultValues;
|
||||
|
||||
public DefaultValueSetter(Action<object, object[]> setDefaultValues, object[] defaultValues)
|
||||
{
|
||||
SetDefaultValues = setDefaultValues;
|
||||
DefaultValues = defaultValues;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static IDictionary<Type, DefaultValueSetter> DefaultValueSetters = new ConcurrentDictionary<Type, DefaultValueSetter>();
|
||||
private static readonly IDictionary<Type, DefaultValueSetter> DefaultValueSetters = new ConcurrentDictionary<Type, DefaultValueSetter>();
|
||||
|
||||
/// <summary>
|
||||
/// set all properties (not fields!) of obj with a DefaultValueAttribute to that value
|
||||
/// </summary>
|
||||
/// <param name="obj">the obj to act on</param>
|
||||
public static void SetDefaultValues<T>(T obj)
|
||||
where T : notnull
|
||||
{
|
||||
if (!DefaultValueSetters.TryGetValue(typeof(T), out var f))
|
||||
{
|
||||
|
@ -34,7 +40,7 @@ namespace BizHawk.Common
|
|||
f.SetDefaultValues(obj, f.DefaultValues);
|
||||
}
|
||||
|
||||
private static Dictionary<Type, OpCode> IntTypes = new Dictionary<Type,OpCode>
|
||||
private static readonly Dictionary<Type, OpCode> IntTypes = new Dictionary<Type,OpCode>
|
||||
{
|
||||
{ typeof(byte), OpCodes.Conv_U1 },
|
||||
{ typeof(sbyte), OpCodes.Conv_I1 },
|
||||
|
@ -64,9 +70,9 @@ namespace BizHawk.Common
|
|||
MethodInfo method = prop.GetSetMethod(true);
|
||||
foreach (object attr in prop.GetCustomAttributes(true))
|
||||
{
|
||||
if (attr is DefaultValueAttribute)
|
||||
if (attr is DefaultValueAttribute dvAttr)
|
||||
{
|
||||
object value = (attr as DefaultValueAttribute).Value;
|
||||
var value = dvAttr.Value;
|
||||
Type desiredType = method.GetParameters()[0].ParameterType;
|
||||
Type sourceType = value.GetType();
|
||||
|
||||
|
@ -98,11 +104,10 @@ namespace BizHawk.Common
|
|||
}
|
||||
il.Emit(OpCodes.Pop);
|
||||
il.Emit(OpCodes.Ret);
|
||||
return new DefaultValueSetter
|
||||
{
|
||||
SetDefaultValues = (Action<object, object[]>)dyn.CreateDelegate(typeof(Action<object, object[]>)),
|
||||
DefaultValues = DefaultValues.ToArray()
|
||||
};
|
||||
return new DefaultValueSetter(
|
||||
(Action<object, object[]>) dyn.CreateDelegate(typeof(Action<object, object[]>)),
|
||||
DefaultValues.ToArray()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
#nullable disable
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace BizHawk.Common
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
#nullable disable
|
||||
|
||||
namespace BizHawk.Common
|
||||
{
|
||||
/// <remarks>This code (and an import for <see cref="Win32Imports.DeleteFileW"/>) is duplicated in each executable project because it needs to be used before loading assemblies.</remarks>
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
#nullable disable
|
||||
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace BizHawk.Common
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#nullable disable
|
||||
#nullable enable
|
||||
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
|
@ -14,7 +14,7 @@ internal static class VersionInfo
|
|||
public const string HomePage = "http://tasvideos.org/BizHawk.html";
|
||||
public static readonly bool DeveloperBuild = true;
|
||||
|
||||
public static readonly string CustomBuildString;
|
||||
public static readonly string? CustomBuildString;
|
||||
|
||||
public static string GetEmuVersion()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue