3
3
4
4
using System . Collections . Concurrent ;
5
5
using System . Diagnostics . CodeAnalysis ;
6
+ using System . Linq ;
6
7
using System . Reflection ;
7
8
using static Microsoft . AspNetCore . Internal . LinkerFlags ;
8
9
@@ -170,12 +171,12 @@ private static void ThrowForUnknownIncomingParameterName([DynamicallyAccessedMem
170
171
{
171
172
if ( ! propertyInfo . IsDefined ( typeof ( ParameterAttribute ) ) &&
172
173
! propertyInfo . IsDefined ( typeof ( CascadingParameterAttribute ) ) &&
173
- ! propertyInfo . IsDefined ( typeof ( SupplyParameterFromFormAttribute ) ) )
174
+ ! propertyInfo . GetCustomAttributes ( ) . OfType < IHostEnvironmentCascadingParameter > ( ) . Any ( ) )
174
175
{
175
176
throw new InvalidOperationException (
176
177
$ "Object of type '{ targetType . FullName } ' has a property matching the name '{ parameterName } ', " +
177
178
$ "but it does not have [{ nameof ( ParameterAttribute ) } ], [{ nameof ( CascadingParameterAttribute ) } ] or " +
178
- $ "[{ nameof ( SupplyParameterFromFormAttribute ) } ] applied.") ;
179
+ $ "[SupplyParameterFromFormAttribute] applied.") ;
179
180
}
180
181
else
181
182
{
@@ -260,11 +261,30 @@ public WritersForType([DynamicallyAccessedMembers(Component)] Type targetType)
260
261
261
262
foreach ( var propertyInfo in GetCandidateBindableProperties ( targetType ) )
262
263
{
263
- var parameterAttribute = propertyInfo . GetCustomAttribute < ParameterAttribute > ( ) ;
264
- var cascadingParameterAttribute = propertyInfo . GetCustomAttribute < CascadingParameterAttribute > ( ) ;
265
- var supplyParameterFromFormAttribute = propertyInfo . GetCustomAttribute < SupplyParameterFromFormAttribute > ( ) ;
264
+ ParameterAttribute ? parameterAttribute = null ;
265
+ CascadingParameterAttribute ? cascadingParameterAttribute = null ;
266
+ IHostEnvironmentCascadingParameter ? hostEnvironmentCascadingParameter = null ;
266
267
267
- var isParameter = parameterAttribute != null || cascadingParameterAttribute != null || supplyParameterFromFormAttribute != null ;
268
+ var attributes = propertyInfo . GetCustomAttributes ( ) ;
269
+ foreach ( var attribute in attributes )
270
+ {
271
+ switch ( attribute )
272
+ {
273
+ case ParameterAttribute parameter :
274
+ parameterAttribute = parameter ;
275
+ break ;
276
+ case CascadingParameterAttribute cascadingParameter :
277
+ cascadingParameterAttribute = cascadingParameter ;
278
+ break ;
279
+ case IHostEnvironmentCascadingParameter hostEnvironmentAttribute :
280
+ hostEnvironmentCascadingParameter = hostEnvironmentAttribute ;
281
+ break ;
282
+ default :
283
+ break ;
284
+ }
285
+ }
286
+
287
+ var isParameter = parameterAttribute != null || cascadingParameterAttribute != null || hostEnvironmentCascadingParameter != null ;
268
288
if ( ! isParameter )
269
289
{
270
290
continue ;
@@ -279,7 +299,7 @@ public WritersForType([DynamicallyAccessedMembers(Component)] Type targetType)
279
299
280
300
var propertySetter = new PropertySetter ( targetType , propertyInfo )
281
301
{
282
- Cascading = cascadingParameterAttribute != null || supplyParameterFromFormAttribute != null ,
302
+ Cascading = cascadingParameterAttribute != null || hostEnvironmentCascadingParameter != null ,
283
303
} ;
284
304
285
305
if ( _underlyingWriters . ContainsKey ( propertyName ) )
0 commit comments