using System; using System.Collections.Generic; namespace TLang.VM { public class TDictionary : TObject { public override string Type => "dictonary"; public override bool True => true; public Dictionary Items{get;}=new Dictionary(); public void SetValue(string key,TObject value) { Items[key] = value; } public TObject GetValue(string key) { if(Items.ContainsKey(key)) return Items[key]; return new TUndefined(); } public bool HasValue(string key) { return Items.ContainsKey(key); } public static TDictionary FromIEnumerator(IEnumerator enumerator) { TDictionary dictionary=new TDictionary(); dictionary.SetValue("movenext",new TExternalMethod(e=>{ return new TBool(enumerator.MoveNext()); })); dictionary.SetValue("reset",new TExternalMethod(e=>{ try{ enumerator.Reset(); }catch(Exception ex) { _=ex; return new TBool(false); } return new TBool(true); })); dictionary.SetValue("getcurrent",new TExternalMethod(e=>{ return enumerator.Current; })); return dictionary; } } }