/// <summary> /// Convert to byte array. /// </summary> /// <param name="value">The current value.</param> /// <param name="order">The byte order.</param> /// <returns>The byte array.</returns> public static byte[] InternalToByteArray(this ulong value, Nequeo.Custom.ByteOrder order) { var bytes = BitConverter.GetBytes(value); if (!order.IsHostOrder()) { Array.Reverse(bytes); } return(bytes); }
/// <summary> /// Converts the order of the specified array of <see cref="byte"/> to the host byte order. /// </summary> /// <returns> /// An array of <see cref="byte"/> converted from <paramref name="source"/>. /// </returns> /// <param name="source"> /// An array of <see cref="byte"/> to convert. /// </param> /// <param name="sourceOrder"> /// One of the <see cref="ByteOrder"/> enum values, indicates the byte order of /// <paramref name="source"/>. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="source"/> is <see langword="null"/>. /// </exception> public static Byte[] ToHostOrder(this Byte[] source, Nequeo.Custom.ByteOrder sourceOrder) { if (source == null) { throw new ArgumentNullException("source"); } return(source.Length > 1 && !sourceOrder.IsHostOrder() ? source.Reverse() : source); }