From e1ec242ff0299c358fddad1c19c69add318ee874 Mon Sep 17 00:00:00 2001 From: Lev Nachmanson Date: Tue, 16 Jul 2024 18:01:59 -0700 Subject: [PATCH] accept faillure of SortedDictionary.operator[int] when the key is not present. --- GraphLayout/Drawing/Graph.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/GraphLayout/Drawing/Graph.cs b/GraphLayout/Drawing/Graph.cs index 2efece5b..59615f4e 100644 --- a/GraphLayout/Drawing/Graph.cs +++ b/GraphLayout/Drawing/Graph.cs @@ -321,7 +321,9 @@ public void AddPrecalculatedEdge(Edge edge) { /// /// public Node FindNode(string nodeId) { - return nodeMap[nodeId] as Node; + if (nodeMap.TryGetValue(nodeId, out Node n)) + return n; + return null; } /// @@ -332,7 +334,8 @@ public Microsoft.Msagl.Core.Layout.Node FindGeometryNode(string nodeId) { if (GeometryGraph != null) { - Node node = nodeMap[nodeId] as Node; + + nodeMap.TryGetValue(nodeId, out Node node); if (node != null) { return GeometryGraph.FindNodeByUserData(node);