Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HiveStatistics/sources/HeuristicLab.Scripting/3.3/Variables.cs @ 11207

Last change on this file since 11207 was 11135, checked in by pfleck, 10 years ago

#2209

  • Added Indexer to Variables for string based access to variables.
  • Updated CSharpScropt code template
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 Variables(VariableStore variableStore) {
10      this.variableStore = variableStore;
11    }
12
13    public override bool TryGetMember(GetMemberBinder binder, out object result) {
14      return variableStore.TryGetValue(binder.Name, out result);
15    }
16
17    public override bool TrySetMember(SetMemberBinder binder, object value) {
18      variableStore[binder.Name] = value;
19      return true;
20    }
21
22    public object this[string key] {
23      get { return variableStore[key]; }
24      set { variableStore[key] = value; }
25    }
26
27    public bool Contains(string variableName) {
28      return variableStore.ContainsKey(variableName);
29    }
30
31    public void Clear() {
32      variableStore.Clear();
33    }
34
35    public IEnumerator<KeyValuePair<string, object>> GetEnumerator() {
36      return variableStore.GetEnumerator();
37    }
38
39    IEnumerator IEnumerable.GetEnumerator() {
40      return GetEnumerator();
41    }
42  }
43}
Note: See TracBrowser for help on using the repository browser.