Ejemplo n.º 1
0
        public override PObject Clone()
        {
            var array = new PArray();

            foreach (var item in this)
            {
                array.Add(item.Clone());
            }
            return(array);
        }
Ejemplo n.º 2
0
        public PArray GetArray(string key)
        {
            var result = Get <PArray>(key);

            if (result == null)
            {
                this[key] = result = new PArray();
            }

            return(result);
        }
Ejemplo n.º 3
0
        public static PObject FromNSObject(NSObject val)
        {
            if (val == null)
            {
                return(null);
            }

            var dict = val as NSDictionary;

            if (dict != null)
            {
                var result = new PDictionary();
                foreach (var pair in dict)
                {
                    string k = pair.Key.ToString();
                    result[k] = FromNSObject(pair.Value);
                }
                return(result);
            }

            var arr = val as NSArray;

            if (arr != null)
            {
                var  result = new PArray();
                uint count  = arr.Count;
                for (uint i = 0; i < count; i++)
                {
                    var obj = Runtime.GetNSObject(arr.ValueAt(i));
                    if (obj != null)
                    {
                        result.Add(FromNSObject(obj));
                    }
                }
                return(result);
            }

            var str = val as NSString;

            if (str != null)
            {
                return(str.ToString());
            }

            var nr = val as NSNumber;

            if (nr != null)
            {
                char t;
                unsafe {
                    t = (char)*((byte *)MonoMac.ObjCRuntime.Messaging.IntPtr_objc_msgSend(val.Handle, selObjCType));
                }
                if (t == 'c' || t == 'C' || t == 'B')
                {
                    return(nr.BoolValue);
                }
                return(nr.Int32Value);
            }

            var date = val as NSDate;

            if (date != null)
            {
                return((DateTime)date);
            }

            var data = val as NSData;

            if (data != null)
            {
                var bytes = new byte[data.Length];
                System.Runtime.InteropServices.Marshal.Copy(data.Bytes, bytes, 0, (int)data.Length);
                return(bytes);
            }

            throw new NotSupportedException(val.ToString());
        }