Skip to content

Commit fd39739

Browse files
committed
CSHARP-1067: Code review changes.
1 parent 89944e0 commit fd39739

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

src/MongoDB.Bson/ObjectModel/ObjectId.cs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -485,18 +485,7 @@ public override int GetHashCode()
485485
public byte[] ToByteArray()
486486
{
487487
var bytes = new byte[12];
488-
bytes[0] = (byte)(_a >> 24);
489-
bytes[1] = (byte)(_a >> 16);
490-
bytes[2] = (byte)(_a >> 8);
491-
bytes[3] = (byte)(_a);
492-
bytes[4] = (byte)(_b >> 24);
493-
bytes[5] = (byte)(_b >> 16);
494-
bytes[6] = (byte)(_b >> 8);
495-
bytes[7] = (byte)(_b);
496-
bytes[8] = (byte)(_c >> 24);
497-
bytes[9] = (byte)(_c >> 16);
498-
bytes[10] = (byte)(_c >> 8);
499-
bytes[11] = (byte)(_c);
488+
ToByteArray(bytes, 0);
500489
return bytes;
501490
}
502491

@@ -507,6 +496,15 @@ public byte[] ToByteArray()
507496
/// <param name="offset">The offset.</param>
508497
public void ToByteArray(byte[] destination, int offset)
509498
{
499+
if (destination == null)
500+
{
501+
throw new ArgumentNullException("destination");
502+
}
503+
if (offset + 12 > destination.Length)
504+
{
505+
throw new ArgumentException("Not enough room in destination buffer.", "offset");
506+
}
507+
510508
destination[offset + 0] = (byte)(_a >> 24);
511509
destination[offset + 1] = (byte)(_a >> 16);
512510
destination[offset + 2] = (byte)(_a >> 8);

0 commit comments

Comments
 (0)