// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Collections.Generic; using System.Linq; namespace Microsoft.AspNetCore.Razor.Language { internal class ReadOnlyItemCollection : ItemCollection { public static readonly ItemCollection Empty = new ReadOnlyItemCollection(); public override object this[object key] { get => null; set => throw new NotSupportedException(); } public override int Count => 0; public override bool IsReadOnly => true; public override void Add(KeyValuePair item) { if (item.Key == null) { throw new ArgumentException(Resources.KeyMustNotBeNull, nameof(item)); } throw new NotSupportedException(); } public override void Clear() { throw new NotSupportedException(); } public override bool Contains(KeyValuePair item) { if (item.Key == null) { throw new ArgumentException(Resources.KeyMustNotBeNull, nameof(item)); } return false; } public override void CopyTo(KeyValuePair[] array, int arrayIndex) { if (array == null) { throw new ArgumentNullException(nameof(array)); } if (arrayIndex < 0 || arrayIndex > array.Length) { throw new ArgumentOutOfRangeException(nameof(arrayIndex)); } else if (array.Length - arrayIndex < Count) { throw new ArgumentOutOfRangeException(nameof(arrayIndex)); } // Do nothing. } public override IEnumerator> GetEnumerator() { return Enumerable.Empty>().GetEnumerator(); } public override bool Remove(KeyValuePair item) { if (item.Key == null) { throw new ArgumentException(Resources.KeyMustNotBeNull, nameof(item)); } throw new NotSupportedException(); } } }