Skip to content

Commit

Permalink
使用 NET8 新语法
Browse files Browse the repository at this point in the history
  • Loading branch information
laolarou726 committed Nov 16, 2023
1 parent 2ba95be commit aeb4447
Show file tree
Hide file tree
Showing 13 changed files with 24 additions and 25 deletions.
2 changes: 1 addition & 1 deletion ProjBobcat/ProjBobcat/Class/Helper/DownloadHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ public static async Task MultiPartDownloadTaskAsync(

#region Calculate ranges

readRanges = new List<DownloadRange>();
readRanges = [];
var partSize = responseLength / downloadSettings.DownloadParts;
var totalSize = responseLength;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,11 @@ public static async IAsyncEnumerable<GameModResolvedInfo> ResolveModListAsync(IE
case JsonValueKind.Object:
var val = doc.RootElement.Deserialize(GameModInfoModelContext.Default.GameModInfoModel);

if (val != null) model = new List<GameModInfoModel> { val };
if (val != null) model = [val];

break;
case JsonValueKind.Array:
model = doc.RootElement.Deserialize(GameModInfoModelContext.Default.ListGameModInfoModel) ??
new List<GameModInfoModel>();
model = doc.RootElement.Deserialize(GameModInfoModelContext.Default.ListGameModInfoModel) ?? [];
break;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class GameConfigurationManager : IEnumerable<KeyValuePair<string, string>

public GameConfigurationManager()
{
_configuration = new Dictionary<string, string>();
_configuration = [];
}

public GameConfigurationManager(string path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class ComparableVersion : IComparable<ComparableVersion>
const int MaxIntItemLength = 9;
const int MaxLongItemLength = 18;

readonly ListItem _items = new();
readonly ListItem _items = [];

string? _canonical;
string _value = null!;
Expand Down Expand Up @@ -104,7 +104,7 @@ void ParseVersion(string version)
: ParseItem(isDigit, version[startIndex..i]));
startIndex = i + 1;

list.Add(list = new ListItem());
list.Add(list = []);
stack.Push(list);
break;
default:
Expand All @@ -116,7 +116,7 @@ void ParseVersion(string version)
list.Add(new StringItem(version[startIndex..i], true));
startIndex = i;

list.Add(list = new ListItem());
list.Add(list = []);
stack.Push(list);
}

Expand All @@ -129,7 +129,7 @@ void ParseVersion(string version)
list.Add(ParseItem(true, version[startIndex..i]));
startIndex = i;

list.Add(list = new ListItem());
list.Add(list = []);
stack.Push(list);
}

Expand Down
6 changes: 3 additions & 3 deletions ProjBobcat/ProjBobcat/Class/Model/Version/Item/StringItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ namespace ProjBobcat.Class.Model.Version.Item;

public class StringItem : IItem
{
static readonly List<string> Qualifiers = new()
{
static readonly List<string> Qualifiers =
[
"alpha",
"beta",
"milestone",
"rc",
"snapshot",
Empty,
"sp"
};
];

static readonly Dictionary<string, string> Aliases = new()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class DefaultResourceCompleter : IResourceCompleter
static readonly object ChangedEventKey = new();
static readonly object CompletedEventKey = new();

readonly ConcurrentBag<DownloadFile> _failedFiles = new();
readonly ConcurrentBag<DownloadFile> _failedFiles = [];
readonly EventHandlerList _listEventDelegates = new();

bool _disposedValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ static readonly Regex

#endif

readonly ConcurrentBag<DownloadFile> _failedFiles = new();
readonly ConcurrentBag<DownloadFile> _failedFiles = [];
int _totalDownloaded, _needToDownload, _totalProcessed, _needToProcess;

public string? JavaExecutablePath { get; init; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace ProjBobcat.DefaultComponent.Installer.ModPackInstaller;

public class ModPackInstallerBase : InstallerBase
{
protected readonly ConcurrentBag<DownloadFile> FailedFiles = new();
protected readonly ConcurrentBag<DownloadFile> FailedFiles = [];
protected int TotalDownloaded, NeedToDownload;

protected void WhenCompleted(object? sender, DownloadFileCompletedEventArgs e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public DefaultLauncherAccountParser(string rootPath, Guid clientToken)
{
var launcherAccount = new LauncherAccountModel
{
Accounts = new Dictionary<string, AccountModel>(),
Accounts = [],
MojangClientToken = clientToken.ToString("N")
};

Expand Down Expand Up @@ -74,7 +74,7 @@ public bool AddNewAccount(string uuid, AccountModel account, out Guid? id)
return false;
}

LauncherAccount.Accounts ??= new Dictionary<string, AccountModel>();
LauncherAccount.Accounts ??= [];

if (LauncherAccount.Accounts.ContainsKey(uuid))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public DefaultLauncherProfileParser(string rootPath, Guid clientToken)
Format = 1,
Name = string.Empty
},
Profiles = new Dictionary<string, GameProfileModel>()
Profiles = []
};

LauncherProfile = launcherProfile;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ public override (List<NativeFileInfo>, List<FileInfo>) GetNatives(IEnumerable<Li
// 存在继承关系。
// Inheritance exists.

inherits = new List<RawVersionModel?>();
inherits = [];
var current = rawVersion;
var first = true;

Expand Down Expand Up @@ -370,8 +370,8 @@ public override (List<NativeFileInfo>, List<FileInfo>) GetNatives(IEnumerable<Li
Assets = rawVersion.AssetsVersion,
AssetInfo = rawVersion.AssetIndex,
MainClass = rawVersion.MainClass,
Libraries = new List<FileInfo>(),
Natives = new List<NativeFileInfo>(),
Libraries = [],
Natives = [],
Logging = rawVersion.Logging,
Id = rawVersion.Id,
DirName = id,
Expand Down Expand Up @@ -484,11 +484,11 @@ public override (List<NativeFileInfo>, List<FileInfo>) GetNatives(IEnumerable<Li
result.MainClass = inherits[i]!.MainClass ?? result.MainClass;
}

var finalJvmArgs = result.JvmArguments?.ToList() ?? new List<string>();
var finalJvmArgs = result.JvmArguments?.ToList() ?? [];
finalJvmArgs.AddRange(jvmArgList);
result.JvmArguments = finalJvmArgs;

var finalGameArgs = result.GameArguments?.ToList() ?? new List<string>();
var finalGameArgs = result.GameArguments?.ToList() ?? [];
finalGameArgs.AddRange(gameArgList);
finalGameArgs = finalGameArgs.Select(arg => arg.Split(' ')).SelectMany(a => a).Distinct().ToList();
result.GameArguments = finalGameArgs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public IEnumerable<IAnalysisReport> GenerateReport()
foreach (var (logFileType, lines) in GetAllLogs())
{
if (!logs.ContainsKey(logFileType))
logs[logFileType] = new List<(string, string)>();
logs[logFileType] = [];

logs[logFileType].Add(lines);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public ServerPingResult Run()
return null;
}

_buffer = new List<byte>();
_buffer = [];
_stream = client.GetStream();

InvokeStatusChangedEvent("发送请求...", 30);
Expand Down

0 comments on commit aeb4447

Please sign in to comment.