File tree Expand file tree Collapse file tree 1 file changed +15
-9
lines changed
Filter options
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 3
3
namespace Asp . Versioning . ApplicationModels ;
4
4
5
5
using Microsoft . AspNetCore . Mvc . ApplicationModels ;
6
+ using Microsoft . AspNetCore . Mvc . Infrastructure ;
6
7
using System . Reflection ;
7
8
8
9
/// <summary>
@@ -11,17 +12,22 @@ namespace Asp.Versioning.ApplicationModels;
11
12
[ CLSCompliant ( false ) ]
12
13
public sealed class ApiBehaviorSpecification : IApiControllerSpecification
13
14
{
14
- static ApiBehaviorSpecification ( )
15
+ /// <inheritdoc />
16
+ public bool IsSatisfiedBy ( ControllerModel controller )
15
17
{
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
+ }
19
22
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
+ }
22
28
23
- private static Func < ControllerModel , bool > IsApiController { get ; }
29
+ var assembly = controller . ControllerType . Assembly ;
24
30
25
- /// <inheritdoc />
26
- public bool IsSatisfiedBy ( ControllerModel controller ) => IsApiController ( controller ) ;
31
+ return assembly . GetCustomAttributes ( ) . OfType < IApiBehaviorMetadata > ( ) . Any ( ) ;
32
+ }
27
33
}
You can’t perform that action at this time.
0 commit comments