Align() public static méthode

Aligns a value to the next 32-bit boundary.
public static Align ( long value ) : long
value long /// The value to align. ///
Résultat long
        /// <summary>
        /// Alignes the underlying string to a 32-bit (4-byte) boundary.
        /// </summary>
        /// <param name="reader">
        /// The reader to align.
        /// </param>
        public static void Align(this BinaryReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            var stream = reader.BaseStream;

            stream.Position = Helpers.Align(stream.Position);
        }
Exemple #2
0
        /// <summary>
        /// Aligns the position of the underlying <see cref="Stream"/> to a 32-boundary.
        /// </summary>
        /// <param name="writer">
        /// The writer for which to align the underlying stream.
        /// </param>
        public static void Align(this BinaryWriter writer)
        {
            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }

            var current = writer.BaseStream.Position;
            var actual  = Helpers.Align(current);

            var padding = actual - current;

            for (var i = 0; i < padding; i++)
            {
                writer.Write((byte)0);
            }
        }