Пример #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);
                }
            }
        }
Пример #2
0
 /// <summary>
 /// メンバにアクセスします。
 /// </summary>
 /// <param name="name">メンバの名前を指定します。</param>
 /// <returns>指定した名前のメンバを返します。</returns>
 public ScriptObject this[string name] {
     get{ return(x.execFunc("return $[0]['" + resolveName(name) + "'];", this)); }
     set{ x.execSub("$[0]['" + resolveName(name) + "']=$[1];", this, value); }
 }