Quantcast
Channel: ClearScript
Viewing all articles
Browse latest Browse all 2297

New Post: Cannot use Action/Function in PropertBag in JScript/V8

0
0
I have created a new class that inherits a PropertyBag (but tried it direct also) so that I can create some standard Actions or Functions automatically when the Bag is created.
Code Below :
        public class ConfigBag : PropertyBag
        {
            private const String stdkeys = "bagkeys,doit";
            public ConfigBag()
            {
                this["bagkeys"] = new Func<String>(() => this.bagkeys());
                this["doit"] = new Action(() => this.doit());
            }

            public String bagkeys()
            {
                List<String> keys = this.Keys.ToList();
                foreach (String k in stdkeys.Split(new char[] { ',' }))
                {
                    keys.Remove(k);
                }
                return String.Join(",", keys.ToArray());                
            }

            public void doit()
            {
                Debug.Print("Got here : ");
            }
        }

            public ConfigBag newbag()
            {
                ConfigBag bag = new ConfigBag();
                bag.Add("Name", "Richard");
                bag.Add("Age", 21);
                bag.Add("FootBall", "Arsenal");
                return bag;
            }
When I execute this from VBScript
x = api.newbag()
debug.log(x.Name)
debug.log(x.Age)
debug.log(x.bagkeys)
debug.log(x.doit)
It all works fine ...

Name,Age,FootBall

But when I execute it from JScript of V8 (exactly the same code) I get

System.Func`1[System.String]

Hitting my head against a wall here! Am I missing something? I am trying to make a standard interface between VBScript and JScript or V8. I need the PropertyBag type functionality which works but I cannot do things like use ".ContainsKey" plus like the idea of adding additional functionality.

Viewing all articles
Browse latest Browse all 2297