/// <summary> /// Constructs a new instance of the <see cref="EndianOrder"/> class. /// </summary> /// <param name="targetEndianness">Endianness parameter.</param> protected EndianOrder(Endianness targetEndianness) { m_targetEndianness = targetEndianness; // We perform this logic only once for speed in conversions - we can do this because neither // the target nor the OS endian order will change during the lifecycle of this class... if (targetEndianness == Endianness.BigEndian) { if (BitConverter.IsLittleEndian) { // If OS is little endian and we want big endian, we swap the bytes m_copyBuffer = SwapCopy; m_coerceByteOrder = ReverseBuffer; } else { // If OS is big endian and we want big endian, we just copy the bytes m_copyBuffer = BlockCopy; m_coerceByteOrder = PassThroughBuffer; } } else { if (BitConverter.IsLittleEndian) { // If OS is little endian and we want little endian, we just copy the bytes m_copyBuffer = BlockCopy; m_coerceByteOrder = PassThroughBuffer; } else { // If OS is big endian and we want little endian, we swap the bytes m_copyBuffer = SwapCopy; m_coerceByteOrder = ReverseBuffer; } } }