示例#1
0
        /// <summary>
        /// Processes the items.
        /// </summary>
        /// <returns>IEnumerable{`0}.</returns>
        public virtual List <T> ProcessItems()
        {
            if (_service == null)
            {
                throw new NullReferenceException("SitecoreService has not been set");
            }

            var items = _options.GetItems(_service.Database);



            if (items == null)
            {
                items = new Item[] {};
            }

            items = items.ToArray();

            var results = new List <T>();

            var options = new GetItemByItemOptions();

            options.Copy(_options);
            //we have to copy these properties to the sub item because
            //normally they are not applied to the whole graph
            options.TemplateId      = _options.TemplateId;
            options.EnforceTemplate = _options.EnforceTemplate;


            foreach (Item child in items)
            {
                options.Item = child;
                var obj = _service.GetItem(options) as T;

                if (obj == null)
                {
                    continue;
                }

                results.Add(obj);
            }

            //release the service after full enumeration
            _service = null;

            return(results);
        }
        /// <summary>
        /// Processes the items.
        /// </summary>
        /// <returns>IEnumerable{`0}.</returns>
        public virtual List <T> ProcessItems()
        {
            if (_service == null)
            {
                throw new NullReferenceException("SitecoreService has not been set");
            }

            var items = _options.GetItems(_service.Database);



            if (items == null)
            {
                items = new Item[] {};
            }

            items = items.ToArray();

            var results = new List <T>();

            var options = new GetItemByItemOptions();

            options.Copy(_options);

            foreach (Item child in items)
            {
                options.Item = child;
                var obj = _service.GetItem(options) as T;

                if (obj == null)
                {
                    continue;
                }

                results.Add(obj);
            }

            //release the service after full enumeration
            _service = null;

            return(results);
        }