From ed969ae8ef7891a2e9511ae8d25df29f8985c257 Mon Sep 17 00:00:00 2001 From: glopesdev Date: Tue, 8 Sep 2026 15:05:58 +0100 Subject: [PATCH] Retarget Harp.Generators to net8.0 The package now ships lib/net8.0 in place of lib/netstandard2.0, and T4.BuildTools is marked PrivateAssets="all" so it no longer reaches the consumer graph, leaving Bonsai.Harp and YamlDotNet as the only declared dependencies. Eight nullable warnings raised by the annotated net8.0 BCL are cleared at the call sites for Dictionary.TryGetValue, object.ToString and MethodInfo.Invoke. A direction key holding a non-string now reports the invalid value rather than raising InvalidCastException. Closes #139 --- src/Firmware.cs | 8 ++++---- src/Harp.Generators.csproj | 4 ++-- src/Interface.cs | 4 ++-- src/TemplateBase.cs | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Firmware.cs b/src/Firmware.cs index db8ec66..4ccdb82 100644 --- a/src/Firmware.cs +++ b/src/Firmware.cs @@ -393,9 +393,9 @@ class PortPinInfoTypeConverter(IDeserializer deserializer) : IYamlTypeConverter public object? ReadYaml(IParser parser, Type type, ObjectDeserializer rootDeserializer) { var portPin = Deserializer.Deserialize>(parser); - if (portPin.TryGetValue(DirectionProperty, out object value)) + if (portPin.TryGetValue(DirectionProperty, out var value)) { - var pinDirection = PascalCaseNamingConvention.Instance.Apply((string)value); + var pinDirection = PascalCaseNamingConvention.Instance.Apply(value as string ?? string.Empty); Type portPinType = pinDirection switch { nameof(PinDirection.Input) => typeof(InputPinInfo), @@ -429,7 +429,7 @@ public void WriteYaml(IEmitter emitter, object? value, Type type, ObjectSerializ return; var scalarStyle = ScalarStyle.Any; - var scalarValue = LowerCaseNamingConvention.Instance.Apply(value.ToString()); + var scalarValue = LowerCaseNamingConvention.Instance.Apply(value.ToString() ?? string.Empty); if (scalarValue == "off") scalarStyle = ScalarStyle.DoubleQuoted; emitter.Emit(new Scalar(AnchorName.Empty, TagName.Empty, scalarValue, scalarStyle, true, true)); @@ -449,7 +449,7 @@ public void WriteYaml(IEmitter emitter, object? value, Type type, ObjectSerializ if (value is null) return; - emitter.Emit(new Scalar(CamelCaseNamingConvention.Instance.Apply(value.ToString()))); + emitter.Emit(new Scalar(CamelCaseNamingConvention.Instance.Apply(value.ToString() ?? string.Empty))); } } diff --git a/src/Harp.Generators.csproj b/src/Harp.Generators.csproj index 18903a9..fbccf11 100644 --- a/src/Harp.Generators.csproj +++ b/src/Harp.Generators.csproj @@ -3,7 +3,7 @@ Provides source generators for Harp device firmware and software interface. $(PackageTags) Device Firmware Interface - netstandard2.0 + net8.0 @@ -17,7 +17,7 @@ - + \ No newline at end of file diff --git a/src/Interface.cs b/src/Interface.cs index ea01547..f61557d 100644 --- a/src/Interface.cs +++ b/src/Interface.cs @@ -561,9 +561,9 @@ static int GetMemberSize( out PayloadType payloadType) { interfaceType = GetInterfaceType(member, register.Type); - if (deviceMetadata.GroupMasks.TryGetValue(interfaceType, out GroupMaskInfo groupMask)) + if (deviceMetadata.GroupMasks.TryGetValue(interfaceType, out var groupMask)) interfaceType = groupMask.InterfaceType; - else if (deviceMetadata.BitMasks.TryGetValue(interfaceType, out BitMaskInfo bitMask)) + else if (deviceMetadata.BitMasks.TryGetValue(interfaceType, out var bitMask)) interfaceType = bitMask.InterfaceType; if (GetInterfaceTypeSize(interfaceType, out payloadType, out int size)) diff --git a/src/TemplateBase.cs b/src/TemplateBase.cs index aae5471..302d725 100644 --- a/src/TemplateBase.cs +++ b/src/TemplateBase.cs @@ -125,9 +125,9 @@ public string ToStringWithCulture(object value) var method = value.GetType().GetMethod(nameof(ToString), [typeof(IFormatProvider)]); if (method is not null) - return (string)method.Invoke(value, [formatProvider]); + return (string?)method.Invoke(value, [formatProvider]) ?? string.Empty; - return value.ToString(); + return value.ToString() ?? string.Empty; } } }