@@ -22,68 +22,6 @@ public static class MapActionEndpointRouteBuilderExtensions
2222 private static readonly string [ ] PutVerb = new [ ] { "PUT" } ;
2323 private static readonly string [ ] DeleteVerb = new [ ] { "DELETE" } ;
2424
25- /// <summary>
26- /// Adds a <see cref="RouteEndpoint"/> to the <see cref="IEndpointRouteBuilder"/> that matches the pattern specified via attributes.
27- /// </summary>
28- /// <param name="endpoints">The <see cref="IEndpointRouteBuilder"/> to add the route to.</param>
29- /// <param name="action">The delegate executed when the endpoint is matched.</param>
30- /// <returns>An <see cref="IEndpointConventionBuilder"/> that can be used to further customize the endpoint.</returns>
31- public static MapActionEndpointConventionBuilder MapAction (
32- this IEndpointRouteBuilder endpoints ,
33- Delegate action )
34- {
35- if ( endpoints is null )
36- {
37- throw new ArgumentNullException ( nameof ( endpoints ) ) ;
38- }
39-
40- if ( action is null )
41- {
42- throw new ArgumentNullException ( nameof ( action ) ) ;
43- }
44-
45- var requestDelegate = MapActionExpressionTreeBuilder . BuildRequestDelegate ( action ) ;
46-
47- var routeAttributes = action . Method . GetCustomAttributes ( ) . OfType < IRoutePatternMetadata > ( ) ;
48- var conventionBuilders = new List < IEndpointConventionBuilder > ( ) ;
49-
50- const int defaultOrder = 0 ;
51-
52- foreach ( var routeAttribute in routeAttributes )
53- {
54- if ( routeAttribute . RoutePattern is not string pattern )
55- {
56- continue ;
57- }
58-
59- var routeName = ( routeAttribute as IRouteNameMetadata ) ? . RouteName ;
60- var routeOrder = ( routeAttribute as IRouteOrderMetadata ) ? . RouteOrder ;
61-
62- var conventionBuilder = endpoints . Map ( pattern , requestDelegate ) ;
63-
64- conventionBuilder . Add ( endpointBuilder =>
65- {
66- foreach ( var attribute in action . Method . GetCustomAttributes ( ) )
67- {
68- endpointBuilder . Metadata . Add ( attribute ) ;
69- }
70-
71- endpointBuilder . DisplayName = routeName ?? pattern ;
72-
73- ( ( RouteEndpointBuilder ) endpointBuilder ) . Order = routeOrder ?? defaultOrder ;
74- } ) ;
75-
76- conventionBuilders . Add ( conventionBuilder ) ;
77- }
78-
79- if ( conventionBuilders . Count == 0 )
80- {
81- throw new InvalidOperationException ( "Action must have a pattern. Is it missing a Route attribute?" ) ;
82- }
83-
84- return new MapActionEndpointConventionBuilder ( conventionBuilders ) ;
85- }
86-
8725 /// <summary>
8826 /// Adds a <see cref="RouteEndpoint"/> to the <see cref="IEndpointRouteBuilder"/> that matches HTTP GET requests
8927 /// for the specified pattern.
@@ -168,8 +106,8 @@ public static MapActionEndpointConventionBuilder MapMethods(
168106 throw new ArgumentNullException ( nameof ( httpMethods ) ) ;
169107 }
170108
171- var displayName = $ " { pattern } HTTP: { string . Join ( ", " , httpMethods ) } " ;
172- var builder = endpoints . Map ( RoutePatternFactory . Parse ( pattern ) , action , displayName ) ;
109+ var builder = endpoints . Map ( RoutePatternFactory . Parse ( pattern ) , action ) ;
110+ builder . WithDisplayName ( $ " { pattern } HTTP: { string . Join ( ", " , httpMethods ) } " ) ;
173111 builder . WithMetadata ( new HttpMethodMetadata ( httpMethods ) ) ;
174112 return builder ;
175113 }
@@ -202,15 +140,6 @@ public static MapActionEndpointConventionBuilder Map(
202140 this IEndpointRouteBuilder endpoints ,
203141 RoutePattern pattern ,
204142 Delegate action )
205- {
206- return Map ( endpoints , pattern , action , displayName : null ) ;
207- }
208-
209- private static MapActionEndpointConventionBuilder Map (
210- this IEndpointRouteBuilder endpoints ,
211- RoutePattern pattern ,
212- Delegate action ,
213- string ? displayName )
214143 {
215144 if ( endpoints is null )
216145 {
@@ -239,39 +168,16 @@ private static MapActionEndpointConventionBuilder Map(
239168
240169 // Add delegate attributes as metadata
241170 var attributes = action . Method . GetCustomAttributes ( ) ;
242- string ? routeName = null ;
243- int ? routeOrder = null ;
244171
245172 // This can be null if the delegate is a dynamic method or compiled from an expression tree
246173 if ( attributes is not null )
247174 {
248175 foreach ( var attribute in attributes )
249176 {
250- if ( attribute is IRoutePatternMetadata patternMetadata && patternMetadata . RoutePattern is not null )
251- {
252- throw new InvalidOperationException ( $ "'{ attribute . GetType ( ) } ' implements { nameof ( IRoutePatternMetadata ) } which is not supported by this method.") ;
253- }
254- if ( attribute is IHttpMethodMetadata methodMetadata && methodMetadata . HttpMethods . Any ( ) )
255- {
256- throw new InvalidOperationException ( $ "'{ attribute . GetType ( ) } ' implements { nameof ( IHttpMethodMetadata ) } which is not supported by this method.") ;
257- }
258-
259- if ( attribute is IRouteNameMetadata nameMetadata && nameMetadata . RouteName is string name )
260- {
261- routeName = name ;
262- }
263- if ( attribute is IRouteOrderMetadata orderMetadata && orderMetadata . RouteOrder is int order )
264- {
265- routeOrder = order ;
266- }
267-
268177 builder . Metadata . Add ( attribute ) ;
269178 }
270179 }
271180
272- builder . DisplayName = routeName ?? displayName ?? builder . DisplayName ;
273- builder . Order = routeOrder ?? defaultOrder ;
274-
275181 var dataSource = endpoints . DataSources . OfType < ModelEndpointDataSource > ( ) . FirstOrDefault ( ) ;
276182 if ( dataSource is null )
277183 {
0 commit comments