From 9a440755053e366a1728d7c1211d13da0430cfe7 Mon Sep 17 00:00:00 2001 From: reddyashish <43763136+reddyashish@users.noreply.github.com> Date: Thu, 22 Aug 2024 06:12:39 -0700 Subject: [PATCH 1/6] New node which will return a string version of list index --- src/Libraries/CoreNodes/List.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Libraries/CoreNodes/List.cs b/src/Libraries/CoreNodes/List.cs index 4833971c456..09dbb12aade 100644 --- a/src/Libraries/CoreNodes/List.cs +++ b/src/Libraries/CoreNodes/List.cs @@ -173,6 +173,21 @@ public static int IndexOf(IList list, object element) return list.IndexOf(element); } + /// + /// Returns the index of the element in the given list. Match between given list and target element must be a strict match (i.e. int to int, double to double, string to string, object to object etc.) + /// Use this node to avoid negative index values. + /// + /// The list to find the element in. + /// The element whose index is to be returned. + /// The stringified index of the element in the list. Invalid index null will be returned if strict match not found. + /// index,indexof + [IsVisibleInDynamoLibrary(true)] + public static string StringifyIndexOf(IList list, object element) + { + var index = list.IndexOf(element); + return index < 0 ? null : index.ToString(); + } + /// /// Returns the number of false boolean values in the given list. /// From 37af4f03329c5018c277120fd4d48af5684a3da4 Mon Sep 17 00:00:00 2001 From: reddyashish <43763136+reddyashish@users.noreply.github.com> Date: Thu, 22 Aug 2024 06:21:27 -0700 Subject: [PATCH 2/6] Update List.cs --- src/Libraries/CoreNodes/List.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Libraries/CoreNodes/List.cs b/src/Libraries/CoreNodes/List.cs index 09dbb12aade..5fa5d9abcfd 100644 --- a/src/Libraries/CoreNodes/List.cs +++ b/src/Libraries/CoreNodes/List.cs @@ -162,6 +162,7 @@ public static IList SetUnion(IList list1, IList list2) /// /// Returns the index of the element in the given list. Match between given list and target element must be a strict match (i.e. int to int, double to double, string to string, object to object etc.) + /// Use StringifyIndexOf to avoid negative index values. /// /// The list to find the element in. /// The element whose index is to be returned. @@ -175,7 +176,6 @@ public static int IndexOf(IList list, object element) /// /// Returns the index of the element in the given list. Match between given list and target element must be a strict match (i.e. int to int, double to double, string to string, object to object etc.) - /// Use this node to avoid negative index values. /// /// The list to find the element in. /// The element whose index is to be returned. From 75936d24c5ac8a60e2009a13f6bda342d9cc7c00 Mon Sep 17 00:00:00 2001 From: reddyashish <43763136+reddyashish@users.noreply.github.com> Date: Thu, 22 Aug 2024 06:22:31 -0700 Subject: [PATCH 3/6] Update List.cs --- src/Libraries/CoreNodes/List.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Libraries/CoreNodes/List.cs b/src/Libraries/CoreNodes/List.cs index 5fa5d9abcfd..4e158f2f7ff 100644 --- a/src/Libraries/CoreNodes/List.cs +++ b/src/Libraries/CoreNodes/List.cs @@ -161,7 +161,7 @@ public static IList SetUnion(IList list1, IList list2) } /// - /// Returns the index of the element in the given list. Match between given list and target element must be a strict match (i.e. int to int, double to double, string to string, object to object etc.) + /// Returns the index of the element in the given list. Match between given list and target element must be a strict match (i.e. int to int, double to double, string to string, object to object etc.). /// Use StringifyIndexOf to avoid negative index values. /// /// The list to find the element in. From 929abb7cec4d60a6547f676c7c8b58fefbb57627 Mon Sep 17 00:00:00 2001 From: reddyashish <43763136+reddyashish@users.noreply.github.com> Date: Thu, 22 Aug 2024 08:54:45 -0700 Subject: [PATCH 4/6] Update List.cs --- src/Libraries/CoreNodes/List.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Libraries/CoreNodes/List.cs b/src/Libraries/CoreNodes/List.cs index 4e158f2f7ff..1a820280704 100644 --- a/src/Libraries/CoreNodes/List.cs +++ b/src/Libraries/CoreNodes/List.cs @@ -175,7 +175,7 @@ public static int IndexOf(IList list, object element) } /// - /// Returns the index of the element in the given list. Match between given list and target element must be a strict match (i.e. int to int, double to double, string to string, object to object etc.) + /// Returns the stringified index of the element in the given list. Match between given list and target element must be a strict match (i.e. int to int, double to double, string to string, object to object etc.) /// /// The list to find the element in. /// The element whose index is to be returned. From a47137f9debafefc12213a9cc85ad7bb87cd4cde Mon Sep 17 00:00:00 2001 From: reddyashish <43763136+reddyashish@users.noreply.github.com> Date: Mon, 26 Aug 2024 08:05:44 -0700 Subject: [PATCH 5/6] Update List.cs --- src/Libraries/CoreNodes/List.cs | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/src/Libraries/CoreNodes/List.cs b/src/Libraries/CoreNodes/List.cs index 1a820280704..1cc13c8b8e1 100644 --- a/src/Libraries/CoreNodes/List.cs +++ b/src/Libraries/CoreNodes/List.cs @@ -162,30 +162,16 @@ public static IList SetUnion(IList list1, IList list2) /// /// Returns the index of the element in the given list. Match between given list and target element must be a strict match (i.e. int to int, double to double, string to string, object to object etc.). - /// Use StringifyIndexOf to avoid negative index values. /// /// The list to find the element in. /// The element whose index is to be returned. /// The index of the element in the list. Invalid index -1 will be returned if strict match not found. /// index,indexof [IsVisibleInDynamoLibrary(true)] - public static int IndexOf(IList list, object element) - { - return list.IndexOf(element); - } - - /// - /// Returns the stringified index of the element in the given list. Match between given list and target element must be a strict match (i.e. int to int, double to double, string to string, object to object etc.) - /// - /// The list to find the element in. - /// The element whose index is to be returned. - /// The stringified index of the element in the list. Invalid index null will be returned if strict match not found. - /// index,indexof - [IsVisibleInDynamoLibrary(true)] - public static string StringifyIndexOf(IList list, object element) + public static int? IndexOf(IList list, object element) { var index = list.IndexOf(element); - return index < 0 ? null : index.ToString(); + return index < 0 ? null : index; } /// From b4a2dbdd717e8b9050fc2734ffadc01109147c78 Mon Sep 17 00:00:00 2001 From: reddyashish <43763136+reddyashish@users.noreply.github.com> Date: Mon, 26 Aug 2024 09:01:57 -0700 Subject: [PATCH 6/6] Update ListTests.cs --- test/Libraries/CoreNodesTests/ListTests.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/Libraries/CoreNodesTests/ListTests.cs b/test/Libraries/CoreNodesTests/ListTests.cs index 14c2fbd110e..3a8cfa1f426 100644 --- a/test/Libraries/CoreNodesTests/ListTests.cs +++ b/test/Libraries/CoreNodesTests/ListTests.cs @@ -2,7 +2,6 @@ using System.Collections; using System.Collections.Generic; using System.Linq; -using Dynamo.Graph.Nodes; using NUnit.Framework; using List = DSCore.List; @@ -180,7 +179,7 @@ public static void ListSetUnion() public static void ListIndexOf() { Assert.AreEqual(1, List.IndexOf(new ArrayList { "x", "y", 1 }, "y")); - Assert.AreEqual(-1, List.IndexOf(new ArrayList { 3, 4, 6, 8 }, 9)); + Assert.AreEqual(null, List.IndexOf(new ArrayList { 3, 4, 6, 8 }, 9)); } [Test]