Exemple #1
0
        /// <summary>Serializes a value type into a <see cref="DbEntry"/> instance
        /// using a specific <see cref="Field{T, F}"/> instance.</summary>
        /// <remarks>Passing the value type by reference avoids copy overhead.
        /// However, this does not allow to pass <c>nulls</c>. Therefore the
        /// companion method <see cref="NullToDbEntry"/> is provided.</remarks>
        /// <typeparam name="T">Value type to serialize.</typeparam>
        /// <param name="value">Struct instance to serialize.</param>
        /// <param name="field"><see cref="ValueField{T, Formatter}"/> instance that
        /// serializes the <c>value</c>argument.</param>
        /// <returns>A properly initialized <see cref="DbEntry"/> instance containing
        /// the serialized object graph.</returns>
        public DbEntry ToDbEntry <T>(ref T value, ValueField <T, Formatter> field)
            where T : struct
        {
            int index = 0;

            byte[] buffer = NextBuffer();
            InitSerialization(buffer, index);
            field.Serialize(ref value);
            index = FinishSerialization();
            return(DbEntry.InOut(buffer, 0, index));
        }