private static void UpdateFailedResultWithArrayElementsDetails(
            FailedResult outputResultToUpdate,
            PropertyInfo collectionProperty,
            Type instanceType,
            object collectionValue)
        {
            if (collectionValue == null)
            {
                return;
            }

            var attributesFromValidateCollection = CustomAttributeExtensions.GetCustomAttributes(collectionProperty, true)
                                                   .OfType <ValidateCollectionAttribute>()
                                                   .Select(a => a.InlineAttribute)
                                                   .ToList();

            var counter = -1;

            foreach (var arrayElement in (System.Collections.IEnumerable)collectionValue)
            {
                counter++;

                if (arrayElement == null)
                {
                    if (attributesFromValidateCollection.Any(a => a.GetType() == typeof(RequiredAttribute)))
                    {
                        var source = $"{instanceType.Name}.{collectionProperty.Name}.{counter}";
                        outputResultToUpdate.AddError(new ExecutionError(AnnotationErrorCodes.Required, source));
                    }

                    continue;
                }

                // Validate every array element itself.
                var arrayResultErrors = CoreValidator.GetValidationErrors(arrayElement, new ValidationContext(arrayElement), attributesFromValidateCollection, false);
                foreach (var arrayElementError in arrayResultErrors)
                {
                    var source = $"{instanceType.Name}.{collectionProperty.Name}.{counter}";
                    outputResultToUpdate.AddError(new ExecutionError(arrayElementError.CodeInfo, source));
                }

                var arrayType = arrayElement.GetType();
                if (arrayType.IsPrimitive || arrayType == typeof(decimal) || arrayType == typeof(string))
                {
                    continue;
                }

                // Validate properties of an array element recursively if it's not an primitive type.
                var propertyResult = Validate(arrayElement);
                if (!(propertyResult is FailedResult fr))
                {
                    continue;
                }

                UpdateFailedResultWithDetails(outputResultToUpdate, fr, collectionProperty, instanceType, counter);
            }
        }