@@ -22,68 +22,6 @@ public static class MapActionEndpointRouteBuilderExtensions
22
22
private static readonly string [ ] PutVerb = new [ ] { "PUT" } ;
23
23
private static readonly string [ ] DeleteVerb = new [ ] { "DELETE" } ;
24
24
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
-
87
25
/// <summary>
88
26
/// Adds a <see cref="RouteEndpoint"/> to the <see cref="IEndpointRouteBuilder"/> that matches HTTP GET requests
89
27
/// for the specified pattern.
@@ -168,8 +106,8 @@ public static MapActionEndpointConventionBuilder MapMethods(
168
106
throw new ArgumentNullException ( nameof ( httpMethods ) ) ;
169
107
}
170
108
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 ) } " ) ;
173
111
builder . WithMetadata ( new HttpMethodMetadata ( httpMethods ) ) ;
174
112
return builder ;
175
113
}
@@ -202,15 +140,6 @@ public static MapActionEndpointConventionBuilder Map(
202
140
this IEndpointRouteBuilder endpoints ,
203
141
RoutePattern pattern ,
204
142
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 )
214
143
{
215
144
if ( endpoints is null )
216
145
{
@@ -239,39 +168,16 @@ private static MapActionEndpointConventionBuilder Map(
239
168
240
169
// Add delegate attributes as metadata
241
170
var attributes = action . Method . GetCustomAttributes ( ) ;
242
- string ? routeName = null ;
243
- int ? routeOrder = null ;
244
171
245
172
// This can be null if the delegate is a dynamic method or compiled from an expression tree
246
173
if ( attributes is not null )
247
174
{
248
175
foreach ( var attribute in attributes )
249
176
{
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
-
268
177
builder . Metadata . Add ( attribute ) ;
269
178
}
270
179
}
271
180
272
- builder . DisplayName = routeName ?? displayName ?? builder . DisplayName ;
273
- builder . Order = routeOrder ?? defaultOrder ;
274
-
275
181
var dataSource = endpoints . DataSources . OfType < ModelEndpointDataSource > ( ) . FirstOrDefault ( ) ;
276
182
if ( dataSource is null )
277
183
{
0 commit comments