コード例 #1
0
        public Object GetFragment(EventBean eventBean, EventBean[] eventsPerStream, ExprEvaluatorContext exprEvaluatorContext)
        {
            Object result = _evaluator.Evaluate(new EvaluateParams(eventsPerStream, true, exprEvaluatorContext));

            if (result == null)
            {
                return(null);
            }

            var asArray = result as Array;

            if (asArray != null)
            {
                return(asArray
                       .Cast <object>()
                       .Where(item => item != null)
                       .Select(item => _eventBeanFactory.Wrap(item))
                       .ToArray());
            }

            if (result is ICollection)
            {
                var collection = (ICollection)result;
                return(collection
                       .Cast <object>()
                       .Where(item => item != null)
                       .Select(item => _eventBeanFactory.Wrap(item))
                       .ToArray());
            }

            if (result is IEnumerable)
            {
                var enumerable = (IEnumerable)result;
                return(enumerable
                       .Cast <object>()
                       .Where(item => item != null)
                       .Select(item => _eventBeanFactory.Wrap(item))
                       .ToArray());
            }

            return(null);
        }
コード例 #2
0
        public object GetFragment(
            EventBean eventBean,
            EventBean[] eventsPerStream,
            ExprEvaluatorContext exprEvaluatorContext)
        {
            object result = evaluator.Evaluate(eventsPerStream, true, exprEvaluatorContext);

            if (result == null) {
                return null;
            }

            if (result is Array asArray) {
                EventBean[] events = new EventBean[asArray.Length];
                for (int i = 0; i < events.Length; i++) {
                    var arrayItem = asArray.GetValue(i);
                    if (arrayItem != null) {
                        events[i] = eventBeanFactory.Wrap(arrayItem);
                    }
                }

                return events;
            }

            if (result.GetType().IsGenericCollection()) {
                return result
                    .Unwrap<object>()
                    .Select(item => item != null ? eventBeanFactory.Wrap(item) : null)
                    .ToArray();
            }

            if (result.GetType().IsGenericEnumerable()) {
                return result
                    .UnwrapEnumerable<object>()
                    .Where(item => item != null)
                    .ToArray();
            }

            return null;
        }