Skip to content

Commit fa75f32

Browse files
committed
fix some nullability warnings
1 parent 42539b7 commit fa75f32

18 files changed

+44
-50
lines changed

src/BizHawk.BizInvoke/BizInvoker.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ private static ParameterLoadInfo EmitParamterLoad(ILGenerator il, int idx, Type
584584
il.Emit(OpCodes.Brfalse, isNull);
585585

586586
var encoding = il.DeclareLocal(typeof(Encoding), false);
587-
il.EmitCall(OpCodes.Call, typeof(Encoding).GetProperty("UTF8")!.GetGetMethod(), Type.EmptyTypes);
587+
il.EmitCall(OpCodes.Call, typeof(Encoding).GetProperty("UTF8")!.GetGetMethod()!, Type.EmptyTypes);
588588
il.Emit(OpCodes.Stloc, encoding);
589589

590590
var strlenbytes = il.DeclareLocal(typeof(int), false);
@@ -616,7 +616,7 @@ private static ParameterLoadInfo EmitParamterLoad(ILGenerator il, int idx, Type
616616
il.Emit(OpCodes.Add);
617617
// charcount
618618
il.Emit(OpCodes.Ldloc, strval);
619-
il.Emit(OpCodes.Call, typeof(string).GetProperty("Length")!.GetGetMethod());
619+
il.Emit(OpCodes.Call, typeof(string).GetProperty("Length")!.GetGetMethod()!);
620620
// bytes
621621
il.Emit(OpCodes.Ldloc, bytes);
622622
// bytelength

src/BizHawk.BizInvoke/BizInvokerUtilities.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ private class CF
5858
/// </summary>
5959
/// <returns></returns>
6060
public static int ComputeClassFirstFieldOffset()
61-
=> ComputeFieldOffset(typeof(CF).GetField("FirstField"));
61+
=> ComputeFieldOffset(typeof(CF).GetField("FirstField")!);
6262

6363
/// <summary>
6464
/// Compute the byte offset of the first byte of string data (UTF16) relative to a pointer to the string.

src/BizHawk.BizInvoke/CallingConventionAdapter.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ private class WaterboxAdapter : ICallingConventionAdapter
144144
{
145145
private class ReferenceEqualityComparer : IEqualityComparer<Delegate>
146146
{
147-
public bool Equals(Delegate x, Delegate y)
147+
public bool Equals(Delegate? x, Delegate? y)
148148
=> x == y;
149149

150150
public int GetHashCode(Delegate obj)

src/BizHawk.Client.Common/Api/Classes/CommApi.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ public sealed class CommApi : ICommApi
2020

2121
public string? HttpTest() => HTTP == null ? null : string.Join("\n", HttpTestGet(), HTTP.SendScreenshot(), "done testing");
2222

23-
public string? HttpTestGet() => HTTP?.Get(HTTP.GetUrl)?.Result;
23+
public string? HttpTestGet() => HttpCommunication.Get(HTTP?.GetUrl)?.Result;
2424
}
2525
}

src/BizHawk.Client.Common/Api/ClientWebSocketWrapper.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ public Task Close(WebSocketCloseStatus closeStatus, string statusDescription, Ca
3232
return task;
3333
}
3434

35-
/// <summary>calls <see cref="ClientWebSocket.ReceiveAsync"/></summary>
35+
/// <summary>calls <see cref="ClientWebSocket.ReceiveAsync(System.ArraySegment{byte}, CancellationToken)"/></summary>
3636
public Task<WebSocketReceiveResult> Receive(ArraySegment<byte> buffer, CancellationToken? cancellationToken = null)
3737
=> _w?.ReceiveAsync(buffer, cancellationToken ?? CancellationToken.None)
3838
?? throw new ObjectDisposedException(nameof(_w));
3939

40-
/// <summary>calls <see cref="ClientWebSocket.ReceiveAsync"/></summary>
40+
/// <summary>calls <see cref="ClientWebSocket.ReceiveAsync(System.ArraySegment{byte}, CancellationToken)"/></summary>
4141
public string Receive(int bufferCap, CancellationToken? cancellationToken = null)
4242
{
4343
if (_w == null) throw new ObjectDisposedException(nameof(_w));
@@ -46,12 +46,12 @@ public string Receive(int bufferCap, CancellationToken? cancellationToken = null
4646
return Encoding.UTF8.GetString(buffer, 0, result.Count);
4747
}
4848

49-
/// <summary>calls <see cref="ClientWebSocket.SendAsync"/></summary>
49+
/// <summary>calls <see cref="ClientWebSocket.SendAsync(System.ArraySegment{byte}, WebSocketMessageType, bool, CancellationToken)"/></summary>
5050
public Task Send(ArraySegment<byte> buffer, WebSocketMessageType messageType, bool endOfMessage, CancellationToken? cancellationToken = null)
5151
=> _w?.SendAsync(buffer, messageType, endOfMessage, cancellationToken ?? CancellationToken.None)
5252
?? throw new ObjectDisposedException(nameof(_w));
5353

54-
/// <summary>calls <see cref="ClientWebSocket.SendAsync"/></summary>
54+
/// <summary>calls <see cref="ClientWebSocket.SendAsync(System.ArraySegment{byte}, WebSocketMessageType, bool, CancellationToken)"/></summary>
5555
public Task Send(string message, bool endOfMessage, CancellationToken? cancellationToken = null)
5656
{
5757
if (_w == null) throw new ObjectDisposedException(nameof(_w));

src/BizHawk.Client.Common/Api/HttpCommunication.cs

+8-8
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace BizHawk.Client.Common
77
{
88
public sealed class HttpCommunication
99
{
10-
private readonly HttpClient _client = new HttpClient();
10+
public static readonly HttpClient Client = new HttpClient();
1111

1212
private readonly Func<byte[]> _takeScreenshotCallback;
1313

@@ -33,24 +33,24 @@ public string ExecPost(string url = null, string payload = "") => Post(
3333
new FormUrlEncodedContent(new Dictionary<string, string> { ["payload"] = payload })
3434
).Result;
3535

36-
public async Task<string> Get(string url)
36+
public static async Task<string> Get(string url)
3737
{
38-
_client.DefaultRequestHeaders.ConnectionClose = false;
39-
var response = await _client.GetAsync(url).ConfigureAwait(false);
38+
Client.DefaultRequestHeaders.ConnectionClose = false;
39+
var response = await Client.GetAsync(url).ConfigureAwait(false);
4040
if (response.IsSuccessStatusCode)
4141
{
4242
return await response.Content.ReadAsStringAsync();
4343
}
4444
return null;
4545
}
4646

47-
public async Task<string> Post(string url, FormUrlEncodedContent content)
47+
public static async Task<string> Post(string url, FormUrlEncodedContent content)
4848
{
49-
_client.DefaultRequestHeaders.ConnectionClose = true;
49+
Client.DefaultRequestHeaders.ConnectionClose = true;
5050
HttpResponseMessage response;
5151
try
5252
{
53-
response = await _client.PostAsync(url, content).ConfigureAwait(false);
53+
response = await Client.PostAsync(url, content).ConfigureAwait(false);
5454
}
5555
catch (Exception e)
5656
{
@@ -87,7 +87,7 @@ public void SetTimeout(int timeout)
8787

8888
if (timeout != 0)
8989
{
90-
_client.Timeout = new TimeSpan(0, 0, 0, timeout / 1000, timeout % 1000);
90+
Client.Timeout = new TimeSpan(0, 0, 0, timeout / 1000, timeout % 1000);
9191
Timeout = timeout;
9292
}
9393
}

src/BizHawk.Client.EmuHawk/AVOut/FFmpegDownloaderForm.cs

-1
Original file line numberDiff line numberDiff line change
@@ -160,4 +160,3 @@ private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs
160160
}
161161
}
162162
}
163-

src/BizHawk.Client.EmuHawk/BizHawk.Client.EmuHawk.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
</PropertyGroup>
1414
<ItemGroup>
1515
<PackageReference Include="System.Net.Http" Version="4.3.4" />
16-
<Reference Include="System.IO.Compression" />
16+
<Reference Condition="$(IsTargetingNetFramework)" Include="System.IO.Compression" />
1717
</ItemGroup>
1818
<ItemGroup>
1919
<Reference Include="PcxFileTypePlugin.HawkQuantizer" HintPath="$(ProjectDir)../../References/PcxFileTypePlugin.HawkQuantizer.dll" Private="true" />

src/BizHawk.Client.EmuHawk/UpdateChecker.cs

+1-6
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,7 @@ private static void CheckInternal()
9090

9191
private static string DownloadURLAsString(string url)
9292
{
93-
var request = (HttpWebRequest)WebRequest.Create(url);
94-
request.UserAgent = "BizHawk";
95-
request.KeepAlive = false;
96-
using var response = (HttpWebResponse)request.GetResponse();
97-
using var responseStream = new StreamReader(response.GetResponseStream());
98-
return responseStream.ReadToEnd();
93+
return HttpCommunication.Get(url).Result;
9994
}
10095

10196
private static string ValidateVersionNumberString(string versionNumber)

src/BizHawk.Client.EmuHawk/tools/VirtualPads/controls/VirtualPadAnalogStick.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ public VirtualPadAnalogStick(
7878
AnalogStick.ClearCallback = ClearCallback;
7979
manualR.Maximum = Math.Max(RectToPolarHelper(RangeX.Max, RangeY.Max).R, RectToPolarHelper(RangeX.Min, RangeY.Min).R);
8080

81-
void UnsetLastFocusedNUD(object sender, EventArgs eventArgs)
82-
=> setLastFocusedNUD(null, null);
81+
void UnsetLastFocusedNUD(object? sender, EventArgs eventArgs)
82+
=> setLastFocusedNUD(null, EventArgs.Empty);
8383
ManualX.ValueChanged += ManualXY_ValueChanged;
8484
ManualX.GotFocus += setLastFocusedNUD;
8585
ManualX.LostFocus += UnsetLastFocusedNUD;
@@ -191,7 +191,7 @@ public void Bump(int? x, int? y)
191191

192192
public void SetPrevious(IController previous) => AnalogStick.SetPrevious(previous);
193193

194-
private void ManualXY_ValueChanged(object sender, EventArgs e)
194+
private void ManualXY_ValueChanged(object? sender, EventArgs e)
195195
{
196196
if (_updatingFromAnalog || _updatingFromPolar) return;
197197
_updatingFromXY = true;
@@ -208,7 +208,7 @@ private void ManualXY_ValueChanged(object sender, EventArgs e)
208208
private void MaxManualXY_ValueChanged(object sender, EventArgs e)
209209
=> AnalogStick.SetUserRange((int) MaxXNumeric.Value, (int) MaxYNumeric.Value);
210210

211-
private void PolarNumeric_Changed(object sender, EventArgs e)
211+
private void PolarNumeric_Changed(object? sender, EventArgs e)
212212
{
213213
if (_updatingFromAnalog || _updatingFromXY) return;
214214
_updatingFromPolar = true;

src/BizHawk.Common/Extensions/CollectionExtensions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ public static TValue GetValueOrPutNew<TKey, TValue>(this IDictionary<TKey, TValu
203203
/// I suppose it's not that important because it's called on cache miss --yoshi
204204
/// </remarks>
205205
public static TValue GetValueOrPutNew1<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key)
206-
=> dictionary.GetValueOrPut(key, static k => (TValue) Activator.CreateInstance(typeof(TValue), k));
206+
=> dictionary.GetValueOrPut(key, static k => (TValue) Activator.CreateInstance(typeof(TValue), k)!);
207207

208208
/// <inheritdoc cref="IList{T}.IndexOf"/>
209209
/// <remarks>

src/BizHawk.Common/PropertyGridConverters/ConstrainedFloatConverter.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ namespace BizHawk.Common
1212
/// </summary>
1313
public class ConstrainedFloatConverter : TypeConverter
1414
{
15-
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
15+
public override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType)
1616
{
1717
return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
1818
}
1919

20-
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
20+
public override object ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object value)
2121
{
2222
var range = (RangeAttribute)context.Instance
2323
.GetType()
@@ -40,7 +40,7 @@ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo c
4040
throw new FormatException($"Invalid value: {value}, {context.PropertyDescriptor.Name} must be a float.");
4141
}
4242

43-
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
43+
public override object ConvertTo(ITypeDescriptorContext? context, CultureInfo? culture, object? value, Type destinationType)
4444
{
4545
if (destinationType == null)
4646
{

src/BizHawk.Common/PropertyGridConverters/ConstrainedIntConverter.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ namespace BizHawk.Common
1212
/// </summary>
1313
public class ConstrainedIntConverter : TypeConverter
1414
{
15-
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
15+
public override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType)
1616
{
1717
return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
1818
}
1919

20-
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
20+
public override object ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object value)
2121
{
2222
var range = (RangeAttribute)context.Instance
2323
.GetType()
@@ -40,7 +40,7 @@ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo c
4040
throw new FormatException($"Invalid value: {value}, {context.PropertyDescriptor.Name} must be an integer.");
4141
}
4242

43-
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
43+
public override object ConvertTo(ITypeDescriptorContext? context, CultureInfo? culture, object? value, Type destinationType)
4444
{
4545
if (destinationType == null)
4646
{

src/BizHawk.Common/PropertyGridConverters/ConstrainedStringConverter.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ namespace BizHawk.Common
1212
/// </summary>
1313
public class ConstrainedStringConverter : TypeConverter
1414
{
15-
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
15+
public override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType)
1616
{
1717
return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
1818
}
1919

20-
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
20+
public override object ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object value)
2121
{
2222
var maxLength = (MaxLengthAttribute)context.Instance
2323
.GetType()
@@ -32,7 +32,7 @@ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo c
3232
throw new FormatException($"{context.PropertyDescriptor.Name} can not be null");
3333
}
3434

35-
return value.ToString();
35+
return value.ToString()!;
3636
}
3737
}
3838
}

src/BizHawk.Common/PropertyGridConverters/DescribableEnumConverter.cs

+8-8
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ public DescribableEnumConverter(Type type) : base(type)
1616
enumType = type;
1717
}
1818

19-
public override bool CanConvertFrom(ITypeDescriptorContext context, Type srcType) => srcType == typeof(string);
19+
public override bool CanConvertFrom(ITypeDescriptorContext? context, Type srcType) => srcType == typeof(string);
2020

21-
public override bool CanConvertTo(ITypeDescriptorContext context, Type destType) => destType == typeof(string);
21+
public override bool CanConvertTo(ITypeDescriptorContext? context, Type? destType) => destType == typeof(string);
2222

23-
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
23+
public override object ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object value)
2424
{
2525
var valueStr = value?.ToString() ?? throw new ArgumentNullException(paramName: nameof(value));
2626
return Enum.Parse(
@@ -31,7 +31,7 @@ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo c
3131
);
3232
}
3333

34-
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destType)
34+
public override object ConvertTo(ITypeDescriptorContext? context, CultureInfo? culture, object? value, Type destType)
3535
{
3636
var fieldName = Enum.GetName(enumType, value ?? throw new ArgumentNullException(paramName: nameof(value)));
3737
if (fieldName != null)
@@ -44,17 +44,17 @@ public override object ConvertTo(ITypeDescriptorContext context, CultureInfo cul
4444
}
4545
}
4646

47-
return value.ToString();
47+
return value.ToString()!;
4848
}
4949

50-
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) => new(
50+
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext? context) => new(
5151
enumType.GetFields(BindingFlags.Public | BindingFlags.Static)
5252
.Select(fi => fi.GetValue(null))
5353
.ToList()
5454
);
5555

