variable declaration- problem with own datattype

May 21, 2013 at 9:53 AM
hello,
i have this classes:
public class SessionConstructor : ClrFunction
    {

        public SessionConstructor(ScriptEngine engine, string path) : base(engine.Function.InstancePrototype, "Session", new SessionInstance(engine.Object.InstancePrototype, path))
        {
        }

        [JSConstructorFunction()]
        public SessionInstance Construct(string path)
        {
            return new SessionInstance(this.InstancePrototype, path);
        }
    }

    public class SessionInstance : ObjectInstance
    {

        private Dictionary<string, object> _items = new Dictionary<string, object>();

        private string path;
        public SessionInstance(ObjectInstance prototype, string path) : base(prototype)
        {
            this.path = path;
            if (System.IO.File.Exists(path + "\\sessions")) {
                load();
            }
            this.PopulateFunctions();
        }

        [JSFunction(Name = "Add")]
        public void Add(string k, string v)
        {
            if (_items.ContainsKey(k)) {
                _items[k] = v;
            } else {
                _items.Add(k, v);
            }
            Save();
        }

        [JSFunction(Name = "Get")]
        public string Get(string k)
        {
            if (_items.ContainsKey(k)) {
                return _items[k];
            }
            return "";
        }

        private void Save()
        {
            StringBuilder c = new StringBuilder();

            foreach (object l_loopVariable in _items) {
                l = l_loopVariable;
                c.AppendLine(l.Key + "=" + l.Value.ToString);
            }

            System.IO.File.WriteAllText(path + "\\sessions", c.ToString());
        }

        private void load()
        {
            _items.Clear();

            foreach (object l_loopVariable in System.IO.File.ReadAllLines(path + "\\sessions")) {
                l = l_loopVariable;
                string k = l.Split("=")(0);
                string v = l.Split("=")(1);

                _items.Add(k, v);
            }

        }

        [JSFunction(Name = "Destroy")]
        public void Destroy()
        {
            System.IO.File.Delete(path + "\\sessions");
            _items.Clear();
        }

        [JSFunction(Name = "Unset")]
        public void Unset(string k)
        {
            _items.Remove(k);
            Save();
        }

    }
and i will use this in javascript-code:
var session = new Session(AddinPath);
        
        session.Add("d",now);
but this make nothing.
please help me