fjgandrade / sharpkit

Automatically exported from code.google.com/p/sharpkit
0 stars 0 forks source link

Dictionary setter indexer throws KeyNotFoundException with new items #241

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Trying to insert an item via the dictionary indexer.

    [JsType(JsMode.Clr, Filename = "res/DictionaryTest.js")]
    public class DictionaryTest
    {
        public static void Setter()
        {
            var dict = new Dictionary<string, string>();

            dict.Add("test", "OK"); //OK

            dict["hello"] = "world"; //Throws exception
        }
    }

    [JsType(JsMode.Global, Filename = "res/Default.js")]
    public class DefaultClient
    {
        static void DefaultClient_Load()
        {
            new jQuery(HtmlContext.document.body).append("Ready<br/>");
        }
        static void btnTest_click(DOMEvent e)
        {
            new jQuery(HtmlContext.document.body).append("Hello world<br/>");

            DictionaryTest.Setter();
        }
    }

Doing this results in a KeyNotFoundException. The method seems to have an 
excessive check -

        set_Item$$TKey: function (key, value)
        {
            if (!this.ContainsKey(key))
                throw $CreateException(new System.Collections.Generic.KeyNotFoundException.ctor$$String("The specified key does not exist."), new Error());

This should insert the value - that's the behaviour in C#

/*Generated by SharpKit 5 v5.00.0000*/

Original issue reported on code.google.com by co...@gravill.com on 30 Oct 2012 at 11:51

GoogleCodeExporter commented 9 years ago

Original comment by DanelK...@gmail.com on 30 Oct 2012 at 3:09