File tree Expand file tree Collapse file tree 1 file changed +10
-12
lines changed
src/MongoDB.Bson/ObjectModel Expand file tree Collapse file tree 1 file changed +10
-12
lines changed Original file line number Diff line number Diff line change @@ -485,18 +485,7 @@ public override int GetHashCode()
485
485
public byte [ ] ToByteArray ( )
486
486
{
487
487
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 ) ;
500
489
return bytes ;
501
490
}
502
491
@@ -507,6 +496,15 @@ public byte[] ToByteArray()
507
496
/// <param name="offset">The offset.</param>
508
497
public void ToByteArray ( byte [ ] destination , int offset )
509
498
{
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
+
510
508
destination [ offset + 0 ] = ( byte ) ( _a >> 24 ) ;
511
509
destination [ offset + 1 ] = ( byte ) ( _a >> 16 ) ;
512
510
destination [ offset + 2 ] = ( byte ) ( _a >> 8 ) ;
You can’t perform that action at this time.
0 commit comments