@@ -183,23 +183,25 @@ string BuildShortName(ActionParameterAttribute a)
183183 }
184184 }
185185 }
186-
187186 void SetDefaultValue (
188187 PropertyInfo prop ,
189188 Type argumentInstanceType ,
190189 object argumentInstance )
191190 {
192- var defaultValueAttr = prop . GetCustomAttribute < DefaultValueAttribute > ( ) ;
193- if ( defaultValueAttr != null )
191+ var delMethod = typeof ( CommandLineHelper ) . GetMethod ( nameof ( GetDefaultValueDelegate ) , BindingFlags . NonPublic | BindingFlags . Static ) ;
192+ var delGen = delMethod . MakeGenericMethod ( prop . PropertyType ) ;
193+ var del = delGen . Invoke ( null , new object [ ] { prop } ) ;
194+ if ( del != null )
194195 {
195196 var defaultValueProperty = argumentInstanceType . GetProperty ( "DefaultValueFactory" ,
196197 BindingFlags . Public | BindingFlags . Instance ) ;
197198 if ( defaultValueProperty == null )
198199 throw new InvalidOperationException (
199200 $ "Could not find property DefaultValueFactory on type { argumentInstanceType } ") ;
200- defaultValueProperty . SetValue ( argumentInstance , ( ArgumentResult _ ) => defaultValueAttr . Value ) ;
201+ defaultValueProperty . SetValue ( argumentInstance , del ) ;
201202 }
202203 }
204+
203205 string [ ] GenerateAliases (
204206 PropertyInfo prop )
205207 {
@@ -438,5 +440,12 @@ private static string FormatTypeName(Type type)
438440 {
439441 return type . Namespace + '.' + type . Name ;
440442 }
443+
444+ private static Func < ArgumentResult , T > GetDefaultValueDelegate < T > ( PropertyInfo prop )
445+ {
446+ var defaultValueAttr = prop . GetCustomAttribute < DefaultValueAttribute > ( ) ;
447+ if ( defaultValueAttr == null ) return null ;
448+ return ( ArgumentResult _ ) => ( T ) defaultValueAttr . Value ;
449+ }
441450 }
442451}
0 commit comments