using System.Collections.Generic; namespace Elsa.Models { public class Variables : Dictionary { public static readonly Variables Empty = new Variables(); public Variables() { } public Variables(Variables other) : this((IEnumerable>) other) { } public Variables(IEnumerable> dictionary) { foreach (var item in dictionary) this[item.Key] = item.Value; } public Variables(IEnumerable> dictionary) { foreach (var item in dictionary) SetVariable(item.Key, item.Value); } public object GetVariable(string name) { return ContainsKey(name) ? this[name].Value : default; } public T GetVariable(string name) { object value = GetVariable(name); return (value != default) ? (T)System.Convert.ChangeType(value, typeof(T)) : default(T); } public Variable SetVariable(string name, object value) { return this[name] = new Variable(value); } public Variable SetVariable(string name, Variable variable) { return SetVariable(name, variable.Value); } public void SetVariables(Variables variables) => SetVariables((IEnumerable>) variables); public void SetVariables(IEnumerable> variables) { foreach (var variable in variables) SetVariable(variable.Key, variable.Value); } public bool HasVariable(string name) { return ContainsKey(name); } } }