diff --git a/src/Libraries/CoreNodes/List.cs b/src/Libraries/CoreNodes/List.cs index 4833971c456..1cc13c8b8e1 100644 --- a/src/Libraries/CoreNodes/List.cs +++ b/src/Libraries/CoreNodes/List.cs @@ -161,16 +161,17 @@ 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.). /// /// 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) + public static int? IndexOf(IList list, object element) { - return list.IndexOf(element); + var index = list.IndexOf(element); + return index < 0 ? null : index; } /// 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]