// Copyright (c) 2019 - Blazored // Copyright (c) 2020 - Adaptations by Jonny Larsson and Meinrad Recheis using System.Collections; namespace Connected.Components; public class DialogParameters : IEnumerable> { internal Dictionary _parameters; public DialogParameters() { _parameters = new Dictionary(); } public void Add(string parameterName, object value) { _parameters[parameterName] = value; } public T Get(string parameterName) { if (_parameters.TryGetValue(parameterName, out var value)) { return (T)value; } throw new KeyNotFoundException($"{parameterName} does not exist in Dialog parameters"); } public T TryGet(string parameterName) { if (_parameters.TryGetValue(parameterName, out var value)) { return (T)value; } return default; } public int Count => _parameters.Count; public object this[string parameterName] { get => Get(parameterName); set => _parameters[parameterName] = value; } public IEnumerator> GetEnumerator() { return _parameters.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() { return _parameters.GetEnumerator(); } }