Beispiel #1
0
        /// <summary>
        /// Evaluates the items in the expression and assigns them to the collection using the builder
        /// </summary>
        /// <param name="expression">the expression to evaluate</param>
        /// <param name="builder">builder used to build the collection</param>
        /// <param name="itemType">the type of the collection's elements</param>
        /// <param name="deserializer">deserializer instance to deserialize items</param>
        /// <returns>evaluated collection object</returns>
        protected virtual object EvaluateItems(ArrayExpression expression, ICollectionBuilder builder, Type itemType, IDeserializerHandler deserializer)
        {
            object result = null;
            bool   constructedEventSent = false;

            try
            {
                result = builder.GetReference();
                expression.OnObjectConstructed(result);
                constructedEventSent = true;
            }
            catch
            {
                // this might fail if the builder's not ready
            }
            foreach (Expression item in expression.Items)
            {
                item.ResultType = itemType;
                object itemResult = deserializer.Evaluate(item);
                builder.Add(itemResult);
            }
            result = builder.GetResult();
            if (!constructedEventSent)
            {
                expression.OnObjectConstructed(result);
            }
            return(result);
        }