コード例 #1
0
        public static void SpawnTo <T>(this Type alias, object[] KnownTypes, Action <T, IHTMLElement> h)
            where T : class, new()
        {
            if (KnownTypes == null)
            {
                throw new Exception("GetKnownTypes is null");
            }

            ScriptCoreLib.JavaScript.Native.Spawn(alias.Name,
                                                  i =>
            {
                if (i.nodeName == "SCRIPT")
                {
                    var tag  = (IHTMLScript)i;
                    var text = i.text;

                    if (tag.type == "text/xml")
                    {
                        var doc = IXMLDocument.Parse(text);

                        h(doc.Deserialize <T>(KnownTypes), i);
                    }
                    else if (tag.type == "text/json")
                    {
                        // reflection info will be lost here?

                        h((T)(object)Expando.FromJSON(text), i);
                    }
                }
            }
                                                  );
        }