Example #1
0
        /// <summary>
        /// Converts the content in <paramref name="data"/> to the format
        /// specified in <paramref name="format"/>.
        /// </summary>
        /// <remarks>
        /// This method will make a copy of the data even if the format is not
        /// changed.
        /// </remarks>
        /// <param name="data">The data to convert to.</param>
        /// <param name="format">The format to convert.</param>
        public static IRomData ConvertTo(this IRomData data, ERomFormat format)
        {
            Guard.IsNotNull(data, nameof(data));

            byte[] copy = new byte[data.Length];
            data.GetData().CopyTo(copy);

            ConvertTo(format, copy);

            return(RomData.LoadRom(copy));
        }
Example #2
0
        /// <summary>
        /// Converts the content in <paramref name="data"/> to the format
        /// specified in <paramref name="format"/>.
        /// </summary>
        /// <remarks>
        /// This method will make a copy of the data even if the format is not
        /// changed.
        /// </remarks>
        /// <param name="data">The data to convert to.</param>
        /// <param name="format">The format to convert.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        public static async ValueTask <IRomData> ConvertToAsync(this IRomData data, ERomFormat format, CancellationToken cancellationToken = default)
        {
            Guard.IsNotNull(data, nameof(data));

            byte[] copy = new byte[data.Length];
            var    src  = await data.GetDataAsync();

            src.CopyTo(copy);

            ConvertTo(format, copy);

            return(await RomData.LoadRomAsync(copy, cancellationToken));
        }