56-
public override bool GetStandardValuesExclusive(ITypeDescriptorContext context) => true;
56+
public override bool GetStandardValuesExclusive(ITypeDescriptorContext? context) => true;
5757

58-
public override bool GetStandardValuesSupported(ITypeDescriptorContext context) => true;
58+
public override bool GetStandardValuesSupported(ITypeDescriptorContext? context) => true;
5959
}
6060
}

src/BizHawk.Common/Util.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public static IEnumerable<Type> GetTypesWithoutLoadErrors(this Assembly assembly
122122
}
123123
catch (ReflectionTypeLoadException e)
124124
{
125-
return e.Types.Where(t => t != null);
125+
return e.Types.Where(t => t != null)!;
126126
}
127127
}
128128

src/BizHawk.Emulation.Common/Database/FirmwareID.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public FirmwareID(string system, string firmware)
2020
Firmware = firmware;
2121
}
2222

23-
public override bool Equals(object obj) => obj is FirmwareID other
23+
public override bool Equals(object? obj) => obj is FirmwareID other
2424
&& other.Firmware == Firmware && other.System == System;
2525

2626
public override int GetHashCode() => (System, Firmware).GetHashCode();

src/BizHawk.Emulation.Common/VSystemID.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public static class Raw
7878

7979
private static List<string> AllSysIDs
8080
=> _allSysIDs ??= typeof(Raw).GetFields(BindingFlags.Public | BindingFlags.Static)
81-
.Select(x => (string) x.GetRawConstantValue())
81+
.Select(x => (string) x.GetRawConstantValue()!)
8282
.Order().ToList();
8383

8484
/// <returns><paramref name="sysID"/> iff it's in <see cref="Raw">the valid list</see>, else <see langword="null"/></returns>

0 commit comments

Comments
 (0)