Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Scripting/3.3/Variables.cs @ 10566

Last change on this file since 10566 was 10566, checked in by abeham, 10 years ago

#2136:

  • Made Variables class public (could be used in other scripts as well)
  • Renamed ItemName to "C# Script"
File size: 1.2 KB
Line 
1using System.Collections;
2using System.Collections.Generic;
3using System.Dynamic;
4
5namespace HeuristicLab.Scripting {
6  public class Variables : DynamicObject, IEnumerable<KeyValuePair<string, object>> {
7    private readonly VariableStore variableStore;
8
9    public ICollection<string> Keys {
10      get { return variableStore.Keys; }
11    }
12
13    public ICollection<object> Values {
14      get { return variableStore.Values; }
15    }
16
17    public Variables(VariableStore variableStore) {
18      this.variableStore = variableStore;
19    }
20
21    public override bool TryGetMember(GetMemberBinder binder, out object result) {
22      return variableStore.TryGetValue(binder.Name, out result);
23    }
24
25    public override bool TrySetMember(SetMemberBinder binder, object value) {
26      variableStore[binder.Name] = value;
27      return true;
28    }
29
30    public bool Contains(string variableName) {
31      return variableStore.ContainsKey(variableName);
32    }
33
34    public IEnumerator<KeyValuePair<string, object>> GetEnumerator() {
35      return variableStore.GetEnumerator();
36    }
37
38    IEnumerator IEnumerable.GetEnumerator() {
39      return GetEnumerator();
40    }
41  }
42}
Note: See TracBrowser for help on using the repository browser.