Esempio n. 1
0
        /// <summary>
        /// Get field with builder.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="fieldName"></param>
        /// <param name="builder"></param>
        /// <returns></returns>
        public T Field <T>(string fieldName, PortableBuilderImpl builder)
        {
            IPortableTypeDescriptor desc = _marsh.Descriptor(true, _typeId);

            InitializeFields();

            int fieldId = PortableUtils.FieldId(_typeId, fieldName, desc.NameConverter, desc.Mapper);

            int pos;

            if (_fields.TryGetValue(fieldId, out pos))
            {
                if (builder != null)
                {
                    // Read in scope of build process.
                    T res;

                    if (!builder.CachedField(pos, out res))
                    {
                        res = Field0 <T>(pos, builder);

                        builder.CacheField(pos, res);
                    }

                    return(res);
                }
                return(Field0 <T>(pos, null));
            }
            return(default(T));
        }
Esempio n. 2
0
        /// <summary>
        /// Reads the handle object.
        /// </summary>
        private T ReadHandleObject <T>(int pos)
        {
            // Get handle position.
            int hndPos = pos - Stream.ReadInt();

            int retPos = Stream.Position;

            try
            {
                object hndObj;

                if (_builder == null || !_builder.CachedField(hndPos, out hndObj))
                {
                    if (_hnds == null || !_hnds.TryGetValue(hndPos, out hndObj))
                    {
                        // No such handler, i.e. we trying to deserialize inner object before deserializing outer.
                        Stream.Seek(hndPos, SeekOrigin.Begin);

                        hndObj = Deserialize <T>();
                    }

                    // Notify builder that we deserialized object on other location.
                    if (_builder != null)
                    {
                        _builder.CacheField(hndPos, hndObj);
                    }
                }

                return((T)hndObj);
            }
            finally
            {
                // Position stream to correct place.
                Stream.Seek(retPos, SeekOrigin.Begin);
            }
        }