@@ -106,7 +106,40 @@ public TCollection GetCollectionValue<TElement, TCollection>(
106106 if ( TryGetCollectionParseResultValue ( binding , elementConverter , createCollection , out var collection ) )
107107 return collection ;
108108
109- return bindingArgs . TryGetDefaultValue ( out collection ) ? collection : default ! ;
109+ return bindingArgs . TryGetDefaultValue ( out collection )
110+ ? collection
111+ : createCollection ( [ ] ) ;
112+ }
113+
114+ /// <summary>
115+ /// Gets a collection property value.
116+ /// </summary>
117+ /// <param name="propertyExpression">The expression that identifies the model property being bound.</param>
118+ /// <param name="elementConverter">A function that converts string arguments to the target element type.</param>
119+ /// <param name="createCollection">A function that converts enumerable values to the strong collection type.</param>
120+ /// <typeparam name="TElement">The collection or array's element type.</typeparam>
121+ /// <typeparam name="TCollection">The collection type.</typeparam>
122+ /// <returns>The collection value</returns>
123+ public TCollection ? GetCollectionValueOrDefault < TElement , TCollection > (
124+ Expression < Func < TModel , TCollection > > propertyExpression ,
125+ ValueConverter < TElement > ? elementConverter ,
126+ Func < IEnumerable < TElement > , TCollection > createCollection )
127+ where TCollection : IEnumerable < TElement >
128+ {
129+ var binding = GetPropertyBinding ( propertyExpression ) ;
130+ var bindingArgs = new PropertyBinder < TCollection > ( binding , this , null ) ;
131+
132+ binding . TryBindValue ( bindingArgs ) ;
133+
134+ if ( bindingArgs . TryGetExplicitValue ( out var value ) )
135+ return value ;
136+
137+ if ( TryGetCollectionParseResultValue ( binding , elementConverter , createCollection , out var collection ) )
138+ return collection ;
139+
140+ return bindingArgs . TryGetDefaultValue ( out collection )
141+ ? collection
142+ : default ;
110143 }
111144
112145 /// <summary>
0 commit comments