Skip to content

Commit

Permalink
Add New Node List.IsNullOrEmpty
Browse files Browse the repository at this point in the history
  • Loading branch information
chuongmep committed Dec 1, 2021
1 parent 692a13e commit 263f9f8
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/Libraries/CoreNodes/List.cs
Original file line number Diff line number Diff line change
Expand Up @@ -762,14 +762,30 @@ public static IList TakeEveryNthItem(IList list, int n, int offset = 0)
/// Determines if the given list is empty.
/// </summary>
/// <param name="list">List to be checked if it is empty</param>
/// <returns name="bool">True if list is empty, false if it isnt</returns>
/// <returns name="bool">True if list is empty, false if it isn't</returns>
/// <search>test,is,empty,null,count</search>
[IsVisibleInDynamoLibrary(true)]
public static bool IsEmpty(IList list)
{
return list.Count == 0;
}

/// <summary>
/// Determines if the given list is null or empty.
/// </summary>
/// <param name="list">List to be checked if it is empty or null</param>
/// <returns name="bool">True if list is empty or null, false if it isn't</returns>
/// <search>test,is,empty,null,count</search>
[IsVisibleInDynamoLibrary(true)]
public static bool IsNullOrEmpty(IList list)
{
bool flag1 = list == null;
if (flag1) return true;
bool flag2 = list.Cast<object>().All(x => x == null);
if (flag2) return true;
return IsEmpty(list);
}

/// <summary>
/// Determines if all items in the given list is a boolean and has a true value.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@
{
"path": "DSCoreNodes.DSCore.List.IsEmpty"
},
{
"path": "DSCoreNodes.DSCore.List.IsNullOrEmpty"
},
{
"path": "DSCoreNodes.DSCore.List.IndexOf"
},
Expand Down
11 changes: 11 additions & 0 deletions test/Libraries/CoreNodesTests/ListTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,17 @@ public static void IsEmptyList()
Assert.IsTrue(List.IsEmpty(List.Empty));
Assert.IsFalse(List.IsEmpty(new ArrayList { 1 }));
}
[Test]
[Category("UnitTests")]
public static void IsNullOrEmptyList()
{
Assert.IsTrue(List.IsNullOrEmpty(List.Empty));
Assert.IsFalse(List.IsNullOrEmpty(new ArrayList { 1 }));
Assert.IsTrue(List.IsNullOrEmpty(new ArrayList { }));
Assert.IsTrue(List.IsNullOrEmpty(new ArrayList { null }));
Assert.IsTrue(List.IsNullOrEmpty(null));
Assert.IsFalse(List.IsNullOrEmpty(new ArrayList{"data",null}));
}

[Test]
[Category("UnitTests")]
Expand Down
8 changes: 8 additions & 0 deletions test/ViewExtensionLibraryTests/resources/libraryItems.json
Original file line number Diff line number Diff line change
Expand Up @@ -4624,6 +4624,14 @@
"itemType": "action",
"keywords": "test, is, empty, null, count"
},
{
"fullyQualifiedName": "DSCore.List.IsNullOrEmpty",
"iconUrl": null,
"contextData": "DSCore.List.IsNullOrEmpty@var[]..[]",
"parameters": null,
"itemType": "action",
"keywords": "test, is, empty, null, count"
},
{
"fullyQualifiedName": "DSCore.List.AllTrue",
"iconUrl": "http://localhost/icons/DSCore.List.AllTrue.Small?path=DSCoreNodes.dll",
Expand Down

0 comments on commit 263f9f8

Please sign in to comment.