예제 #1
0
        /// <summary>
        /// Constructs a builder used to build the deserialized collection
        /// </summary>
        /// <param name="collection">an existing collection object or null for a new collection</param>
        /// <param name="list">the list expression</param>
        /// <param name="itemType">the type of the items</param>
        /// <returns>collection builder</returns>
        protected virtual ICollectionBuilder ConstructBuilder(object collection, ArrayExpression list, out Type itemType)
        {
            Type listType = collection != null?collection.GetType() : list.ResultType;

            ITypeData         typeHandler = Settings.Types[listType];
            CollectionHandler collHandler = typeHandler.CollectionHandler;

            itemType = collHandler.GetItemType(listType);
            if (itemType == null)
            {
                throw new Exception("Null item type returned from " + collHandler.GetType() + " for Collection type: " + listType);
            }

            if (collection != null)
            {
                return(collHandler.ConstructBuilder(collection));
            }
            else
            {
                return(collHandler.ConstructBuilder(listType, list.Items.Count));
            }
        }