Example #1
0
        public override bool Read(DeserializationContext context, out Object outVal)
        {
            uint refId = context.Reader.ReadUInt32();

            // this 'special' object indicates that we haven't read a real object, but will read it later on
            outVal = new DelayedReferenceHolder(refId);
            return(true);
        }
Example #2
0
        public bool Read(DeserializationContext context, uint id, uint count, Object type, out Object outVal)
        {
            bool ret = true;

            Array array;

            if (type is BinaryPrimitiveTypeCode)
            {
                // this is a primitive array
                array = ReadPrimitiveTypeArray(context, (BinaryPrimitiveTypeCode)type, (int)count);
            }
            else if (type is Type)
            {
                // this is an object array
                Type convertedType = (Type)type;
                array = Array.CreateInstance(convertedType, (int)count);
                for (int i = 0; i < count; i++)
                {
                    Object val;
                    ret &= ReadValue(context, out val);

                    if (val is DelayedReferenceHolder)
                    {
                        // record this index for fixup
                        DelayedReferenceHolder holder = (DelayedReferenceHolder)val;
                        context.Manager.RecordArrayElementFixup(id, i, holder.ReferenceId);
                    }
                    else if (val is ArrayNullValueHolder)
                    {
                        ArrayNullValueHolder holder = (ArrayNullValueHolder)val;
                        for (int j = 0; j < holder.NumNullValues; j++)
                        {
                            array.SetValue(null, i);
                            i++;
                        }
                    }
                    else
                    {
                        // set this value
                        array.SetValue(val, i);
                    }
                }
            }
            else
            {
                throw new SerializationException("illegal call with:" + type);
            }

            context.Manager.RegisterObject(array, id);
            outVal = array;

            return(ret);
        }
	public override bool Read(DeserializationContext context, out Object outVal)
	{
		uint refId = context.Reader.ReadUInt32();

		// this 'special' object indicates that we haven't read a real object, but will read it later on
		outVal = new DelayedReferenceHolder(refId);
		return true;
	}
Example #4
0
        public bool Read(DeserializationContext context, out Object outVal, uint id, TypeInfo typeInfo)
        {
            bool ret = true;

            // create instance
            Object            obj  = null;
            SerializationInfo info = null;

            if (typeInfo.IsISerializable)
            {
                info = typeInfo.GetSerializationInfo();

                // create instance
                obj = FormatterServices.GetUninitializedObject(typeInfo.ObjectType);

                // read and set values
                for (uint i = 0; i < typeInfo.NumMembers; i++)
                {
                    // first get inlined data
                    Object memberValue;
                    if (typeInfo.GetTypeTag(i) == BinaryTypeTag.PrimitiveType)
                    {
                        memberValue = ReadPrimitiveType(context, typeInfo.GetTypeSpecification(i).GetPrimitiveType());
                    }
                    else
                    {
                        ret &= ReadValue(context, out memberValue);
                    }

                    // set value
                    String field = typeInfo.GetFieldName(i);
                    if (memberValue is DelayedReferenceHolder)
                    {
                        // this is a reference
                        DelayedReferenceHolder holder = (DelayedReferenceHolder)memberValue;
                        context.Manager.RecordDelayedFixup(id, field, holder.ReferenceId);
                    }
                    else
                    {
                        // this is a real value
                        info.AddValue(field, memberValue, typeInfo.GetTypeSpecification(i).GetObjectType(context));
                    }
                }
                context.Manager.RegisterObject(obj, id, info);
            }
            else
            {
                // create instance
                obj = FormatterServices.GetUninitializedObject(typeInfo.ObjectType);

                // read and set values
                for (uint i = 0; i < typeInfo.NumMembers; i++)
                {
                    // first get inlined data
                    Object memberValue;
                    if (typeInfo.GetTypeTag(i) == BinaryTypeTag.PrimitiveType)
                    {
                        memberValue = ReadPrimitiveType(context, typeInfo.GetTypeSpecification(i).GetPrimitiveType());
                    }
                    else
                    {
                        ret &= ReadValue(context, out memberValue);
                    }

                    // set value
                    MemberInfo field = typeInfo.GetMember(i);
                    if (memberValue is DelayedReferenceHolder)
                    {
                        // this is a reference
                        DelayedReferenceHolder holder = (DelayedReferenceHolder)memberValue;
                        context.Manager.RecordFixup(id, field, holder.ReferenceId);
                    }
                    else
                    {
                        // this is a real value
                        if (field is FieldInfo)
                        {
                            FieldInfo fi = (FieldInfo)field;
                            fi.SetValue(obj, memberValue);
                        }
                        // TODO: i'm not sure if I have to cover that case, too!
                        // I just noticed that Mono does this
                        //				else if(field is PropertyInfo)
                        //				{
                        //					PropertyInfo pi = (PropertyInfo) field;
                        //					pi.SetValue();
                        else
                        {
                            throw new SerializationException("unknown memeber type:" + field.GetType());
                        }
                    }
                }
                context.Manager.RegisterObject(obj, id);
            }
            outVal = obj;
            return(ret);
        }