using System.Collections;
namespace Elsa.JavaScript.Helpers;
///
/// Contains helper methods for working with object arrays.
///
public static class ObjectArrayHelper
{
///
/// Determines if the specified object is an array-like CLR collection.
///
public static bool DetermineIfObjectIsArrayLikeClrCollection(Type type)
{
var isDictionary = typeof(IDictionary).IsAssignableFrom(type);
if (isDictionary)
return false;
if (typeof(ICollection).IsAssignableFrom(type))
return true;
foreach (var interfaceType in type.GetInterfaces())
{
if (!interfaceType.IsGenericType)
{
continue;
}
if (interfaceType.GetGenericTypeDefinition() == typeof(IReadOnlyCollection<>)
|| interfaceType.GetGenericTypeDefinition() == typeof(ICollection<>))
{
return true;
}
}
return false;
}
}