Exemple #1
0
        /// <summary>
        ///     Creates the chain.
        /// </summary>
        /// <param name="parameter1">The parameter1.</param>
        /// <param name="tree">The nodes.</param>
        /// <exception cref="NotSupportedException">Expression Tree Node not supported.</exception>
        protected void CreateChain(INotifyPropertyChanged parameter1, IRootAware tree)
        {
            foreach (var treeRoot in tree.Roots)
            {
                switch (treeRoot)
                {
                case ParameterNode parameterElement:
                {
                    if (!(parameterElement.Next is PropertyNode propertyElement))
                    {
                        continue;
                    }

                    var root = new RootPropertyObserverNode(
                        propertyElement.PropertyInfo,
                        this.OnAction,
                        parameter1);
                    this.LoopTree(propertyElement, root);
                    this.RootNodes.Add(root);
                    break;
                }

                case ConstantNode constantElement when treeRoot.Next is FieldNode fieldElement:
                {
                    if (!(fieldElement.Next is PropertyNode propertyElement))
                    {
                        continue;
                    }

                    var root = new RootPropertyObserverNode(
                        propertyElement.PropertyInfo,
                        this.OnAction,
                        (INotifyPropertyChanged)fieldElement.FieldInfo.GetValue(constantElement.Value));

                    this.LoopTree(propertyElement, root);
                    this.RootNodes.Add(root);
                    break;
                }

                case ConstantNode constantElement:
                {
                    if (!(treeRoot.Next is PropertyNode propertyElement))
                    {
                        continue;
                    }

                    var root = new RootPropertyObserverNode(
                        propertyElement.PropertyInfo,
                        this.OnAction,
                        (INotifyPropertyChanged)constantElement.Value !);

                    this.LoopTree(propertyElement, root);
                    this.RootNodes.Add(root);

                    break;
                }

                default:
                    throw new NotSupportedException();
                }
            }
        }
        /// <summary>
        ///     Creates the chain.
        /// </summary>
        /// <param name="parameter1">The parameter1.</param>
        /// <param name="parameter2">The parameter2.</param>
        /// <param name="nodes">The nodes.</param>
        /// <exception cref="NotSupportedException">Expression Tree Node not supported.</exception>
        private void CreateChain(TParameter1 parameter1, TParameter2 parameter2, IRootAware nodes)
        {
            foreach (var treeRoot in nodes.Roots)
            {
                switch (treeRoot)
                {
                case ParameterNode parameterElement:
                {
                    if (!(parameterElement.Next is PropertyNode propertyElement))
                    {
                        continue;
                    }

                    var parameterGetter = ExpressionGetter.CreateParameterGetter(
                        parameterElement,
                        this.propertyExpression);
                    var root = new RootPropertyObserverNode(
                        propertyElement.PropertyInfo,
                        this.OnAction,
                        (INotifyPropertyChanged)parameterGetter(parameter1, parameter2));

                    this.LoopTree(propertyElement, root);
                    this.RootNodes.Add(root);
                    break;
                }

                case ConstantNode constantElement when treeRoot.Next is FieldNode fieldElement:
                {
                    if (!(fieldElement.Next is PropertyNode propertyElement))
                    {
                        continue;
                    }

                    var root = new RootPropertyObserverNode(
                        propertyElement.PropertyInfo,
                        this.OnAction,
                        (INotifyPropertyChanged)fieldElement.FieldInfo.GetValue(constantElement.Value));

                    this.LoopTree(propertyElement, root);
                    this.RootNodes.Add(root);
                    break;
                }

                case ConstantNode constantElement:
                {
                    if (!(treeRoot.Next is PropertyNode propertyElement))
                    {
                        continue;
                    }

                    var root = new RootPropertyObserverNode(
                        propertyElement.PropertyInfo,
                        this.OnAction,
                        (INotifyPropertyChanged)constantElement.Value !);

                    this.LoopTree(propertyElement, root);
                    this.RootNodes.Add(root);

                    break;
                }

                default:
                    throw new NotSupportedException();
                }
            }
        }