/// <summary>
        /// Writes the value of the <paramref name="member"/> to the stream.
        /// </summary>
        /// <param name="member">Must not be null.</param>
        /// <param name="writer">Must not be null.</param>
        private void WritePropertyValue(ObjectMemberData member, FileChunkWriter writer)
        {
            var value = member.GetValue(Instance);
            var type  = member.DataType;

            if (value != null)
            {
                switch (Type.GetTypeCode(type))
                {
                case TypeCode.Byte:
                    writer.WriteByte((byte)value);
                    break;

                case TypeCode.Char:
                    writer.WriteChar((char)value);
                    break;

                case TypeCode.Int16:
                    writer.WriteInt16((short)value);
                    break;

                case TypeCode.Int32:
                    writer.WriteInt32((int)value);
                    break;

                case TypeCode.Int64:
                    writer.WriteInt64((long)value);
                    break;

                case TypeCode.String:
                    writer.WriteString((string)value);
                    break;

                case TypeCode.UInt16:
                    writer.WriteUInt16((ushort)value);
                    break;

                case TypeCode.UInt32:
                    writer.WriteUInt32((uint)value);
                    break;

                case TypeCode.UInt64:
                    writer.WriteUInt64((ulong)value);
                    break;

                case TypeCode.Object:
                    WriteObjectValue(writer, value, type);
                    break;

                default:
                    throw new NotSupportedException();
                }
            }
        }
        /// <summary>
        /// Writes all the object's members as data fields to the stream.
        /// </summary>
        /// <param name="writer">Must not be null.</param>
        public void WriteFields(FileChunkWriter writer)
        {
            foreach (var member in _members)
            {
                if (member.ChunkIds != null && member.ChunkIds.Count > 0)
                {
                    throw new NotSupportedException("This method does not support writing chunks. No mixed (chunks and data) types allowed.");
                }

                WritePropertyValue(member, writer);
            }
        }
        /// <summary>
        /// Writes an object value to the stream.
        /// </summary>
        /// <param name="writer">Must not be null.</param>
        /// <param name="value">Must not be null.</param>
        /// <param name="valueType">Must not be null.</param>
        private static void WriteObjectValue(FileChunkWriter writer, object value, Type valueType)
        {
            if (valueType.FullName == typeof(FourCharacterCode).FullName)
            {
                writer.WriteFourCharacterCode((FourCharacterCode)value);
            }

            if (valueType.FullName == typeof(Stream).FullName)
            {
                writer.WriteStream((Stream)value);
            }

            if (valueType.FullName == typeof(byte[]).FullName)
            {
                writer.WriteBuffer((byte[])value);
            }

            if (valueType.IsChunk())
            {
                // should be handled outside the member writer
                throw new InvalidOperationException();
            }
        }