Exemplo n.º 1
0
        private Filtering(Expression <Func <TSourceItem, bool> > predicateExpression,
                          int sourceCapacity, int capacity) : base(capacity)
        {
            _initialCapacity   = capacity;
            _filteredPositions = new Positions <Position>(new List <Position>(_initialCapacity));
            _itemInfos         = new List <ItemInfo>(sourceCapacity);
            _sourcePositions   = new Positions <ItemInfo>(_itemInfos);

            _predicateExpressionOriginal = predicateExpression;

            CallToConstantConverter callToConstantConverter =
                new CallToConstantConverter(predicateExpression.Parameters);

            _predicateExpression =
                (Expression <Func <TSourceItem, bool> >)callToConstantConverter.Visit(predicateExpression);
            _predicateContainsParametrizedObservableComputationsCalls =
                callToConstantConverter.ContainsParametrizedObservableComputationCalls;

            if (!_predicateContainsParametrizedObservableComputationsCalls)
            {
                _predicateExpressionInfo = ExpressionWatcher.GetExpressionInfo(_predicateExpression);
                // ReSharper disable once PossibleNullReferenceException
                _predicateFunc = _predicateExpression.Compile();
            }
        }
Exemplo n.º 2
0
        private ItemInfo registerSourceItem(TSourceItem sourceItem, int index, ItemInfo itemInfo = null)
        {
            itemInfo = itemInfo == null?_sourcePositions.Insert(index) : _itemInfos[index];

            ExpressionWatcher watcher;

            if (!_selectorContainsParametrizedObservableComputationsCalls)
            {
                watcher = new ExpressionWatcher(_selectorExpressionInfo, sourceItem);
            }
            else
            {
                Expression <Func <TResultItem> > deparametrizedSelectorExpression =
                    (Expression <Func <TResultItem> >)_selectorExpression.ApplyParameters(new object[] { sourceItem });
                Expression <Func <TResultItem> > selectorExpression =
                    (Expression <Func <TResultItem> >)
                    new CallToConstantConverter().Visit(deparametrizedSelectorExpression);
                // ReSharper disable once PossibleNullReferenceException
                itemInfo.SelectorFunc = selectorExpression.Compile();
                watcher = new ExpressionWatcher(ExpressionWatcher.GetExpressionInfo(selectorExpression));
            }

            watcher.ValueChanged       = expressionWatcher_OnValueChanged;
            itemInfo.ExpressionWatcher = watcher;
            watcher._position          = itemInfo;

            return(itemInfo);
        }
Exemplo n.º 3
0
        public Computing(
            Expression <Func <TResult> > getValueExpression)
        {
            _changeValueAction          = () => setValue(getResult());
            _getValueExpressionOriginal = getValueExpression;

            CallToConstantConverter      callToConstantConverter = new CallToConstantConverter(_getValueExpressionOriginal.Parameters);
            Expression <Func <TResult> > getValueExpression1     =
                (Expression <Func <TResult> >)callToConstantConverter.Visit(_getValueExpressionOriginal);

            // ReSharper disable once PossibleNullReferenceException
            _getValueFunc   = getValueExpression1.Compile();
            _expressionInfo = ExpressionWatcher.GetExpressionInfo(getValueExpression1);
        }
Exemplo n.º 4
0
        private void getNewExpressionWatcherAndPredicateFunc(TSourceItem sourceItem, out ExpressionWatcher watcher, out Func <bool> predicateFunc)
        {
            predicateFunc = null;

            if (!_predicateContainsParametrizedObservableComputationCalls)
            {
                watcher = new ExpressionWatcher(_predicateExpressionInfo, sourceItem);
            }
            else
            {
                Expression <Func <bool> > deparametrizedPredicateExpression =
                    (Expression <Func <bool> >)_predicateExpression.ApplyParameters(new object[] { sourceItem });
                Expression <Func <bool> > predicateExpression =
                    (Expression <Func <bool> >)
                    new CallToConstantConverter().Visit(deparametrizedPredicateExpression);
                predicateFunc = predicateExpression.Compile();
                watcher       = new ExpressionWatcher(ExpressionWatcher.GetExpressionInfo(predicateExpression));
            }
        }
Exemplo n.º 5
0
        public Computing(
            Expression <Func <TResult> > getValueExpression)
        {
            if (getValueExpression != null)
            {
                _getValueExpressionOriginal = getValueExpression;
                Expression <Func <TResult> > getValueExpression1 =
                    (Expression <Func <TResult> >) new CallToConstantConverter(_getValueExpressionOriginal.Parameters).Visit(_getValueExpressionOriginal);
                // ReSharper disable once PossibleNullReferenceException
                _getValueFunc = getValueExpression1.Compile();
                _getValueExpressionWatcher = new ExpressionWatcher(ExpressionWatcher.GetExpressionInfo(getValueExpression1));
                _getValueExpressionWatcher.ValueChanged = getValueExpressionWatcherOnValueChanged;

                setValue(getResult());
            }
            else
            {
                _isDefaulted = true;
                setValue(default(TResult));
            }
        }
Exemplo n.º 6
0
        private Selecting(Expression <Func <TSourceItem, TResultItem> > selectorExpression, int capacity) : base(capacity)
        {
            _itemInfos       = new List <ItemInfo>(capacity);
            _sourcePositions = new Positions <ItemInfo>(_itemInfos);

            _selectorExpressionOriginal = selectorExpression;
            CallToConstantConverter callToConstantConverter =
                new CallToConstantConverter(_selectorExpressionOriginal.Parameters);

            _selectorExpression =
                (Expression <Func <TSourceItem, TResultItem> >)callToConstantConverter.Visit(
                    _selectorExpressionOriginal);
            _selectorContainsParametrizedObservableComputationsCalls =
                callToConstantConverter.ContainsParametrizedObservableComputationCalls;

            if (!_selectorContainsParametrizedObservableComputationsCalls)
            {
                _selectorExpressionInfo = ExpressionWatcher.GetExpressionInfo(_selectorExpression);
                // ReSharper disable once PossibleNullReferenceException
                _selectorFunc = _selectorExpression.Compile();
            }
        }