public static byte[] InternalToByteArray(this ulong value, ByteOrder order) { var bytes = BitConverter.GetBytes(value); if (!order.IsHostOrder()) { Array.Reverse(bytes); } return(bytes); }
internal static byte[] ToByteArrayInternally(this ushort value, 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="src"/>. /// </returns> /// <param name="src"> /// An array of <see cref="byte"/> to convert. /// </param> /// <param name="srcOrder"> /// One of the <see cref="ByteOrder"/> enum values, indicates the byte order of /// <paramref name="src"/>. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="src"/> is <see langword="null"/>. /// </exception> public static byte[] ToHostOrder(this byte[] src, ByteOrder srcOrder) { if (src == null) { throw new ArgumentNullException("src"); } return(src.Length > 1 && !srcOrder.IsHostOrder() ? src.Reverse() : src); }
public static byte[] ToHostOrder(this byte[] src, ByteOrder srcOrder) { if (src == null) { return(null); } return(src.Length > 1 && !srcOrder.IsHostOrder() ? src.CopyReverse() : src); }
/// <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="src"/>. /// </returns> /// <param name="src"> /// An array of <see cref="byte"/> to convert. /// </param> /// <param name="srcOrder"> /// One of the <see cref="ByteOrder"/> enum values, indicates the byte order of /// <paramref name="src"/>. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="src"/> is <see langword="null"/>. /// </exception> public static void ToHostOrder(this byte[] src, ByteOrder srcOrder) { if (src == null) { throw new ArgumentNullException(nameof(src)); } if (src.Length > 1 && !srcOrder.IsHostOrder()) { Array.Reverse(src); } }
public static byte[] ToByteArray <T>(this T value, ByteOrder order) where T : struct { Type typeFromHandle = typeof(T); byte[] array = ((typeFromHandle == typeof(bool)) ? BitConverter.GetBytes((bool)(object)value) : ((typeFromHandle == typeof(byte)) ? new byte[1] { (byte)(object)value } : ((typeFromHandle == typeof(char)) ? BitConverter.GetBytes((char)(object)value) : ((typeFromHandle == typeof(double)) ? BitConverter.GetBytes((double)(object)value) : ((typeFromHandle == typeof(short)) ? BitConverter.GetBytes((short)(object)value) : ((typeFromHandle == typeof(int)) ? BitConverter.GetBytes((int)(object)value) : ((typeFromHandle == typeof(long)) ? BitConverter.GetBytes((long)(object)value) : ((typeFromHandle == typeof(float)) ? BitConverter.GetBytes((float)(object)value) : ((typeFromHandle == typeof(ushort)) ? BitConverter.GetBytes((ushort)(object)value) : ((typeFromHandle == typeof(uint)) ? BitConverter.GetBytes((uint)(object)value) : ((typeFromHandle != typeof(ulong)) ? new byte[0] : BitConverter.GetBytes((ulong)(object)value)))))))))))); if (array.Length > 1 && !order.IsHostOrder()) { Array.Reverse(array); } return(array); }
public static byte[] ToHostOrder(this byte[] src, ByteOrder srcOrder) { if (src == null) return null; return src.Length > 1 && !srcOrder.IsHostOrder() ? src.CopyReverse() : src; }
private static byte[] AdjustByteOrder(byte[] bytes, ByteOrder byteOrder) { if (!byteOrder.IsHostOrder()) Array.Reverse(bytes); return bytes; }