/*
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Collections.Generic;
using QuantConnect.Python;
namespace Common.Util
{
///
/// Provides a read-only implementation of ExtendedDictionary
///
[PandasNonExpandable]
public class ReadOnlyExtendedDictionary : BaseExtendedDictionary, IReadOnlyDictionary
{
///
/// Initializes a new instance of the ReadOnlyExtendedDictionary class that is empty
///
public ReadOnlyExtendedDictionary()
{
}
///
/// Initializes a new instance of the ReadOnlyExtendedDictionary class that contains elements copied from the specified dictionary
///
/// The dictionary whose elements are copied to the new dictionary
public ReadOnlyExtendedDictionary(IDictionary dictionary) : base(dictionary)
{
}
///
/// Initializes a new instance of the ReadOnlyExtendedDictionary class
/// using the specified as a data source
///
/// The data source for this dictionary
/// Delegate used to select a key from the value
public ReadOnlyExtendedDictionary(IEnumerable data, Func keySelector) : base(data, keySelector)
{
}
///
/// Gets a value indicating whether the dictionary is read-only
///
public override bool IsReadOnly => true;
///
/// Gets an enumerable collection containing the keys of the read-only dictionary
///
IEnumerable IReadOnlyDictionary.Keys => base.Keys;
///
/// Gets an enumerable collection containing the values of the read-only dictionary
///
IEnumerable IReadOnlyDictionary.Values => base.Values;
///
/// Gets or sets the value associated with the specified key
///
/// The key of the value to get or set
/// The value associated with the specified key
public override TValue this[TKey key]
{
get => base[key];
set => throw new InvalidOperationException("Dictionary is read-only");
}
///
/// Removes all items from the dictionary
///
public override void Clear()
{
throw new InvalidOperationException("Dictionary is read-only");
}
///
/// Removes the value with the specified key
///
/// The key of the element to remove
/// true if the element was successfully found and removed; otherwise, false
public override bool Remove(TKey key)
{
throw new InvalidOperationException("Dictionary is read-only");
}
///
/// Adds an element with the provided key and value to the dictionary
///
/// The key of the element to add
/// The value of the element to add
public new void Add(TKey key, TValue value)
{
throw new InvalidOperationException("Dictionary is read-only");
}
///
/// Adds an element with the provided key-value pair to the dictionary
///
/// The key-value pair to add
public new void Add(KeyValuePair item)
{
throw new InvalidOperationException("Dictionary is read-only");
}
///
/// Removes the first occurrence of a specific object from the dictionary
///
/// The key-value pair to remove
/// true if the key-value pair was successfully removed; otherwise, false
public new bool Remove(KeyValuePair item)
{
throw new InvalidOperationException("Dictionary is read-only");
}
}
}