File tree Expand file tree Collapse file tree 1 file changed +15
-9
lines changed
src/AspNetCore/WebApi/src/Asp.Versioning.Mvc/ApplicationModels Expand file tree Collapse file tree 1 file changed +15
-9
lines changed Original file line number Diff line number Diff line change 33namespace Asp . Versioning . ApplicationModels ;
44
55using Microsoft . AspNetCore . Mvc . ApplicationModels ;
6+ using Microsoft . AspNetCore . Mvc . Infrastructure ;
67using System . Reflection ;
78
89/// <summary>
@@ -11,17 +12,22 @@ namespace Asp.Versioning.ApplicationModels;
1112[ CLSCompliant ( false ) ]
1213public sealed class ApiBehaviorSpecification : IApiControllerSpecification
1314{
14- static ApiBehaviorSpecification ( )
15+ /// <inheritdoc />
16+ public bool IsSatisfiedBy ( ControllerModel controller )
1517 {
16- const string ApiBehaviorApplicationModelProviderTypeName = "Microsoft.AspNetCore.Mvc.ApplicationModels.ApiBehaviorApplicationModelProvider, Microsoft.AspNetCore.Mvc.Core" ;
17- var type = Type . GetType ( ApiBehaviorApplicationModelProviderTypeName , throwOnError : true ) ! ;
18- var method = type . GetRuntimeMethods ( ) . Single ( m => m . Name == "IsApiController" ) ;
18+ if ( controller == null )
19+ {
20+ throw new ArgumentNullException ( nameof ( controller ) ) ;
21+ }
1922
20- IsApiController = ( Func < ControllerModel , bool > ) method . CreateDelegate ( typeof ( Func < ControllerModel , bool > ) ) ;
21- }
23+ // REF: https://github.com/dotnet/aspnetcore/blob/main/src/Mvc/Mvc.Core/src/ApplicationModels/ApiBehaviorApplicationModelProvider.cs
24+ if ( controller . Attributes . OfType < IApiBehaviorMetadata > ( ) . Any ( ) )
25+ {
26+ return true ;
27+ }
2228
23- private static Func < ControllerModel , bool > IsApiController { get ; }
29+ var assembly = controller . ControllerType . Assembly ;
2430
25- /// <inheritdoc />
26- public bool IsSatisfiedBy ( ControllerModel controller ) => IsApiController ( controller ) ;
31+ return assembly . GetCustomAttributes ( ) . OfType < IApiBehaviorMetadata > ( ) . Any ( ) ;
32+ }
2733}
You can’t perform that action at this time.
0 commit comments