From f4aacf70eecde552c46ae35662d82f9c706c4201 Mon Sep 17 00:00:00 2001 From: Morten Nielsen Date: Fri, 4 Aug 2023 09:48:51 -0700 Subject: [PATCH] Added .NET 6 support --- src/NmeaParser/BluetoothDevice.Android.cs | 4 ++-- src/NmeaParser/BufferedStreamDevice.cs | 2 +- src/NmeaParser/Gnss/GnssMonitor.cs | 4 ++-- src/NmeaParser/Gnss/Ntrip/Client.cs | 2 +- src/NmeaParser/Nmea/NmeaMessage.cs | 5 ++-- src/NmeaParser/NmeaParser.csproj | 23 +++++++++++-------- src/NmeaParser/SerialPortDevice.Desktop.cs | 2 +- .../SampleApp.NetCore.csproj | 4 ++-- .../NmeaParser.Tests.Net.csproj | 2 +- 9 files changed, 27 insertions(+), 21 deletions(-) diff --git a/src/NmeaParser/BluetoothDevice.Android.cs b/src/NmeaParser/BluetoothDevice.Android.cs index cbc2be9..34bb3f5 100644 --- a/src/NmeaParser/BluetoothDevice.Android.cs +++ b/src/NmeaParser/BluetoothDevice.Android.cs @@ -52,9 +52,9 @@ namespace NmeaParser public static IEnumerable GetBluetoothSerialDevices() { var adapter = Android.Bluetooth.BluetoothAdapter.DefaultAdapter; - if (adapter != null && adapter.IsEnabled) + if (adapter != null && adapter.IsEnabled && adapter.BondedDevices is not null) { - foreach (var b in adapter.BondedDevices.Where(d => d.GetUuids().Any(t => SERIAL_UUID.CompareTo(t.Uuid) == 0))) + foreach (var b in adapter.BondedDevices.Where(d => d.GetUuids()?.Any(t => SERIAL_UUID.CompareTo(t.Uuid) == 0) == true)) yield return b; } } diff --git a/src/NmeaParser/BufferedStreamDevice.cs b/src/NmeaParser/BufferedStreamDevice.cs index e6953f8..cfc493b 100644 --- a/src/NmeaParser/BufferedStreamDevice.cs +++ b/src/NmeaParser/BufferedStreamDevice.cs @@ -65,7 +65,7 @@ namespace NmeaParser return m_stream; } - private void OnEndOfStreamReached(object sender, EventArgs e) + private void OnEndOfStreamReached(object? sender, EventArgs e) { EndOfStreamReached?.Invoke(this, e); if (m_stream is BufferedStream stream && !stream.CanRewind && IsOpen) diff --git a/src/NmeaParser/Gnss/GnssMonitor.cs b/src/NmeaParser/Gnss/GnssMonitor.cs index a689ad4..e9ade43 100644 --- a/src/NmeaParser/Gnss/GnssMonitor.cs +++ b/src/NmeaParser/Gnss/GnssMonitor.cs @@ -58,7 +58,7 @@ namespace NmeaParser.Gnss /// public NmeaDevice Device { get; } - private void NmeaMessageReceived(object sender, NmeaParser.NmeaMessageReceivedEventArgs e) + private void NmeaMessageReceived(object? sender, NmeaParser.NmeaMessageReceivedEventArgs e) { OnMessageReceived(e.Message); } @@ -448,7 +448,7 @@ namespace NmeaParser.Gnss { SynchronizationContext.Post((d) => { - foreach (string propertyName in (IEnumerable)d) + foreach (string propertyName in (IEnumerable)d!) PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); }, properties); } diff --git a/src/NmeaParser/Gnss/Ntrip/Client.cs b/src/NmeaParser/Gnss/Ntrip/Client.cs index e0a19a6..c0b8c99 100644 --- a/src/NmeaParser/Gnss/Ntrip/Client.cs +++ b/src/NmeaParser/Gnss/Ntrip/Client.cs @@ -198,7 +198,7 @@ namespace NmeaParser.Gnss.Ntrip private void ReceiveCallback(IAsyncResult ar) { - TaskCompletionSource tcs = (TaskCompletionSource)ar.AsyncState; + TaskCompletionSource tcs = (TaskCompletionSource)ar.AsyncState!; if (tcs.Task.IsCanceled) return; try { diff --git a/src/NmeaParser/Nmea/NmeaMessage.cs b/src/NmeaParser/Nmea/NmeaMessage.cs index f7a59ff..0c474e1 100644 --- a/src/NmeaParser/Nmea/NmeaMessage.cs +++ b/src/NmeaParser/Nmea/NmeaMessage.cs @@ -125,7 +125,7 @@ namespace NmeaParser.Messages if (pinfo.Length == 2 && pinfo[0].ParameterType == typeof(string) && pinfo[1].ParameterType == typeof(string[])) { if (!replace && messageTypes.ContainsKey(nmeaType)) - throw new InvalidOperationException($"Message type {nmeaType} declared in {typeInfo.FullName} is already registered by {messageTypes[nmeaType].DeclaringType.FullName}"); + throw new InvalidOperationException($"Message type {nmeaType} declared in {typeInfo.FullName} is already registered by {messageTypes[nmeaType].DeclaringType?.FullName}"); messageTypes[nmeaType] = c; return; } @@ -309,8 +309,9 @@ namespace NmeaParser.Messages /// /// An object to compare with this object. /// true if the current object is equal to the other parameter; otherwise, false. - public bool Equals(NmeaMessage other) + public bool Equals(NmeaMessage? other) { + if (other is null) return false; if (other.MessageType != MessageType) return false; if (other.MessageParts.Count != MessageParts.Count) diff --git a/src/NmeaParser/NmeaParser.csproj b/src/NmeaParser/NmeaParser.csproj index 7bddef9..cf5c4ea 100644 --- a/src/NmeaParser/NmeaParser.csproj +++ b/src/NmeaParser/NmeaParser.csproj @@ -2,7 +2,7 @@ - netstandard2.0;netstandard1.4;netcoreapp2.1;net452;monoandroid50;monoandroid70;xamarinios10;uap10.0.18362 + netstandard2.0;netstandard1.4;netcoreapp2.1;net452;monoandroid50;monoandroid70;xamarinios10;uap10.0.18362;net6.0;net6.0-ios;net6.0-android;net6.0-windows10.0.19041.0 true true Debug;Release @@ -12,20 +12,20 @@ An NMEA stream parser for serial port, bluetooth and file-based nmea simulation. NMEA GPS GNSS Serialport Bluetooth Navigation NTRIP RTCM Galileo GLONASS BeiDou Garmin Trimble SharpGIS.NmeaParser - 2.2.2 + 2.3.0 NMEA Parser Apache-2.0 https://dotmorten.github.io/NmeaParser/ https://github.com/dotMorten/NmeaParser en-US - Copyright © Morten Nielsen 2015-2020 + Copyright © Morten Nielsen 2015-2023 $(MSBuildThisFileDirectory)..\..\artifacts\NmeaParser\$(Configuration) ..\..\artifacts\NuGet\$(Configuration)\ true true $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb - 8.0 + 9.0 true true enable @@ -48,26 +48,31 @@ $(DefineConstants);NETSTANDARD - + + $(DefineConstants);NETSTANDARD + + $(DefineConstants);NETFX false - $(DefineConstants);XAMARIN;API_LEVEL_21 + $(DefineConstants);API_LEVEL_21 $(NoWarn);XA0113;XA0114 false false - $(DefineConstants);XAMARIN;API_LEVEL_24 + $(DefineConstants);API_LEVEL_24 $(NoWarn);XA0113;XA0114 false + + $(DefineConstants);API_LEVEL_24 + - $(DefineConstants);XAMARIN $(NoWarn);VSX1000 @@ -87,7 +92,7 @@ - + diff --git a/src/NmeaParser/SerialPortDevice.Desktop.cs b/src/NmeaParser/SerialPortDevice.Desktop.cs index daf8d79..ea855ba 100644 --- a/src/NmeaParser/SerialPortDevice.Desktop.cs +++ b/src/NmeaParser/SerialPortDevice.Desktop.cs @@ -12,7 +12,7 @@ // * limitations under the License. // ****************************************************************************** -#if NETFX || NETCOREAPP +#if NETFX || NETCOREAPP && WINDOWS using System; using System.Collections.Generic; using System.Linq; diff --git a/src/SampleApp.WinDesktop/SampleApp.NetCore.csproj b/src/SampleApp.WinDesktop/SampleApp.NetCore.csproj index 8b0f4c8..860dc86 100644 --- a/src/SampleApp.WinDesktop/SampleApp.NetCore.csproj +++ b/src/SampleApp.WinDesktop/SampleApp.NetCore.csproj @@ -2,7 +2,7 @@ WinExe - net5.0-windows10.0.18362.0 + net6.0-windows10.0.19041.0 true SampleApp.WinDesktop @@ -19,7 +19,7 @@ NmeaSampleData.txt PreserveNewest - + PreserveNewest diff --git a/src/UnitTests/NmeaParser.Tests.NET/NmeaParser.Tests.Net.csproj b/src/UnitTests/NmeaParser.Tests.NET/NmeaParser.Tests.Net.csproj index a853fd9..4941952 100644 --- a/src/UnitTests/NmeaParser.Tests.NET/NmeaParser.Tests.Net.csproj +++ b/src/UnitTests/NmeaParser.Tests.NET/NmeaParser.Tests.Net.csproj @@ -1,7 +1,7 @@ - net452;netcoreapp3.1 + net472;net6.0 false 8.0