csharp/1996v/Bssom.Net/Bssom.Serializer/Internal/Lookup.cs

Lookup.cs
//using System.Runtime.CompilerServices;

using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace Bssom.Serializer.Internal
{
    internal clast Lookup : ILookup
    {
        private readonly Dictionary groupings;

        public Lookup(IEnumerable elements)
        {
            groupings = new Dictionary();
            foreach (IGrouping item in elements)
            {
                groupings.Add(item.Key, item);
            }
        }

        public IEnumerable this[TKey key] => groupings[key];

        public int Count => groupings.Count;

        public bool Contains(TKey key)
        {
            return groupings.ContainsKey(key);
        }

        public IEnumerator GetEnumerator()
        {
            return groupings.Values.GetEnumerator();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return groupings.Values.GetEnumerator();
        }
    }
}