@@ -135,7 +135,7 @@ private set
135135 /// </param>
136136 /// <seealso cref="IIncrementalSource{TSource}"/>
137137 public IncrementalLoadingCollection ( int itemsPerPage = 20 , Action onStartLoading = null , Action onEndLoading = null , Action < Exception > onError = null )
138- : this ( default ( TSource ) , itemsPerPage , onStartLoading , onEndLoading , onError )
138+ : this ( InstantiateSourceByReflection ( ) , itemsPerPage , onStartLoading , onEndLoading , onError )
139139 {
140140 }
141141
@@ -160,16 +160,9 @@ public IncrementalLoadingCollection(int itemsPerPage = 20, Action onStartLoading
160160 /// <seealso cref="IIncrementalSource{TSource}"/>
161161 public IncrementalLoadingCollection ( TSource source , int itemsPerPage = 20 , Action onStartLoading = null , Action onEndLoading = null , Action < Exception > onError = null )
162162 {
163- if ( EqualityComparer < TSource > . Default . Equals ( source , default ( TSource ) ) )
163+ if ( source == null )
164164 {
165- var type = typeof ( TSource ) ;
166- ConstructorInfo constructor = type . GetConstructor ( new Type [ 0 ] ) ;
167- if ( constructor == null )
168- {
169- throw new InvalidOperationException ( "TSource must have a parameterless constructor" ) ;
170- }
171-
172- source = ( TSource ) constructor . Invoke ( null ) ;
165+ throw new ArgumentNullException ( nameof ( source ) ) ;
173166 }
174167
175168 Source = source ;
@@ -209,6 +202,18 @@ protected virtual async Task<IEnumerable<IType>> LoadDataAsync(CancellationToken
209202 return result ;
210203 }
211204
205+ private static TSource InstantiateSourceByReflection ( )
206+ {
207+ var type = typeof ( TSource ) ;
208+ ConstructorInfo constructor = type . GetConstructor ( new Type [ 0 ] ) ;
209+ if ( constructor == null )
210+ {
211+ throw new InvalidOperationException ( "TSource must have a parameterless constructor" ) ;
212+ }
213+
214+ return ( TSource ) constructor . Invoke ( null ) ;
215+ }
216+
212217 private async Task < LoadMoreItemsResult > LoadMoreItemsAsync ( uint count , CancellationToken cancellationToken )
213218 {
214219 uint resultCount = 0 ;
0 commit comments