Esempio n. 1
0
        public override object ReadValueNotExisted(HessianReader reader, HessianContext context, Type objectType, byte initialOctet)
        {
            int  len         = 0;
            Type elementType = null;

            if (0x70 <= initialOctet && initialOctet <= 0x77)
            {
                elementType = ((Type)TypeConverter.ReadValue(reader, context, null)).GetElementType();
                len         = initialOctet - 0x70;
            }
            else if (0x78 <= initialOctet && initialOctet <= 0x7f)
            {
                elementType = typeof(object);
                len         = initialOctet - 0x78;
            }
            else if (Constants.BC_LIST_FIXED_UNTYPED == initialOctet)
            {
                elementType = typeof(object);
                len         = (int)IntConverter.ReadValue(reader, context, typeof(int));
            }
            else if (Constants.BC_LIST_FIXED == initialOctet)
            {
                elementType = ((Type)TypeConverter.ReadValue(reader, context, null)).GetElementType();
                len         = (int)IntConverter.ReadValue(reader, context, typeof(int));
            }

            var array = Array.CreateInstance(elementType, len);

            context.ValueRefs.AddItem(array);

            HessianConverter itemConverter = null;

            if (elementType == typeof(object))
            {
                itemConverter = AutoConverter;
            }
            else
            {
                itemConverter = AutoConverter.GetConverter(elementType);
            }

            for (int i = 0; i < len; i++)
            {
                var item = itemConverter.ReadValue(reader, context, elementType);
                array.SetValue(item, i);
            }
            return(array);
        }
Esempio n. 2
0
        public override object ReadValueNotExisted(HessianReader reader, HessianContext context, Type objectType, byte initialOctet)
        {
            Type             listType      = null;
            Type             elementType   = null;
            HessianConverter itemConverter = null;

            if (Constants.BC_LIST_VARIABLE_UNTYPED == initialOctet)
            {
                listType      = typeof(List <object>);
                elementType   = typeof(object);
                itemConverter = AutoConverter;
            }
            else if (Constants.BC_LIST_VARIABLE == initialOctet)
            {
                listType      = (Type)TypeConverter.ReadValue(reader, context, null);
                elementType   = listType.GenericTypeArguments[0];
                itemConverter = AutoConverter.GetConverter(elementType);
            }
            else
            {
                throw Exceptions.UnExpectedInitialOctet(this, initialOctet);
            }

            var addMethod = listType.GetMethod("Add");
            var list      = Activator.CreateInstance(listType);

            context.ValueRefs.AddItem(list);

            initialOctet = reader.ReadByte();
            var parameters = new object[1];

            while (Constants.BC_END != initialOctet)
            {
                parameters[0] = itemConverter.ReadValue(reader, context, elementType, initialOctet);
                addMethod.Invoke(list, parameters);
                initialOctet = reader.ReadByte();
            }
            return(list);
        }