#nullable enable
using System;
using System.Collections.Generic;
using IronPython.Runtime.Operations;
namespace IronPython.Runtime {
[Serializable]
internal class EmptyDictionaryStorage : DictionaryStorage {
public static EmptyDictionaryStorage Instance = new EmptyDictionaryStorage();
private EmptyDictionaryStorage() {
}
public override void Add(ref DictionaryStorage storage, object? key, object? value) {
lock (this) {
if (storage == this) {
CommonDictionaryStorage newStorage = new CommonDictionaryStorage();
newStorage.AddNoLock(key, value);
storage = newStorage;
return;
}
}
storage.Add(ref storage, key, value);
}
public override bool Remove(ref DictionaryStorage storage, object? key) {
return false;
}
public override DictionaryStorage AsMutable(ref DictionaryStorage storage) {
lock (this) {
if (storage == this) {
return storage = new CommonDictionaryStorage();
}
}
return storage.AsMutable(ref storage);
}
public override void Clear(ref DictionaryStorage storage) {
}
public override bool Contains(object? key) {
if (PythonContext.IsHashable(key)) {
return false;
}
throw PythonOps.TypeErrorForUnhashableObject(key);
}
public override bool TryGetValue(object? key, out object? value) {
value = null;
return false;
}
public override int Count {
get { return 0; }
}
public override List<KeyValuePair<object?, object?>> GetItems() {
return new List<KeyValuePair<object?, object?>>();
}
public override DictionaryStorage Clone() {
return this;
}
public override bool HasNonStringAttributes() {
return false;
}
}
}