File tree 2 files changed +26
-4
lines changed
NHibernate/Collection/Generic/SetHelpers
NHibernate.Test/UtilityTest
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 ;
2
3
using System . IO ;
3
4
using System . Runtime . Serialization . Formatters . Binary ;
4
5
using NHibernate . Collection . Generic . SetHelpers ;
@@ -70,6 +71,17 @@ public void TestCopyTo()
70
71
Assert . That ( list , Is . EquivalentTo ( array ) ) ;
71
72
}
72
73
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
+
73
85
[ Test ]
74
86
public void TestSerialization ( )
75
87
{
Original file line number Diff line number Diff line change @@ -114,12 +114,22 @@ IEnumerator IEnumerable.GetEnumerator()
114
114
115
115
void ICollection . CopyTo ( Array array , int index )
116
116
{
117
- if ( ! ( array is T [ ] typedArray ) )
117
+ if ( array is T [ ] typedArray )
118
118
{
119
- throw new ArgumentException ( $ "Array must be of type { typeof ( T [ ] ) } .", nameof ( array ) ) ;
119
+ CopyTo ( typedArray , index ) ;
120
+ return ;
120
121
}
121
122
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 ) ) ;
123
133
}
124
134
125
135
public int Count => _values . Count + ( _hasNull ? 1 : 0 ) ;
You can’t perform that action at this time.
0 commit comments