コード例 #1
0
            protected override object MapByteArrayToNative(IActionScriptSerializer serializer, Type nativeType,
                                                           int length, IEnumerable <ArraySegment <byte> > segments)
            {
                ICollection <T> collection = CreateCollectionInstance(length);

                if (typeof(T) == typeof(byte))
                {
                    ICollection <byte> byteCollection = (ICollection <byte>)collection;

                    foreach (ArraySegment <byte> segment in segments)
                    {
                        for (int i = 0; i < segment.Count; i++)
                        {
                            byteCollection.Add(segment.Array[i + segment.Offset]);
                        }
                    }
                }
                else
                {
                    foreach (ArraySegment <byte> segment in segments)
                    {
                        for (int i = 0; i < segment.Count; i++)
                        {
                            IASValue byteValue = new ASInt29(segment.Array[i + segment.Offset]);
                            T        value     = (T)serializer.ToNative(byteValue, typeof(T));
                            collection.Add(value);
                        }
                    }
                }

                return(collection);
            }
コード例 #2
0
        public void MixedValueIndexer()
        {
            ASArray array = new ASArray(0);

            array["abc"] = new ASInt29(1);
            Assert.AreEqual(new ASInt29(1), array["abc"]);

            // do it twice to be sure
            array["abc"] = new ASInt29(2);
            Assert.AreEqual(new ASInt29(2), array["abc"]);
        }
コード例 #3
0
        public void Indexer()
        {
            ASClass  @class = new ASClass("class", ASClassLayout.Dynamic, new string[] { "member" });
            ASObject obj    = new ASObject(@class);

            obj["member"] = new ASInt29(1);
            Assert.AreEqual(new ASInt29(1), obj["member"]);
            Assert.AreEqual(new ASInt29(1), obj.MemberValues[0]);

            obj["nonmember"] = new ASInt29(2);
            Assert.AreEqual(new ASInt29(2), obj["nonmember"]);
            Assert.AreEqual(new ASInt29(2), obj.DynamicProperties["nonmember"]);
        }
コード例 #4
0
        public void ReadObject_Ints_AMF3()
        {
            byte[] bytes         = new byte[] { (byte)AMF0ObjectTypeCode.AMF3Data, (byte)AMF3ObjectTypeCode.Integer, 0x01 };
            int    expectedValue = 1;

            SetStreamContents(bytes);

            input.BeginObjectStream();
            ASInt29 result = (ASInt29)input.ReadObject();

            Assert.AreEqual(AMFObjectEncoding.AMF3, input.ObjectEncoding);
            input.EndObjectStream();

            Assert.AreEqual(expectedValue, result.Value);
        }