/// <summary>
        /// Reads a collection of objects which implement ICustomSerializable from the current stream.
        /// </summary>
        public List <T> ReadList <T>() where T : ICustomSerializable, new()
        {
            int count = ReadInt32();

            if (count == -1)
            {
                return(null);
            }
            else
            {
                List <T> list = SafeMemoryAllocator.CreateList <T>(count);

                for (int i = 0; i < count; i++)
                {
                    if (ReadBoolean())
                    {
                        T item = new T();

                        item.Deserialize(this);

                        list.Add(item);
                    }
                    else
                    {
                        list.Add(default(T));
                    }
                }
                return(list);
            }
        }
Пример #2
0
        private static IEnumerable <string> ReadSegments(
            IPrimitiveReader reader,
            char segmentDelimiter)
        {
            int count = reader.ReadVarInt32();

            if (count == 0)
            {
                yield break;
            }

            var segments = SafeMemoryAllocator.CreateList <string>(count);

            for (; count > 0; --count)
            {
                segments.Add(ReadString(reader));
            }

            var builder = new StringBuilder();

            count = reader.ReadVarInt32();
            for (; count > 0; --count)
            {
                while (true)
                {
                    int segmentId = reader.ReadVarInt32();
                    if (segmentId < 0)
                    {
                        builder.Append(segments[-segmentId - 1]);
                        break;
                    }
                    builder.Append(segments[segmentId - 1]);
                    builder.Append(segmentDelimiter);
                }
                yield return(builder.ToString());

                builder.Length = 0;
            }
        }