Пример #1
0
        public static JSBCollection FromCollection(IEnumerable collection)
        {
            JSBCollection col = new JSBCollection();

            foreach (object obj in collection)
            {
                col.Collection.Add(JSBObject.FromAnonymous(obj));
            }
            return(col);
        }
Пример #2
0
        public static object FromAnonymous(object obj)
        {
            Type t = obj.GetType();

            if (t.IsObject())
            {
                //List/Array
                if (t.IsList() || t.IsArray())
                {
                    return(JSBCollection.FromCollection((IEnumerable)obj));
                }
                //Object
                else
                {
                    return(FromObject(obj));
                }
            }
            else
            {
                return(obj);
            }
        }
Пример #3
0
        public void AddObject(string name, object val)
        {
            Type t = val.GetType();

            if (t.IsObject())
            {
                //List
                if (t.IsList() || t.IsArray())
                {
                    Properties.Add(name, JSBCollection.FromCollection((IEnumerable)val));
                }
                //Object
                else if (t == typeof(JSBObject) || t == typeof(JSBCollection) || t == typeof(JSBFunction))
                {
                    Properties.Add(name, val);
                }
                else
                {
                    Properties.Add(name, FromObject(val));
                }
            }
            else
            {
                AddProperty(name, val);

                /*
                 * new Switcher()
                 *  .Case(typeof(String), () => AddProperty(name, (string)val))
                 *  .Case(typeof(int), () => AddProperty(name, (int)val))
                 *  .Case(typeof(short), () => AddProperty(name, (short)val))
                 *  .Case(typeof(long), () => AddProperty(name, (long)val))
                 *  .Case(typeof(bool), () => AddProperty(name, (bool)val))
                 *  .Case(typeof(byte), () => AddProperty(name, (byte)val))
                 *  .Switch(val);*/
            }
        }