Skip to content

Commit f2a8d36

Browse files
committed
style: nullable
[skip changelog]
1 parent 3afc19f commit f2a8d36

File tree

4 files changed

+19
-21
lines changed

4 files changed

+19
-21
lines changed

src/MaaWpfGui/Configuration/ConfigFactory.cs

+10-10
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
// This program is distributed in the hope that it will be useful,
1111
// but WITHOUT ANY WARRANTY
1212
// </copyright>
13-
13+
#nullable enable
1414
using System;
1515
using System.Collections.Generic;
1616
using System.Collections.Specialized;
@@ -44,10 +44,10 @@ public static class ConfigFactory
4444

4545
private static readonly SemaphoreSlim _semaphore = new(1, 1);
4646

47-
public delegate void ConfigurationUpdateEventHandler(string key, object oldValue, object newValue);
47+
public delegate void ConfigurationUpdateEventHandler(string key, object? oldValue, object? newValue);
4848

4949
// ReSharper disable once EventNeverSubscribedTo.Global
50-
public static event ConfigurationUpdateEventHandler ConfigurationUpdateEvent;
50+
public static event ConfigurationUpdateEventHandler? ConfigurationUpdateEvent;
5151

5252
private static readonly JsonSerializerOptions _options = new() { WriteIndented = true, Converters = { new JsonStringEnumConverter() }, Encoder = JavaScriptEncoder.Create(UnicodeRanges.BasicLatin, UnicodeRanges.CjkUnifiedIdeographs, UnicodeRanges.CjkSymbolsandPunctuation, UnicodeRanges.HalfwidthandFullwidthForms), DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull };
5353

@@ -61,7 +61,7 @@ public static class ConfigFactory
6161
Directory.CreateDirectory("config");
6262
}
6363

64-
Root parsed = null;
64+
Root? parsed = null;
6565
if (File.Exists(_configurationFile))
6666
{
6767
try
@@ -195,7 +195,7 @@ void SpecificConfigBind(string name, SpecificConfig config)
195195
}
196196
});
197197

198-
private static PropertyChangedEventHandler OnPropertyChangedFactory(string key, object oldValue, object newValue)
198+
private static PropertyChangedEventHandler OnPropertyChangedFactory(string key, object? oldValue, object? newValue)
199199
{
200200
return (o, args) =>
201201
{
@@ -213,7 +213,7 @@ private static PropertyChangedEventHandler OnPropertyChangedFactory(string key =
213213
{
214214
return (o, args) =>
215215
{
216-
object after = null;
216+
object? after = null;
217217
if (args is PropertyChangedEventDetailArgs detailArgs)
218218
{
219219
after = detailArgs.NewValue;
@@ -236,7 +236,7 @@ private static NotifyCollectionChangedEventHandler<KeyValuePair<T1, T2>> OnColle
236236

237237
public static readonly SpecificConfig CurrentConfig = Root.CurrentConfig;
238238

239-
private static async void OnPropertyChanged(string key, object oldValue, object newValue)
239+
private static async void OnPropertyChanged(string key, object? oldValue, object? newValue)
240240
{
241241
var result = await SaveAsync();
242242
if (result)
@@ -250,7 +250,7 @@ private static async void OnPropertyChanged(string key, object oldValue, object
250250
}
251251
}
252252

253-
private static bool Save(string file = null)
253+
private static bool Save(string? file = null)
254254
{
255255
lock (_lock)
256256
{
@@ -268,7 +268,7 @@ private static bool Save(string file = null)
268268
}
269269
}
270270

271-
private static async Task<bool> SaveAsync(string file = null)
271+
private static async Task<bool> SaveAsync(string? file = null)
272272
{
273273
await _semaphore.WaitAsync();
274274
try
@@ -325,7 +325,7 @@ public static bool SwitchConfig(string configName)
325325
return true;
326326
}
327327

328-
public static bool AddConfiguration(string configName, string copyFrom = null)
328+
public static bool AddConfiguration(string configName, string? copyFrom = null)
329329
{
330330
if (string.IsNullOrEmpty(configName))
331331
{

src/MaaWpfGui/Configuration/PropertyChangedEventDetailArgs.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
// This program is distributed in the hope that it will be useful,
1111
// but WITHOUT ANY WARRANTY
1212
// </copyright>
13-
13+
#nullable enable
1414
using System.ComponentModel;
1515

1616
namespace MaaWpfGui.Configuration

src/MaaWpfGui/Configuration/Root.cs

+4-5
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
// This program is distributed in the hope that it will be useful,
1111
// but WITHOUT ANY WARRANTY
1212
// </copyright>
13-
14-
using System.Collections.Generic;
13+
#nullable enable
1514
using System.ComponentModel;
1615
using System.Text.Json.Serialization;
1716
using ObservableCollections;
@@ -20,13 +19,13 @@ namespace MaaWpfGui.Configuration
2019
{
2120
public class Root : INotifyPropertyChanged
2221
{
23-
public event PropertyChangedEventHandler PropertyChanged;
22+
public event PropertyChangedEventHandler? PropertyChanged;
2423

2524
[JsonInclude]
26-
public ObservableDictionary<string, SpecificConfig> Configurations { get; private set; } = new ObservableDictionary<string, SpecificConfig>();
25+
public ObservableDictionary<string, SpecificConfig> Configurations { get; private set; } = [];
2726

2827
[JsonInclude]
29-
public ObservableDictionary<int, Timer> Timers { get; private set; } = new ObservableDictionary<int, Timer>();
28+
public ObservableDictionary<int, Timer> Timers { get; private set; } = [];
3029

3130
public string Current { get; set; } = "Default";
3231

src/MaaWpfGui/Configuration/VersionUpdate.cs

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// <copyright file="VersionUpdate.cs" company="MaaAssistantArknights">
1+
// <copyright file="VersionUpdate.cs" company="MaaAssistantArknights">
22
// MaaWpfGui - A part of the MaaCoreArknights project
33
// Copyright (C) 2021 MistEO and Contributors
44
//
@@ -10,15 +10,14 @@
1010
// This program is distributed in the hope that it will be useful,
1111
// but WITHOUT ANY WARRANTY
1212
// </copyright>
13-
14-
using System;
13+
#nullable enable
1514
using System.ComponentModel;
1615

1716
namespace MaaWpfGui.Configuration
1817
{
1918
public class VersionUpdate : INotifyPropertyChanged
2019
{
21-
public event PropertyChangedEventHandler PropertyChanged;
20+
public event PropertyChangedEventHandler? PropertyChanged;
2221

2322
// The following should not be modified manually
2423
public string Name { get; set; } = string.Empty;
@@ -61,7 +60,7 @@ public enum UpdateVersionType
6160
/// <summary>
6261
/// 开发版
6362
/// </summary>
64-
Beta
63+
Beta,
6564
}
6665
}
6766
}

0 commit comments

Comments
 (0)