using System.Collections; using System.Collections.Generic; using System.Dynamic; namespace HeuristicLab.Scripting { public class Variables : DynamicObject, IEnumerable> { private readonly VariableStore variableStore; public ICollection Keys { get { return variableStore.Keys; } } public ICollection Values { get { return variableStore.Values; } } public Variables(VariableStore variableStore) { this.variableStore = variableStore; } public override bool TryGetMember(GetMemberBinder binder, out object result) { return variableStore.TryGetValue(binder.Name, out result); } public override bool TrySetMember(SetMemberBinder binder, object value) { variableStore[binder.Name] = value; return true; } public bool Contains(string variableName) { return variableStore.ContainsKey(variableName); } public IEnumerator> GetEnumerator() { return variableStore.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } } }