delegateas / ExpressionEngine

Expression Engine for Power Automate expressions written in C# using Sprache!
MIT License
8 stars 3 forks source link

Feature: Better Array support of ValueContainer #57

Open pksorensen opened 2 years ago

pksorensen commented 2 years ago

In the below example, getting the values of the array ValueContainer type is abit bloated and requires one to explicite do GetValue<IList<ValueContainer>>(), using ValueContainer[] or Object[] would throw exceptions.

        public override ValueTask<ValueContainer> ExecuteFunction(params ValueContainer[] parameters)
        {
            var relationship = parameters[0]?.ToString()?.ToLower();
            var data = _formDataAccessor.Data;

            if (data.ContainsKey(relationship))
            {
                var array = data[relationship];
                if(array.Type() == ValueType.Array)
                {
                    var arrayData = array.GetValue<IList<ValueContainer>>();
                    return new ValueTask<ValueContainer>(new ValueContainer(arrayData.Count > 0));
                }
            }

            return new ValueTask<ValueContainer>(new ValueContainer(false));

        }

consider ValueContainer to implement IEnumerable ? as short cuts to return properties for objects or items for arrays. Or just a better AsArray?