protected internal override T Deserialize(
            IntermediateReader input, ContentSerializerAttribute format, T existingInstance)
        {
            var elements = PackedElementsHelper.ReadElements(input);

            if (elements.Length < _elementCount)
            {
                ThrowElementCountException();
            }

            var index = 0;

            return(Deserialize(elements, ref index));
        }
        protected internal void Deserialize(IntermediateReader input, List <T> results)
        {
            var elements = PackedElementsHelper.ReadElements(input);

            for (var index = 0; index < elements.Length;)
            {
                if (elements.Length - index < _elementCount)
                {
                    ThrowElementCountException();
                }

                var elem = Deserialize(elements, ref index);
                results.Add(elem);
            }
        }
        protected internal override CurveKeyCollection Deserialize(
            IntermediateReader input,
            ContentSerializerAttribute format,
            CurveKeyCollection existingInstance)
        {
            var result = existingInstance ?? new CurveKeyCollection();

            if (input.Xml.HasValue)
            {
                var elements = PackedElementsHelper.ReadElements(input);
                if (elements.Length > 0)
                {
                    // Each CurveKey consists of 5 elements
                    if (elements.Length % 5 != 0)
                    {
                        throw new InvalidContentException(
                                  "Elements count in CurveKeyCollection is inncorect!");
                    }
                    try
                    {
                        // Parse all CurveKeys
                        for (int i = 0; i < elements.Length; i += 5)
                        {
                            // Order: Position, Value, TangentIn, TangentOut and Continuity
                            var curveKey = new CurveKey
                                               (XmlConvert.ToSingle(elements[i]),
                                               XmlConvert.ToSingle(elements[i + 1]),
                                               XmlConvert.ToSingle(elements[i + 2]),
                                               XmlConvert.ToSingle(elements[i + 3]),
                                               (CurveContinuity)Enum.Parse(
                                                   typeof(CurveContinuity),
                                                   elements[i + 4],
                                                   true));
                            result.Add(curveKey);
                        }
                    }
                    catch (Exception e)
                    {
                        throw new InvalidContentException
                                  ("Error parsing CurveKey", e);
                    }
                }
            }
            return(result);
        }