File tree Expand file tree Collapse file tree 2 files changed +26
-4
lines changed
NHibernate.Test/UtilityTest
NHibernate/Collection/Generic/SetHelpers Expand file tree Collapse file tree 2 files changed +26
-4
lines changed Original file line number Diff line number Diff line change 1- using System . Collections . Generic ;
1+ using System . Collections ;
2+ using System . Collections . Generic ;
23using System . IO ;
34using System . Runtime . Serialization . Formatters . Binary ;
45using NHibernate . Collection . Generic . SetHelpers ;
@@ -70,6 +71,17 @@ public void TestCopyTo()
7071 Assert . That ( list , Is . EquivalentTo ( array ) ) ;
7172 }
7273
74+ [ Test ]
75+ public void TestCopyToObjectArray ( )
76+ {
77+ var list = new List < string > { "test1" , null , "test2" } ;
78+ ICollection sn = new SetSnapShot < string > ( list ) ;
79+
80+ var array = new object [ 3 ] ;
81+ sn . CopyTo ( array , 0 ) ;
82+ Assert . That ( list , Is . EquivalentTo ( array ) ) ;
83+ }
84+
7385 [ Test ]
7486 public void TestSerialization ( )
7587 {
Original file line number Diff line number Diff line change @@ -114,12 +114,22 @@ IEnumerator IEnumerable.GetEnumerator()
114114
115115 void ICollection . CopyTo ( Array array , int index )
116116 {
117- if ( ! ( array is T [ ] typedArray ) )
117+ if ( array is T [ ] typedArray )
118118 {
119- throw new ArgumentException ( $ "Array must be of type { typeof ( T [ ] ) } .", nameof ( array ) ) ;
119+ CopyTo ( typedArray , index ) ;
120+ return ;
120121 }
121122
122- CopyTo ( typedArray , index ) ;
123+ if ( array . GetType ( ) . GetElementType ( ) . IsAssignableFrom ( typeof ( T ) ) )
124+ {
125+ if ( _hasNull )
126+ array . SetValue ( default ( T ) , index ) ;
127+ ICollection keysCollection = _values . Keys ;
128+ keysCollection . CopyTo ( array , index + ( _hasNull ? 1 : 0 ) ) ;
129+ return ;
130+ }
131+
132+ throw new ArgumentException ( $ "Array must be of type { typeof ( T [ ] ) } .", nameof ( array ) ) ;
123133 }
124134
125135 public int Count => _values . Count + ( _hasNull ? 1 : 0 ) ;
You can’t perform that action at this time.
0 commit comments