private static long FromBytes(byte[] buffer, int offset, int count)
{
Guard.NotNull(() => buffer, buffer);
if (offset < 0)
{
throw new ArgumentOutOfRangeException("offset", offset, CommonStrings.OffsetMustBeNonNegative);
}
if (offset > buffer.Length || offset + count > buffer.Length)
{
throw ArraySegmentException.GetByStartAndLength(offset, count);
}
long result = 0;
int end = offset + count;
for (int position = end - 1; position >= offset; position--)
{
result = unchecked((result << 8) | buffer[position]);
}
return result;
}