Esempio n. 1
0
        /// <summary>
        /// Serializes the given <paramref name="table"/> in the specified <paramref name="endianness"/> and saves the output to the file specified by <paramref name="path"/>.
        /// </summary>
        /// <param name="table">The table to be serialized.</param>
        /// <param name="path">The path to the file to save the output to.</param>
        /// <param name="endianness">The endianness in which to write the output with.</param>
        public static void Serialize(object table, string path, Endianness endianness = Endianness.LittleEndian)
        {
            var tableType = table.GetType();

            using (var fileStream = File.OpenWrite(path))
                using (var serializer = new TableSerializer(tableType, fileStream))
                {
                    serializer.SerializeTable(tableType, table, endianness, false);
                }
        }
Esempio n. 2
0
        /// <summary>
        /// Serializes the given <paramref name="table"/> in the specified <paramref name="endianness"/> and saves the output the given <paramref name="stream"/>.
        /// </summary>
        /// <remarks>The stream is not disposed after calling this method.</remarks>
        /// <param name="table">The table to be serialized.</param>
        /// <param name="stream">The stream save the output to.</param>
        /// <param name="endianness">The endianness in which to write the output with.</param>
        public static void Serialize(object table, Stream stream, Endianness endianness = Endianness.LittleEndian)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            var tableType  = table.GetType();
            var serializer = new TableSerializer(tableType, stream);

            serializer.SerializeTable(tableType, table, endianness, true);
        }