2021-07-12 15:28:46 -06:00
|
|
|
using System;
|
|
|
|
|
using System.Collections;
|
2016-08-16 10:25:19 +02:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
2021-02-18 11:06:02 +01:00
|
|
|
namespace Umbraco.Cms.Core.Composing
|
2016-08-16 10:25:19 +02:00
|
|
|
{
|
2021-07-12 15:28:46 -06:00
|
|
|
|
2016-08-16 10:25:19 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// Provides a base class for builder collections.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <typeparam name="TItem">The type of the items.</typeparam>
|
|
|
|
|
public abstract class BuilderCollectionBase<TItem> : IBuilderCollection<TItem>
|
|
|
|
|
{
|
2021-07-12 15:28:46 -06:00
|
|
|
private readonly LazyReadOnlyCollection<TItem> _items;
|
2016-08-16 10:25:19 +02:00
|
|
|
|
|
|
|
|
/// Initializes a new instance of the <see cref="BuilderCollectionBase{TItem}"/> with items.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="items">The items.</param>
|
2021-07-12 15:28:46 -06:00
|
|
|
public BuilderCollectionBase(Func<IEnumerable<TItem>> items) => _items = new LazyReadOnlyCollection<TItem>(items);
|
2016-08-16 10:25:19 +02:00
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
2021-07-12 15:28:46 -06:00
|
|
|
public int Count => _items.Count;
|
2016-08-16 10:25:19 +02:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets an enumerator.
|
|
|
|
|
/// </summary>
|
2021-07-12 15:28:46 -06:00
|
|
|
public IEnumerator<TItem> GetEnumerator() => ((IEnumerable<TItem>)_items).GetEnumerator();
|
2016-08-16 10:25:19 +02:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets an enumerator.
|
|
|
|
|
/// </summary>
|
2021-07-12 15:28:46 -06:00
|
|
|
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
2016-08-16 10:25:19 +02:00
|
|
|
}
|
2017-07-20 11:21:28 +02:00
|
|
|
}
|