public void BytecodeApi_ConvertEx() { byte[] data = MathEx.RandomNumberGenerator.GetBytes(100); Assert.IsTrue(ConvertEx.FromHexadecimalString(ConvertEx.ToHexadecimalString(data)).Compare(data)); Assert.IsTrue(ConvertEx.FromBase32String(ConvertEx.ToBase32String(data)).Compare(data)); for (int i = 0; i < 1000; i++) { Assert.AreEqual(ConvertEx.FromExcelColumnString(ConvertEx.ToExcelColumnString(i)), i); Assert.AreEqual(ConvertEx.From7BitEncodedInt(ConvertEx.To7BitEncodedInt(i)), i); } for (int i = 1; i <= 3999; i++) { Assert.AreEqual(ConvertEx.FromRomanNumber(ConvertEx.ToRomanNumber(i)), i); } Point point = ConvertEx.ToStructure <Point>(ConvertEx.FromStructure(new Point(1337, 4242))); Assert.IsTrue(point.X == 1337 && point.Y == 4242); }
/// <summary> /// Writes a structure of the specified type to the stream. /// </summary> /// <typeparam name="T">The type of the structure to write.</typeparam> /// <param name="stream">The <see cref="Stream" /> to write to.</param> /// <param name="structure">The structure to write to <paramref name="stream" />.</param> public static void WriteStructure <T>(this Stream stream, T structure) where T : struct { Check.ArgumentNull(stream, nameof(stream)); stream.Write(ConvertEx.FromStructure(structure)); }