Ejemplo n.º 1
0
        public static IStateBundle ToStateBundle(this NSDictionary bundle)
        {
            var state = new StateBundle();
            var formatter = new BinaryFormatter();

            if (bundle != null)
            {
                foreach (var key in bundle.Keys)
                {
                    var byteArray = bundle.ObjectForKey(key) as NSArray;
                    if (byteArray != null)
                    {
                        var bytes = new List<byte>();

                        for (nuint i = 0; i < byteArray.Count; i++)
                        {
                            var v = byteArray.GetItem<NSNumber>(i);
                            bytes.Add(v.ByteValue);
                        }

                        using (var stream = new MemoryStream(bytes.ToArray()))
                        {
                            var value = formatter.Deserialize(stream);
                            state.Data[key.ToString()] = value;
                        }
                    }
                }
            }

            return state;
        }
Ejemplo n.º 2
0
        public static IStateBundle ToStateBundle(this Bundle bundle)
        {
            var state = new StateBundle();
            var formatter = new BinaryFormatter();

            if (bundle != null)
            {
                foreach (var key in bundle.KeySet())
                {
                    var bytes = bundle.GetByteArray(key);
                    if (bytes != null)
                    {
                        using (var stream = new MemoryStream(bytes))
                        {
                            var value = formatter.Deserialize(stream);
                            state.Data[key] = value;
                        }
                    }
                }
            }

            return state;
        }