Use ValueTask for DynamicRouteValuesTransformer
This commit is contained in:
parent
bff743aced
commit
1552e9f842
|
|
@ -2914,7 +2914,7 @@ namespace Microsoft.AspNetCore.Mvc.Routing
|
||||||
public abstract partial class DynamicRouteValueTransformer
|
public abstract partial class DynamicRouteValueTransformer
|
||||||
{
|
{
|
||||||
protected DynamicRouteValueTransformer() { }
|
protected DynamicRouteValueTransformer() { }
|
||||||
public abstract System.Threading.Tasks.Task<Microsoft.AspNetCore.Routing.RouteValueDictionary> TransformAsync(Microsoft.AspNetCore.Http.HttpContext httpContext, Microsoft.AspNetCore.Routing.RouteValueDictionary values);
|
public abstract System.Threading.Tasks.ValueTask<Microsoft.AspNetCore.Routing.RouteValueDictionary> TransformAsync(Microsoft.AspNetCore.Http.HttpContext httpContext, Microsoft.AspNetCore.Routing.RouteValueDictionary values);
|
||||||
}
|
}
|
||||||
[System.AttributeUsageAttribute(System.AttributeTargets.Method, AllowMultiple=true, Inherited=true)]
|
[System.AttributeUsageAttribute(System.AttributeTargets.Method, AllowMultiple=true, Inherited=true)]
|
||||||
public abstract partial class HttpMethodAttribute : System.Attribute, Microsoft.AspNetCore.Mvc.Routing.IActionHttpMethodProvider, Microsoft.AspNetCore.Mvc.Routing.IRouteTemplateProvider
|
public abstract partial class HttpMethodAttribute : System.Attribute, Microsoft.AspNetCore.Mvc.Routing.IActionHttpMethodProvider, Microsoft.AspNetCore.Mvc.Routing.IRouteTemplateProvider
|
||||||
|
|
|
||||||
|
|
@ -9,22 +9,22 @@ using Microsoft.AspNetCore.Routing.Matching;
|
||||||
namespace Microsoft.AspNetCore.Mvc.Routing
|
namespace Microsoft.AspNetCore.Mvc.Routing
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Provides an abstraction for dynamically manipulating route value to select a controller action or page.
|
/// Provides an abstraction for dynamically manipulating route value to select a controller action or page.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// <para>
|
/// <para>
|
||||||
/// <see cref="DynamicRouteValueTransformer"/> can be used with
|
/// <see cref="DynamicRouteValueTransformer"/> can be used with
|
||||||
/// <see cref="Microsoft.AspNetCore.Builder.ControllerEndpointRouteBuilderExtensions.MapDynamicControllerRoute{TTransformer}(IEndpointRouteBuilder, string)" />
|
/// <see cref="Microsoft.AspNetCore.Builder.ControllerEndpointRouteBuilderExtensions.MapDynamicControllerRoute{TTransformer}(IEndpointRouteBuilder, string)" />
|
||||||
/// or <c>MapDynamicPageRoute</c> to implement custom logic that selects a controller action or page.
|
/// or <c>MapDynamicPageRoute</c> to implement custom logic that selects a controller action or page.
|
||||||
/// </para>
|
/// </para>
|
||||||
/// <para>
|
/// <para>
|
||||||
/// The route values returned from a <see cref="TransformAsync(HttpContext, RouteValueDictionary)"/> implementation
|
/// The route values returned from a <see cref="TransformAsync(HttpContext, RouteValueDictionary)"/> implementation
|
||||||
/// will be used to select an action based on matching of the route values. All actions that match the route values
|
/// will be used to select an action based on matching of the route values. All actions that match the route values
|
||||||
/// will be considered as candidates, and may be further disambiguated by <see cref="IEndpointSelectorPolicy" />
|
/// will be considered as candidates, and may be further disambiguated by <see cref="IEndpointSelectorPolicy" />
|
||||||
/// implementations such as <see cref="HttpMethodMatcherPolicy" />.
|
/// implementations such as <see cref="HttpMethodMatcherPolicy" />.
|
||||||
/// </para>
|
/// </para>
|
||||||
/// <para>
|
/// <para>
|
||||||
/// Implementations <see cref="DynamicRouteValueTransformer" /> should be registered with the service
|
/// Implementations <see cref="DynamicRouteValueTransformer" /> should be registered with the service
|
||||||
/// collection as type <see cref="DynamicRouteValueTransformer" />. Implementations can use any service
|
/// collection as type <see cref="DynamicRouteValueTransformer" />. Implementations can use any service
|
||||||
/// lifetime.
|
/// lifetime.
|
||||||
/// </para>
|
/// </para>
|
||||||
|
|
@ -37,6 +37,6 @@ namespace Microsoft.AspNetCore.Mvc.Routing
|
||||||
/// <param name="httpContext">The <see cref="HttpContext" /> associated with the current request.</param>
|
/// <param name="httpContext">The <see cref="HttpContext" /> associated with the current request.</param>
|
||||||
/// <param name="values">The route values associated with the current match. Implementations should not modify <paramref name="values"/>.</param>
|
/// <param name="values">The route values associated with the current match. Implementations should not modify <paramref name="values"/>.</param>
|
||||||
/// <returns>A task which asynchronously returns a set of route values.</returns>
|
/// <returns>A task which asynchronously returns a set of route values.</returns>
|
||||||
public abstract Task<RouteValueDictionary> TransformAsync(HttpContext httpContext, RouteValueDictionary values);
|
public abstract ValueTask<RouteValueDictionary> TransformAsync(HttpContext httpContext, RouteValueDictionary values);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ namespace RoutingWebSite
|
||||||
private class Transformer : DynamicRouteValueTransformer
|
private class Transformer : DynamicRouteValueTransformer
|
||||||
{
|
{
|
||||||
// Turns a format like `controller=Home,action=Index` into an RVD
|
// Turns a format like `controller=Home,action=Index` into an RVD
|
||||||
public override Task<RouteValueDictionary> TransformAsync(HttpContext httpContext, RouteValueDictionary values)
|
public override ValueTask<RouteValueDictionary> TransformAsync(HttpContext httpContext, RouteValueDictionary values)
|
||||||
{
|
{
|
||||||
var kvps = ((string)values["slug"]).Split(",");
|
var kvps = ((string)values["slug"]).Split(",");
|
||||||
|
|
||||||
|
|
@ -59,7 +59,7 @@ namespace RoutingWebSite
|
||||||
results[split[0]] = split[1];
|
results[split[0]] = split[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
return Task.FromResult(results);
|
return new ValueTask<RouteValueDictionary>(results);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue