Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 10fde6c

Browse filesBrowse files
Remove use of Reflection; not AOT friendly
1 parent e3644b4 commit 10fde6c
Copy full SHA for 10fde6c

File tree

Expand file treeCollapse file tree

1 file changed

+15
-9
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+15
-9
lines changed

‎src/AspNetCore/WebApi/src/Asp.Versioning.Mvc/ApplicationModels/ApiBehaviorSpecification.cs

Copy file name to clipboardExpand all lines: src/AspNetCore/WebApi/src/Asp.Versioning.Mvc/ApplicationModels/ApiBehaviorSpecification.cs
+15-9Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Asp.Versioning.ApplicationModels;
44

55
using Microsoft.AspNetCore.Mvc.ApplicationModels;
6+
using Microsoft.AspNetCore.Mvc.Infrastructure;
67
using System.Reflection;
78

89
/// <summary>
@@ -11,17 +12,22 @@ namespace Asp.Versioning.ApplicationModels;
1112
[CLSCompliant( false )]
1213
public 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
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.