Beispiel #1
0
        internal static ScriptObject FromManaged(ScriptExecutor x, object obj)
        {
            if (obj == null)
            {
                return(new ScriptObject(x, obj));
            }

            System.Type t = obj.GetType();

            // 配列に変換
            if (t.IsArray && ((System.Array)obj).Rank == 1)
            {
                object[] arr = (object[])obj;
                Array    a   = (Array)x.execFunc("var a=[];document.body['<mwg:root>'].creatingArrays.push(a);return a;");
                for (int i = 0, m = arr.Length; i < m; i++)
                {
                    x.execSub("$[0].push($[1]);", a, x.FromManaged(arr[i]));
                }
                return(a);
            }

            ScriptObject r = new ScriptObject(x, obj);

            if (t == typeof(string) || t.IsValueType)
            {
                return(r);
            }

            // 具体化
            if (r.instanceof("Array"))
            {
                return(new Array(x, obj));
            }
            else
            {
                switch (r.@typeof)
                {
                case "object":
                case "unknown":
                case "number":
                case "string":
                case "null":
                default:
                    return(r);
                }
            }
        }
Beispiel #2
0
 public ScriptObject InvokeMember(string name)
 {
     return(x.execFunc("return $[0]['" + resolveName(name) + "']();", this));
 }