using System.Collections.Generic;
namespace SabreTools.Models.Internal
{
///
/// Specialized dictionary base for item types
///
public abstract class DictionaryBase : Dictionary
{
///
/// Read a key as the specified type, returning null on error
///
public T? Read(string key)
{
if (string.IsNullOrWhiteSpace(key))
return default;
if (!ContainsKey(key))
return default;
return (T?)this[key];
}
///
/// Read a key as a bool, returning null on error
///
public bool? ReadBool(string key) => Read(key);
///
/// Read a key as a double, returning null on error
///
public double? ReadDouble(string key) => Read(key);
///
/// Read a key as a long, returning null on error
///
public long? ReadLong(string key) => Read(key);
///
/// Read a key as a string, returning null on error
///
public string? ReadString(string key) => Read(key);
///
/// Read a key as a string[], returning null on error
///
public string[]? ReadStringArray(string key) => Read(key);
}
}