Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DYN-7082: Improvements to node List.IndexOf #15440

Merged
merged 6 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/Libraries/CoreNodes/List.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,17 @@ public static IList SetUnion(IList<object> list1, IList<object> list2)
}

/// <summary>
/// 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.).
/// </summary>
/// <param name="list">The list to find the element in.</param>
/// <param name="element">The element whose index is to be returned.</param>
/// <returns name="int">The index of the element in the list. Invalid index -1 will be returned if strict match not found.</returns>
/// <search>index,indexof</search>
[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;
}

/// <summary>
Expand Down
3 changes: 1 addition & 2 deletions test/Libraries/CoreNodesTests/ListTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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]
Expand Down
Loading