/// <summary> /// Calculates the checksum of the byte stream. /// </summary> /// <param name="byteStream">The byte stream to calculate the checksum for.</param> /// <returns>A 32-bit reversed checksum.</returns> public System.UInt32 Get <T>(System.Collections.Generic.IEnumerable <T> byteStream) { try { // Initialize checksumRegister to 0xFFFFFFFF and calculate the checksum. return(~byteStream.Aggregate(0xFFFFFFFF, (checksumRegister, currentByte) => (m_checksumTable[(checksumRegister & 0xFF) ^ System.Convert.ToByte(currentByte)] ^ (checksumRegister >> 8)))); } catch (System.FormatException e) { throw new System.Exception("Could not read the stream out as bytes.", e); } catch (System.InvalidCastException e) { throw new System.Exception("Could not read the stream out as bytes.", e); } catch (System.OverflowException e) { throw new System.Exception("Could not read the stream out as bytes.", e); } }