Quantcast
Viewing all articles
Browse latest Browse all 2297

New Post: dictionary returns undefined

Glad to hear it furesoft, but PropertyBag really should be sufficient for this purpose.

We don't have your HttpProcessor class, but if we modify the Create method as follows:
publicstatic PropertyBag Create(string url) {
    var props = new PropertyBag();
    var q = new Uri("htt://localhost/" + url).Query;
    foreach (var qi in q.Split(new[] { '&', '?' }, StringSplitOptions.RemoveEmptyEntries)) {
        var s = qi.Split('=');
        props.Add(s[0], s[1]);
    }
    return props;
}
Then this test code works as expected:
engine.AddHostObject("_GET", Create("qux.html?foo=123&bar=456&baz=789"));
engine.AddHostType("Console", typeof(Console));
engine.Execute(@"
    Console.WriteLine(_GET['foo']); // prints '123'
    Console.WriteLine(_GET['bar']); // prints '456'
    Console.WriteLine(_GET['baz']); // prints '789'
");
Good luck!

Viewing all articles
Browse latest Browse all 2297

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>