Skip to content

Commit

Permalink
fix: Warnings picked up in net8.0 (#3446)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanRynne authored May 29, 2024
1 parent 1f59f01 commit 59a9f23
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ public void AddDatasetsToMap((string, string) databaseObj, string databasePath)
private string[] GetLayerPath(TraversalContext context)
{
string[] collectionBasedPath = context.GetAscendantOfType<Collection>().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();
}

Expand Down Expand Up @@ -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(() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ CancellationToken cancellationToken
private string GetLayerPath(TraversalContext context, string baseLayerPrefix)
{
string[] collectionBasedPath = context.GetAscendantOfType<Collection>().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?
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ private int GetAndCreateLayerFromPath(string[] path, string baseLayerName, Dicti
private string[] GetLayerPath(TraversalContext context)
{
string[] collectionBasedPath = context.GetAscendantOfType<Collection>().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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<ACG.Geometry>(), parentId);
value = (new List<ACG.Geometry>(), parentId);
geometryGroups[parentPath] = value;
}

geometryGroups[parentPath].geometries.Add(geom);
value.geometries.Add(geom);
}
catch (Exception ex) when (!ex.IsFatal())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,27 @@ public DisplayValueExtractor(
foreach (var mesh in meshes)
{
var materialId = mesh.MaterialElementId;
if (!meshesByMaterial.ContainsKey(materialId))
if (!meshesByMaterial.TryGetValue(materialId, out List<DB.Mesh>? value))
{
meshesByMaterial[materialId] = new List<DB.Mesh>();
value = new List<DB.Mesh>();
meshesByMaterial[materialId] = value;
}

meshesByMaterial[materialId].Add(mesh);
value.Add(mesh);
}

foreach (var solid in solids)
{
foreach (DB.Face face in solid.Faces)
{
var materialId = face.MaterialElementId;
if (!meshesByMaterial.ContainsKey(materialId))
if (!meshesByMaterial.TryGetValue(materialId, out List<DB.Mesh>? value))
{
meshesByMaterial[materialId] = new List<DB.Mesh>();
value = new List<DB.Mesh>();
meshesByMaterial[materialId] = value;
}

meshesByMaterial[materialId].Add(face.Triangulate());
value.Add(face.Triangulate());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down

0 comments on commit 59a9f23

Please sign in to comment.