Beispiel #1
0
        private object DeserializeObject(
            Type type,
            long id,
            long parentId,
            MemberInfo parentMemberInfo,
            int[] indices)
        {
            SerializationInfo info      = null;
            bool NeedsSerializationInfo = false;
            bool hasFixup;

            // in case of String & TimeSpan we should allways use 'ReadInternalSoapValue' method
            // in case of other internal types, we should use ReadInternalSoapValue' only if it is NOT
            // the root object, means it is a data member of another object that is being serialized.
            bool shouldReadInternal = (type == typeof(String) || type == typeof(TimeSpan));

            if (shouldReadInternal || mapper.IsInternalSoapType(type) && (indices != null || parentMemberInfo != null))
            {
                object obj = mapper.ReadInternalSoapValue(this, type);

                if (id != 0)
                {
                    RegisterObject(id, obj, info, parentId, parentMemberInfo, indices);
                }

                return(obj);
            }
            object objReturn =
                FormatterServices.GetUninitializedObject(type);

            objMgr.RaiseOnDeserializingEvent(objReturn);
            if (objReturn is ISerializable)
            {
                NeedsSerializationInfo = true;
            }

            if (_surrogateSelector != null && NeedsSerializationInfo == false)
            {
                ISurrogateSelector      selector;
                ISerializationSurrogate surrogate = _surrogateSelector.GetSurrogate(
                    type,
                    _context,
                    out selector);
                NeedsSerializationInfo |= (surrogate != null);
            }

            if (NeedsSerializationInfo)
            {
                objReturn =
                    DeserializeISerializableObject(objReturn, id, out info, out hasFixup);
            }
            else
            {
                objReturn =
                    DeserializeSimpleObject(objReturn, id, out hasFixup);
                if (!hasFixup && objReturn is IObjectReference)
                {
                    objReturn = ((IObjectReference)objReturn).GetRealObject(_context);
                }
            }

            RegisterObject(id, objReturn, info, parentId, parentMemberInfo, indices);
            xmlReader.ReadEndElement();
            return(objReturn);
        }
Beispiel #2
0
        private void SerializeComponent(
            object obj,
            bool specifyEncoding)
        {
            if (_typeFormat == FormatterTypeStyle.TypesAlways)
            {
                specifyEncoding = true;
            }

            // A null component
            if (obj == null)
            {
                Null();
                return;
            }
            Type objType    = obj.GetType();
            bool canBeValue = _mapper.IsInternalSoapType(objType);
            bool firstTime;
            long id = 0;

            // An object already serialized
            if ((id = idGen.HasId(obj, out firstTime)) != 0L)
            {
                Href((long)idGen.GetId(obj, out firstTime));
                return;
            }



            // A string
            if (objType == typeof(string))
            {
                if (_typeFormat != FormatterTypeStyle.XsdString)
                {
                    id = idGen.GetId(obj, out firstTime);
                    Id(id);
                }
//				specifyEncoding = false;
            }

            // This component has to be
            // serialized later
            if (!canBeValue && !objType.IsValueType)
            {
                long href = idGen.GetId(obj, out firstTime);
                Href(href);
                _objectQueue.Enqueue(new EnqueuedObject(obj, href));
                return;
            }

            if (specifyEncoding)
            {
                EncodeType(objType);
            }

            // A struct
            if (!canBeValue && objType.IsValueType)
            {
                SerializeObject(obj, 0);
                return;
            }

            _xmlWriter.WriteString(_mapper.GetInternalSoapValue(this, obj));
        }