From 59a9f23f81e8a670186578dd15736952940c04c8 Mon Sep 17 00:00:00 2001 From: Alan Rynne Date: Wed, 29 May 2024 10:07:29 +0200 Subject: [PATCH] fix: Warnings picked up in net8.0 (#3446) --- .../Bindings/ArcGISSendBinding.cs | 2 +- .../Operations/Receive/HostObjectBuilder.cs | 8 +++----- .../Operations/Receive/AutocadHostObjectBuilder.cs | 2 +- .../Bindings/BasicConnectorBindingRevit.cs | 2 +- .../Bindings/SendBinding.cs | 2 +- .../Operations/Send/RevitRootObjectBuilder.cs | 4 ++-- .../Bindings/RhinoSendBinding.cs | 2 +- .../Operations/Receive/RhinoHostObjectBuilder.cs | 3 ++- .../Utils/NonNativeFeaturesUtils.cs | 7 ++++--- .../Raw/PolycurveToHostPolylineRawConverter.cs | 2 +- .../Helpers/DisplayValueExtractor.cs | 14 ++++++++------ .../ReferencePointConverter.cs | 7 ++++--- 12 files changed, 29 insertions(+), 26 deletions(-) diff --git a/DUI3-DX/Connectors/ArcGIS/Speckle.Connectors.ArcGIS3/Bindings/ArcGISSendBinding.cs b/DUI3-DX/Connectors/ArcGIS/Speckle.Connectors.ArcGIS3/Bindings/ArcGISSendBinding.cs index 9f883384c3..537acd8f5c 100644 --- a/DUI3-DX/Connectors/ArcGIS/Speckle.Connectors.ArcGIS3/Bindings/ArcGISSendBinding.cs +++ b/DUI3-DX/Connectors/ArcGIS/Speckle.Connectors.ArcGIS3/Bindings/ArcGISSendBinding.cs @@ -286,7 +286,7 @@ public async Task Send(string modelCardId) .Where(obj => obj != null) .ToList(); - if (!mapMembers.Any()) + if (mapMembers.Count == 0) { // Handle as CARD ERROR in this function throw new SpeckleSendFilterException( diff --git a/DUI3-DX/Connectors/ArcGIS/Speckle.Connectors.ArcGIS3/Operations/Receive/HostObjectBuilder.cs b/DUI3-DX/Connectors/ArcGIS/Speckle.Connectors.ArcGIS3/Operations/Receive/HostObjectBuilder.cs index 865c0abdcb..6bae793020 100644 --- a/DUI3-DX/Connectors/ArcGIS/Speckle.Connectors.ArcGIS3/Operations/Receive/HostObjectBuilder.cs +++ b/DUI3-DX/Connectors/ArcGIS/Speckle.Connectors.ArcGIS3/Operations/Receive/HostObjectBuilder.cs @@ -82,7 +82,8 @@ public void AddDatasetsToMap((string, string) databaseObj, string databasePath) private string[] GetLayerPath(TraversalContext context) { string[] collectionBasedPath = context.GetAscendantOfType().Select(c => c.name).ToArray(); - string[] reverseOrderPath = collectionBasedPath.Any() ? collectionBasedPath : context.GetPropertyPath().ToArray(); + string[] reverseOrderPath = + collectionBasedPath.Length != 0 ? collectionBasedPath : context.GetPropertyPath().ToArray(); return reverseOrderPath.Reverse().ToArray(); } @@ -180,10 +181,7 @@ CancellationToken cancellationToken // 3. add layer and tables to the Table Of Content foreach ((string, string) databaseObj in convertedGISObjects) { - if (cancellationToken.IsCancellationRequested) - { - throw new OperationCanceledException(cancellationToken); - } + cancellationToken.ThrowIfCancellationRequested(); // BAKE OBJECTS HERE // POC: QueuedTask var task = QueuedTask.Run(() => diff --git a/DUI3-DX/Connectors/Autocad/Speckle.Connectors.AutocadShared/Operations/Receive/AutocadHostObjectBuilder.cs b/DUI3-DX/Connectors/Autocad/Speckle.Connectors.AutocadShared/Operations/Receive/AutocadHostObjectBuilder.cs index 9b6b081c5e..12cdf9aaec 100644 --- a/DUI3-DX/Connectors/Autocad/Speckle.Connectors.AutocadShared/Operations/Receive/AutocadHostObjectBuilder.cs +++ b/DUI3-DX/Connectors/Autocad/Speckle.Connectors.AutocadShared/Operations/Receive/AutocadHostObjectBuilder.cs @@ -103,7 +103,7 @@ CancellationToken cancellationToken private string GetLayerPath(TraversalContext context, string baseLayerPrefix) { string[] collectionBasedPath = context.GetAscendantOfType().Select(c => c.name).ToArray(); - string[] path = collectionBasedPath.Any() ? collectionBasedPath : context.GetPropertyPath().ToArray(); + string[] path = collectionBasedPath.Length != 0 ? collectionBasedPath : context.GetPropertyPath().ToArray(); return _autocadLayerManager.LayerFullName(baseLayerPrefix, string.Join("-", path)); //TODO: reverse path? } diff --git a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Bindings/BasicConnectorBindingRevit.cs b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Bindings/BasicConnectorBindingRevit.cs index fb01f781e6..56d73f3296 100644 --- a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Bindings/BasicConnectorBindingRevit.cs +++ b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Bindings/BasicConnectorBindingRevit.cs @@ -91,7 +91,7 @@ public void HighlightModel(string modelCardId) SenderModelCard model = (SenderModelCard)_store.GetModelById(modelCardId); var elementIds = model.SendFilter.NotNull().GetObjectIds().Select(ElementId.Parse).ToList(); - if (elementIds.Any()) + if (elementIds.Count != 0) { Commands.SetModelError(modelCardId, new InvalidOperationException("No objects found to highlight.")); return; diff --git a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Bindings/SendBinding.cs b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Bindings/SendBinding.cs index 0383e8a77c..223c8d4b0c 100644 --- a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Bindings/SendBinding.cs +++ b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Bindings/SendBinding.cs @@ -98,7 +98,7 @@ private async Task HandleSend(string modelCardId) .Select(id => ElementId.Parse(id)) .ToList(); - if (!revitObjects.Any()) + if (revitObjects.Count == 0) { // Handle as CARD ERROR in this function throw new SpeckleSendFilterException("No objects were found to convert. Please update your publish filter!"); diff --git a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Operations/Send/RevitRootObjectBuilder.cs b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Operations/Send/RevitRootObjectBuilder.cs index 921d443444..de37e9d8ad 100644 --- a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Operations/Send/RevitRootObjectBuilder.cs +++ b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Operations/Send/RevitRootObjectBuilder.cs @@ -122,9 +122,9 @@ private Collection GetAndCreateObjectHostCollection(string[] path) { flatPathName += pathItem; Collection childCollection; - if (_collectionCache.ContainsKey(flatPathName)) + if (_collectionCache.TryGetValue(flatPathName, out Collection? collection)) { - childCollection = _collectionCache[flatPathName]; + childCollection = collection; } else { diff --git a/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/Bindings/RhinoSendBinding.cs b/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/Bindings/RhinoSendBinding.cs index 76bca9085c..e609468020 100644 --- a/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/Bindings/RhinoSendBinding.cs +++ b/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/Bindings/RhinoSendBinding.cs @@ -153,7 +153,7 @@ public async Task Send(string modelCardId) .Where(obj => obj != null) .ToList(); - if (!rhinoObjects.Any()) + if (rhinoObjects.Count == 0) { // Handle as CARD ERROR in this function throw new SpeckleSendFilterException("No objects were found to convert. Please update your publish filter!"); diff --git a/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/Operations/Receive/RhinoHostObjectBuilder.cs b/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/Operations/Receive/RhinoHostObjectBuilder.cs index f0a2f5822e..7de29b7a57 100644 --- a/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/Operations/Receive/RhinoHostObjectBuilder.cs +++ b/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/Operations/Receive/RhinoHostObjectBuilder.cs @@ -194,7 +194,8 @@ private int GetAndCreateLayerFromPath(string[] path, string baseLayerName, Dicti private string[] GetLayerPath(TraversalContext context) { string[] collectionBasedPath = context.GetAscendantOfType().Select(c => c.name).ToArray(); - string[] reverseOrderPath = collectionBasedPath.Any() ? collectionBasedPath : context.GetPropertyPath().ToArray(); + string[] reverseOrderPath = + collectionBasedPath.Length != 0 ? collectionBasedPath : context.GetPropertyPath().ToArray(); return reverseOrderPath.Reverse().ToArray(); } } diff --git a/DUI3-DX/Converters/ArcGIS/Speckle.Converters.ArcGIS3/Utils/NonNativeFeaturesUtils.cs b/DUI3-DX/Converters/ArcGIS/Speckle.Converters.ArcGIS3/Utils/NonNativeFeaturesUtils.cs index 1682b8774c..4f0fa7cdfc 100644 --- a/DUI3-DX/Converters/ArcGIS/Speckle.Converters.ArcGIS3/Utils/NonNativeFeaturesUtils.cs +++ b/DUI3-DX/Converters/ArcGIS/Speckle.Converters.ArcGIS3/Utils/NonNativeFeaturesUtils.cs @@ -49,12 +49,13 @@ public NonNativeFeaturesUtils( (string parentPath, ACG.Geometry geom, string? parentId) = item.Value; // add dictionnary item if doesn't exist yet - if (!geometryGroups.ContainsKey(parentPath)) + if (!geometryGroups.TryGetValue(parentPath, out var value)) { - geometryGroups[parentPath] = (new List(), parentId); + value = (new List(), parentId); + geometryGroups[parentPath] = value; } - geometryGroups[parentPath].geometries.Add(geom); + value.geometries.Add(geom); } catch (Exception ex) when (!ex.IsFatal()) { diff --git a/DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/ToHost/Raw/PolycurveToHostPolylineRawConverter.cs b/DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/ToHost/Raw/PolycurveToHostPolylineRawConverter.cs index faa13f0167..1a3425ebe7 100644 --- a/DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/ToHost/Raw/PolycurveToHostPolylineRawConverter.cs +++ b/DUI3-DX/Converters/Autocad/Speckle.Converters.AutocadShared/ToHost/Raw/PolycurveToHostPolylineRawConverter.cs @@ -49,7 +49,7 @@ public ADB.Polyline Convert(SOG.Polycurve target) angle = angle < 0 ? angle + 2 * Math.PI : angle; if (angle is null) { - throw new ArgumentNullException(nameof(arc), "Cannot convert arc without angle value."); + throw new ArgumentNullException(nameof(target), "Cannot convert arc without angle value."); } var bulge = Math.Tan((double)angle / 4) * BulgeDirection(arc.startPoint, arc.midPoint, arc.endPoint); diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/DisplayValueExtractor.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/DisplayValueExtractor.cs index 3a9fdb33de..cd65fb5f90 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/DisplayValueExtractor.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/DisplayValueExtractor.cs @@ -51,12 +51,13 @@ public DisplayValueExtractor( foreach (var mesh in meshes) { var materialId = mesh.MaterialElementId; - if (!meshesByMaterial.ContainsKey(materialId)) + if (!meshesByMaterial.TryGetValue(materialId, out List? value)) { - meshesByMaterial[materialId] = new List(); + value = new List(); + meshesByMaterial[materialId] = value; } - meshesByMaterial[materialId].Add(mesh); + value.Add(mesh); } foreach (var solid in solids) @@ -64,12 +65,13 @@ public DisplayValueExtractor( foreach (DB.Face face in solid.Faces) { var materialId = face.MaterialElementId; - if (!meshesByMaterial.ContainsKey(materialId)) + if (!meshesByMaterial.TryGetValue(materialId, out List? value)) { - meshesByMaterial[materialId] = new List(); + value = new List(); + meshesByMaterial[materialId] = value; } - meshesByMaterial[materialId].Add(face.Triangulate()); + value.Add(face.Triangulate()); } } diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ReferencePointConverter.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ReferencePointConverter.cs index 1c63df79d6..901c5c5572 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ReferencePointConverter.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ReferencePointConverter.cs @@ -42,16 +42,17 @@ public DB.Transform GetDocReferencePointTransform(DB.Document doc) //if the current doc is unsaved it will not, but then it'll be the only one :) var id = doc.PathName; - if (!_docTransforms.ContainsKey(id)) + if (!_docTransforms.TryGetValue(id, out DB.Transform? transform)) { // get from settings var referencePointSetting = _revitSettings.TryGetSettingString("reference-point", out string value) ? value : string.Empty; - _docTransforms[id] = GetReferencePointTransform(referencePointSetting); + transform = GetReferencePointTransform(referencePointSetting); + _docTransforms[id] = transform; } - return _docTransforms[id]; + return transform; } [SuppressMessage("Reliability", "CA2000:Dispose objects before losing scope")]