Skip to content

Commit 0d2f7b4

Browse files
authored
Migrate to .NET 8.0 (#277)
1 parent 0c647eb commit 0d2f7b4

20 files changed

+46
-87
lines changed

nanoFirmwareFlasher.Library/CC13x26x2Firmware.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
// See LICENSE file in the project root for full license information.
44
//
55

6-
using System.IO;
7-
using System.Linq;
8-
96
namespace nanoFramework.Tools.FirmwareFlasher
107
{
118
/// <summary>

nanoFirmwareFlasher.Library/CC13x26x2Operations.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using System.Collections.Generic;
88
using System.Diagnostics;
99
using System.IO;
10-
using System.Linq;
1110

1211
namespace nanoFramework.Tools.FirmwareFlasher
1312
{
@@ -119,15 +118,15 @@ public static async System.Threading.Tasks.Task<ExitCodes> UpdateFirmwareAsync(
119118

120119
ExitCodes programResult = ExitCodes.OK;
121120
// write HEX files to flash
122-
if (filesToFlash.Any(f => f.EndsWith(".hex")))
121+
if (filesToFlash.Exists(f => f.EndsWith(".hex")))
123122
{
124123
programResult = ccDevice.FlashHexFiles(filesToFlash);
125124
}
126125

127126
if (programResult == ExitCodes.OK && isApplicationBinFile)
128127
{
129128
// now program the application file
130-
programResult = ccDevice.FlashBinFiles(new List<string> { applicationPath }, new List<string> { deploymentAddress });
129+
programResult = ccDevice.FlashBinFiles([applicationPath], [deploymentAddress]);
131130
}
132131

133132
if (updateFw)

nanoFirmwareFlasher.Library/Esp32Firmware.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ internal class Esp32Firmware : FirmwarePackage
2424
/// <summary>
2525
/// ESP32 nanoCLR is available for 2MB, 4MB, 8MB and 16MB flash sizes
2626
/// </summary>
27-
private List<int> SupportedFlashSizes => new() { 0x200000, 0x400000, 0x800000, 0x1000000 };
27+
private List<int> SupportedFlashSizes => [0x200000, 0x400000, 0x800000, 0x1000000];
2828

2929
internal string BootloaderPath;
3030

nanoFirmwareFlasher.Library/Esp32Operations.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ public static async System.Threading.Tasks.Task<ExitCodes> UpdateFirmwareAsync(
450450
// check for empty flash partitions
451451
if (firmware.FlashPartitions is null)
452452
{
453-
firmware.FlashPartitions = new Dictionary<int, string>();
453+
firmware.FlashPartitions = [];
454454
}
455455

456456
// add DEPLOYMENT partition with the address provided in the command OR the address from the partition table
@@ -504,7 +504,7 @@ public static async System.Threading.Tasks.Task<ExitCodes> UpdateFirmwareAsync(
504504

505505
int configPartitionAddress = 0;
506506
int configPartitionSize = 0;
507-
string configPartitionBackup = Path.GetTempFileName();
507+
string configPartitionBackup = Path.GetRandomFileName();
508508

509509
// if mass erase wasn't requested, backup config partitition
510510
if (!massErase)
@@ -613,7 +613,6 @@ public static async System.Threading.Tasks.Task<ExitCodes> DeployApplicationAsyn
613613
VerbosityLevel verbosity,
614614
PartitionTableSize? partitionTableSize)
615615
{
616-
var operationResult = ExitCodes.OK;
617616
uint address = 0;
618617

619618
// perform sanity checks for the specified target against the connected device details
@@ -665,7 +664,7 @@ public static async System.Threading.Tasks.Task<ExitCodes> DeployApplicationAsyn
665664
// check for empty flash partitions
666665
if (firmware.FlashPartitions is null)
667666
{
668-
firmware.FlashPartitions = new Dictionary<int, string>();
667+
firmware.FlashPartitions = [];
669668
}
670669

671670
// add DEPLOYMENT partition with the address provided in the command OR the address from the partition table
@@ -688,7 +687,7 @@ public static async System.Threading.Tasks.Task<ExitCodes> DeployApplicationAsyn
688687
}
689688

690689
// write to flash
691-
operationResult = espTool.WriteFlash(firmware.FlashPartitions);
690+
ExitCodes operationResult = espTool.WriteFlash(firmware.FlashPartitions);
692691

693692
if (operationResult == ExitCodes.OK)
694693
{

nanoFirmwareFlasher.Library/FileDeployment/FileDeploymentManager.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
using nanoFramework.Tools.Debugger;
1+
//
2+
// Copyright (c) .NET Foundation and Contributors
3+
// See LICENSE file in the project root for full license information.
4+
//
5+
6+
using nanoFramework.Tools.Debugger;
27
using nanoFramework.Tools.Debugger.Extensions;
38
using Newtonsoft.Json;
49
using System;
5-
using System.Collections.Generic;
610
using System.IO;
7-
using System.Linq;
8-
using System.Runtime;
9-
using System.Text;
1011
using System.Threading.Tasks;
1112

1213
namespace nanoFramework.Tools.FirmwareFlasher.FileDeployment
@@ -16,9 +17,9 @@ namespace nanoFramework.Tools.FirmwareFlasher.FileDeployment
1617
/// </summary>
1718
public class FileDeploymentManager
1819
{
19-
private FileDeploymentConfiguration _configuration;
20-
private VerbosityLevel _verbosity;
21-
private string _serialPort;
20+
private readonly FileDeploymentConfiguration _configuration;
21+
private readonly VerbosityLevel _verbosity;
22+
private readonly string _serialPort;
2223

2324
/// <summary>
2425
/// Creates an instance of FileDeploymentManager.

nanoFirmwareFlasher.Library/FirmwarePackage.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public static List<CloudSmithPackageDetail> GetTargetList(
158158
// Because new stable releases are published on a regular basis and preview very rarely, we query for stable versions published in past month and preview versions published during the past 6 months.
159159
string requestUri = $"{repoName}/?page_size=500&q=uploaded:'>{(preview ? "6" : "1")} month ago' {(platform.HasValue ? "AND tag:" + platform.Value : "")}";
160160

161-
List<CloudSmithPackageDetail> targetPackages = new();
161+
List<CloudSmithPackageDetail> targetPackages = [];
162162

163163
if (verbosity > VerbosityLevel.Normal)
164164
{
@@ -246,7 +246,7 @@ internal async Task<ExitCodes> DownloadAndExtractAsync()
246246
return ExitCodes.E9006;
247247
}
248248

249-
List<FileInfo> fwFiles = new();
249+
List<FileInfo> fwFiles = [];
250250

251251
if (_preview)
252252
{

nanoFirmwareFlasher.Library/JLinkCli.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public ExitCodes ExecuteFlashBinFiles(
179179
}
180180
}
181181

182-
List<string> shadowFiles = new List<string>();
182+
List<string> shadowFiles = [];
183183

184184
ProcessFilePaths(files, shadowFiles);
185185

@@ -335,7 +335,7 @@ public ExitCodes ExecuteFlashHexFiles(
335335
return ExitCodes.E5004;
336336
}
337337

338-
List<string> shadowFiles = new List<string>();
338+
List<string> shadowFiles = [];
339339

340340
ProcessFilePaths(files, shadowFiles);
341341

nanoFirmwareFlasher.Library/JLinkDevice.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public static List<string> ListDevices()
151151
if (jlinkMatches.Count == 0)
152152
{
153153
// no J-Link probe found
154-
return new List<string>();
154+
return [];
155155
}
156156

157157
return jlinkMatches.Cast<Match>().Select(i => i.Value).ToList();

nanoFirmwareFlasher.Library/JLinkOperations.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public static async System.Threading.Tasks.Task<ExitCodes> UpdateFirmwareAsync(
6969
}
7070

7171
// setup files to flash
72-
var filesToFlash = new List<string>();
72+
List<string> filesToFlash = [];
7373

7474
if (updateFw)
7575
{
@@ -153,15 +153,15 @@ public static async System.Threading.Tasks.Task<ExitCodes> UpdateFirmwareAsync(
153153
jlinkDevice.Verbosity = verbosity;
154154

155155
// write HEX files to flash
156-
if (filesToFlash.Any(f => f.EndsWith(".hex")))
156+
if (filesToFlash.Exists(f => f.EndsWith(".hex")))
157157
{
158158
operationResult = jlinkDevice.FlashHexFiles(filesToFlash);
159159
}
160160

161161
if (operationResult == ExitCodes.OK && isApplicationBinFile)
162162
{
163163
// now program the application file
164-
operationResult = jlinkDevice.FlashBinFiles(new List<string> { applicationPath }, new List<string> { deploymentAddress });
164+
operationResult = jlinkDevice.FlashBinFiles([applicationPath], [deploymentAddress]);
165165
}
166166

167167
return operationResult;
@@ -178,7 +178,7 @@ public static ExitCodes MassErase(
178178
VerbosityLevel verbosity)
179179
{
180180
// J-Link device
181-
JLinkDevice jlinkDevice = new JLinkDevice(probeId);
181+
JLinkDevice jlinkDevice = new(probeId);
182182

183183
if (!jlinkDevice.DevicePresent)
184184
{

nanoFirmwareFlasher.Library/NanoDeviceOperations.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,6 @@ public ExitCodes GetDeviceDetails(
163163
// report issue
164164
throw new CantConnectToNanoDeviceException("Couldn't connect to specified nano device.");
165165
}
166-
167-
if (nanoDevice is null)
168-
{
169-
throw new ArgumentNullException(nameof(nanoDevice));
170-
}
171-
172-
return ExitCodes.E2000;
173166
}
174167

175168
/// <summary>

0 commit comments

Comments
 (0)