diff --git a/src/Microsoft.AspNetCore.Routing.Abstractions/EndpointMetadataCollection.cs b/src/Microsoft.AspNetCore.Routing.Abstractions/EndpointMetadataCollection.cs index a792fff295..137423a886 100644 --- a/src/Microsoft.AspNetCore.Routing.Abstractions/EndpointMetadataCollection.cs +++ b/src/Microsoft.AspNetCore.Routing.Abstractions/EndpointMetadataCollection.cs @@ -29,7 +29,7 @@ namespace Microsoft.AspNetCore.Http private readonly ConcurrentDictionary _cache; /// - /// Creates a new . + /// Creates a new instance of . /// /// The metadata items. public EndpointMetadataCollection(IEnumerable items) @@ -44,7 +44,7 @@ namespace Microsoft.AspNetCore.Http } /// - /// Creates a new . + /// Creates a new instance of . /// /// The metadata items. public EndpointMetadataCollection(params object[] items) diff --git a/src/Microsoft.AspNetCore.Routing.Abstractions/RouteContext.cs b/src/Microsoft.AspNetCore.Routing.Abstractions/RouteContext.cs index 767f39b1ec..7162446e7d 100644 --- a/src/Microsoft.AspNetCore.Routing.Abstractions/RouteContext.cs +++ b/src/Microsoft.AspNetCore.Routing.Abstractions/RouteContext.cs @@ -14,7 +14,7 @@ namespace Microsoft.AspNetCore.Routing private RouteData _routeData; /// - /// Creates a new for the provided . + /// Creates a new instance of for the provided . /// /// The associated with the current request. public RouteContext(HttpContext httpContext) diff --git a/src/Microsoft.AspNetCore.Routing.Abstractions/RouteData.cs b/src/Microsoft.AspNetCore.Routing.Abstractions/RouteData.cs index e0628dc1bb..858c3a67f4 100644 --- a/src/Microsoft.AspNetCore.Routing.Abstractions/RouteData.cs +++ b/src/Microsoft.AspNetCore.Routing.Abstractions/RouteData.cs @@ -16,7 +16,7 @@ namespace Microsoft.AspNetCore.Routing private RouteValueDictionary _values; /// - /// Creates a new instance. + /// Creates a new instance of instance. /// public RouteData() { @@ -24,7 +24,7 @@ namespace Microsoft.AspNetCore.Routing } /// - /// Creates a new instance with values copied from . + /// Creates a new instance of instance with values copied from . /// /// The other instance to copy. public RouteData(RouteData other) @@ -52,7 +52,7 @@ namespace Microsoft.AspNetCore.Routing } /// - /// Creates a new instance with the specified values. + /// Creates a new instance of instance with the specified values. /// /// The values. public RouteData(RouteValueDictionary values) @@ -197,7 +197,7 @@ namespace Microsoft.AspNetCore.Routing private readonly RouteValueDictionary _values; /// - /// Creates a new for . + /// Creates a new instance of for . /// /// The . /// The data tokens. diff --git a/src/Microsoft.AspNetCore.Routing.Abstractions/RouteValueDictionary.cs b/src/Microsoft.AspNetCore.Routing.Abstractions/RouteValueDictionary.cs index 837e466d28..ca132a7889 100644 --- a/src/Microsoft.AspNetCore.Routing.Abstractions/RouteValueDictionary.cs +++ b/src/Microsoft.AspNetCore.Routing.Abstractions/RouteValueDictionary.cs @@ -25,7 +25,7 @@ namespace Microsoft.AspNetCore.Routing private int _count; /// - /// Creates a new from the provided array. + /// Creates a new instance of from the provided array. /// The new instance will take ownership of the array, and may mutate it. /// /// The items array. diff --git a/src/Microsoft.AspNetCore.Routing.Abstractions/VirtualPathContext.cs b/src/Microsoft.AspNetCore.Routing.Abstractions/VirtualPathContext.cs index 036aa445f8..88f899e925 100644 --- a/src/Microsoft.AspNetCore.Routing.Abstractions/VirtualPathContext.cs +++ b/src/Microsoft.AspNetCore.Routing.Abstractions/VirtualPathContext.cs @@ -11,7 +11,7 @@ namespace Microsoft.AspNetCore.Routing public class VirtualPathContext { /// - /// Creates a new . + /// Creates a new instance of . /// /// The associated with the current request. /// The set of route values associated with the current request. @@ -25,7 +25,7 @@ namespace Microsoft.AspNetCore.Routing } /// - /// Creates a new . + /// Creates a new instance of . /// /// The associated with the current request. /// The set of route values associated with the current request. diff --git a/src/Microsoft.AspNetCore.Routing/Constraints/HttpMethodRouteConstraint.cs b/src/Microsoft.AspNetCore.Routing/Constraints/HttpMethodRouteConstraint.cs index a894acaacb..f5a4d81830 100644 --- a/src/Microsoft.AspNetCore.Routing/Constraints/HttpMethodRouteConstraint.cs +++ b/src/Microsoft.AspNetCore.Routing/Constraints/HttpMethodRouteConstraint.cs @@ -14,7 +14,7 @@ namespace Microsoft.AspNetCore.Routing.Constraints public class HttpMethodRouteConstraint : IRouteConstraint { /// - /// Creates a new that accepts the HTTP methods specified + /// Creates a new instance of that accepts the HTTP methods specified /// by . /// /// The allowed HTTP methods. diff --git a/src/Microsoft.AspNetCore.Routing/EndpointNameMetadata.cs b/src/Microsoft.AspNetCore.Routing/EndpointNameMetadata.cs index 925c355807..1342962797 100644 --- a/src/Microsoft.AspNetCore.Routing/EndpointNameMetadata.cs +++ b/src/Microsoft.AspNetCore.Routing/EndpointNameMetadata.cs @@ -16,7 +16,7 @@ namespace Microsoft.AspNetCore.Routing public class EndpointNameMetadata : IEndpointNameMetadata { /// - /// Creates a new with the provided endpoint name. + /// Creates a new instance of with the provided endpoint name. /// /// The endpoint name. public EndpointNameMetadata(string endpointName) diff --git a/src/Microsoft.AspNetCore.Routing/IRouteValuesAddressMetadata.cs b/src/Microsoft.AspNetCore.Routing/IRouteValuesAddressMetadata.cs index 1e771c27d8..076dea8a92 100644 --- a/src/Microsoft.AspNetCore.Routing/IRouteValuesAddressMetadata.cs +++ b/src/Microsoft.AspNetCore.Routing/IRouteValuesAddressMetadata.cs @@ -5,9 +5,20 @@ using System.Collections.Generic; namespace Microsoft.AspNetCore.Routing { + /// + /// Represents metadata used during link generation to find + /// the associated endpoint using route values. + /// public interface IRouteValuesAddressMetadata { + /// + /// Gets the route name. Can be null. + /// string RouteName { get; } + + /// + /// Gets the required route values. + /// IReadOnlyDictionary RequiredValues { get; } } } diff --git a/src/Microsoft.AspNetCore.Routing/Patterns/RoutePatternException.cs b/src/Microsoft.AspNetCore.Routing/Patterns/RoutePatternException.cs index 04dc26daf4..7b21ac0ac5 100644 --- a/src/Microsoft.AspNetCore.Routing/Patterns/RoutePatternException.cs +++ b/src/Microsoft.AspNetCore.Routing/Patterns/RoutePatternException.cs @@ -19,7 +19,7 @@ namespace Microsoft.AspNetCore.Routing.Patterns } /// - /// Creates a new . + /// Creates a new instance of . /// /// The route pattern as raw text. /// The exception message. diff --git a/src/Microsoft.AspNetCore.Routing/Patterns/RoutePatternFactory.cs b/src/Microsoft.AspNetCore.Routing/Patterns/RoutePatternFactory.cs index bbc1e50aca..71941ffde6 100644 --- a/src/Microsoft.AspNetCore.Routing/Patterns/RoutePatternFactory.cs +++ b/src/Microsoft.AspNetCore.Routing/Patterns/RoutePatternFactory.cs @@ -67,7 +67,7 @@ namespace Microsoft.AspNetCore.Routing.Patterns } /// - /// Creates a new from a collection of segments. + /// Creates a new instance of from a collection of segments. /// /// The collection of segments. /// The . @@ -82,7 +82,7 @@ namespace Microsoft.AspNetCore.Routing.Patterns } /// - /// Creates a new from a collection of segments. + /// Creates a new instance of from a collection of segments. /// /// The raw text to associate with the route pattern. May be null. /// The collection of segments. @@ -158,7 +158,7 @@ namespace Microsoft.AspNetCore.Routing.Patterns } /// - /// Creates a new from a collection of segments. + /// Creates a new instance of from a collection of segments. /// /// The collection of segments. /// The . @@ -173,7 +173,7 @@ namespace Microsoft.AspNetCore.Routing.Patterns } /// - /// Creates a new from a collection of segments. + /// Creates a new instance of from a collection of segments. /// /// The raw text to associate with the route pattern. May be null. /// The collection of segments. diff --git a/src/Microsoft.AspNetCore.Routing/RouteConstraintBuilder.cs b/src/Microsoft.AspNetCore.Routing/RouteConstraintBuilder.cs index f170ac81fa..0c444236a5 100644 --- a/src/Microsoft.AspNetCore.Routing/RouteConstraintBuilder.cs +++ b/src/Microsoft.AspNetCore.Routing/RouteConstraintBuilder.cs @@ -23,7 +23,7 @@ namespace Microsoft.AspNetCore.Routing private readonly Dictionary> _constraints; private readonly HashSet _optionalParameters; /// - /// Creates a new instance. + /// Creates a new instance of instance. /// /// The . /// The display name (for use in error messages). diff --git a/src/Microsoft.AspNetCore.Routing/RouteValuesAddressMetadata.cs b/src/Microsoft.AspNetCore.Routing/RouteValuesAddressMetadata.cs index a65c48101a..c901d185ee 100644 --- a/src/Microsoft.AspNetCore.Routing/RouteValuesAddressMetadata.cs +++ b/src/Microsoft.AspNetCore.Routing/RouteValuesAddressMetadata.cs @@ -3,22 +3,61 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Diagnostics; using System.Linq; namespace Microsoft.AspNetCore.Routing { + /// + /// Metadata used during link generation to find the associated endpoint using route values. + /// [DebuggerDisplay("{DebuggerToString(),nq}")] public sealed class RouteValuesAddressMetadata : IRouteValuesAddressMetadata { + private static readonly IReadOnlyDictionary EmptyRouteValues = + new ReadOnlyDictionary(new Dictionary()); + + /// + /// Creates a new instance of with the provided route name. + /// + /// The route name. Can be null. + public RouteValuesAddressMetadata(string routeName) : this(routeName, EmptyRouteValues) + { + } + + /// + /// Creates a new instance of with the provided required route values. + /// + /// The required route values. + public RouteValuesAddressMetadata(IReadOnlyDictionary requiredValues) : this(null, requiredValues) + { + } + + /// + /// Creates a new instance of with the provided route name and required route values. + /// + /// The route name. Can be null. + /// The required route values. public RouteValuesAddressMetadata(string routeName, IReadOnlyDictionary requiredValues) { + if (requiredValues == null) + { + throw new ArgumentNullException(nameof(requiredValues)); + } + RouteName = routeName; RequiredValues = requiredValues; } + /// + /// Gets the route name. Can be null. + /// public string RouteName { get; } + /// + /// Gets the required route values. + /// public IReadOnlyDictionary RequiredValues { get; } internal string DebuggerToString() diff --git a/src/Microsoft.AspNetCore.Routing/Template/InlineConstraint.cs b/src/Microsoft.AspNetCore.Routing/Template/InlineConstraint.cs index 4d58ce6181..a711ecb136 100644 --- a/src/Microsoft.AspNetCore.Routing/Template/InlineConstraint.cs +++ b/src/Microsoft.AspNetCore.Routing/Template/InlineConstraint.cs @@ -12,7 +12,7 @@ namespace Microsoft.AspNetCore.Routing.Template public class InlineConstraint { /// - /// Creates a new . + /// Creates a new instance of . /// /// The constraint text. public InlineConstraint(string constraint) diff --git a/src/Microsoft.AspNetCore.Routing/Tree/TreeRouter.cs b/src/Microsoft.AspNetCore.Routing/Tree/TreeRouter.cs index 679cbf5261..8670b6cdff 100644 --- a/src/Microsoft.AspNetCore.Routing/Tree/TreeRouter.cs +++ b/src/Microsoft.AspNetCore.Routing/Tree/TreeRouter.cs @@ -30,7 +30,7 @@ namespace Microsoft.AspNetCore.Routing.Tree private readonly ILogger _constraintLogger; /// - /// Creates a new . + /// Creates a new instance of . /// /// The list of that contains the route entries. /// The set of . diff --git a/test/Microsoft.AspNetCore.Routing.Tests/EndpointFactory.cs b/test/Microsoft.AspNetCore.Routing.Tests/EndpointFactory.cs index eb23c5daab..e3a5b0f802 100644 --- a/test/Microsoft.AspNetCore.Routing.Tests/EndpointFactory.cs +++ b/test/Microsoft.AspNetCore.Routing.Tests/EndpointFactory.cs @@ -22,7 +22,7 @@ namespace Microsoft.AspNetCore.Routing var d = new List(metadata ?? Array.Empty()); if (requiredValues != null) { - d.Add(new RouteValuesAddressMetadata(null, new RouteValueDictionary(requiredValues))); + d.Add(new RouteValuesAddressMetadata(new RouteValueDictionary(requiredValues))); } return new RouteEndpoint( diff --git a/test/Microsoft.AspNetCore.Routing.Tests/LinkGeneratorRouteValuesAddressExtensionsTest.cs b/test/Microsoft.AspNetCore.Routing.Tests/LinkGeneratorRouteValuesAddressExtensionsTest.cs index 57f530cdb8..3c3e63c78e 100644 --- a/test/Microsoft.AspNetCore.Routing.Tests/LinkGeneratorRouteValuesAddressExtensionsTest.cs +++ b/test/Microsoft.AspNetCore.Routing.Tests/LinkGeneratorRouteValuesAddressExtensionsTest.cs @@ -24,11 +24,11 @@ namespace Microsoft.AspNetCore.Routing var endpoint1 = EndpointFactory.CreateRouteEndpoint( "Home/Index/{id}", defaults: new { controller = "Home", action = "Index", }, - metadata: new[] { new RouteValuesAddressMetadata(routeName: null, new RouteValueDictionary(new { controller = "Home", action = "Index", })) }); + metadata: new[] { new RouteValuesAddressMetadata(new RouteValueDictionary(new { controller = "Home", action = "Index", })) }); var endpoint2 = EndpointFactory.CreateRouteEndpoint( "Home/Index/{id?}", defaults: new { controller = "Home", action = "Index", }, - metadata: new[] { new RouteValuesAddressMetadata(routeName: null, new RouteValueDictionary(new { controller = "Home", action = "Index", })) }); + metadata: new[] { new RouteValuesAddressMetadata(new RouteValueDictionary(new { controller = "Home", action = "Index", })) }); var linkGenerator = CreateLinkGenerator(endpoint1, endpoint2); @@ -59,11 +59,11 @@ namespace Microsoft.AspNetCore.Routing var endpoint1 = EndpointFactory.CreateRouteEndpoint( "Home/Index/{id}", defaults: new { controller = "Home", action = "Index", }, - metadata: new[] { new RouteValuesAddressMetadata(routeName: null, new RouteValueDictionary(new { controller = "Home", action = "Index", })) }); + metadata: new[] { new RouteValuesAddressMetadata(new RouteValueDictionary(new { controller = "Home", action = "Index", })) }); var endpoint2 = EndpointFactory.CreateRouteEndpoint( "Home/Index/{id?}", defaults: new { controller = "Home", action = "Index", }, - metadata: new[] { new RouteValuesAddressMetadata(routeName: null, new RouteValueDictionary(new { controller = "Home", action = "Index", })) }); + metadata: new[] { new RouteValuesAddressMetadata(new RouteValueDictionary(new { controller = "Home", action = "Index", })) }); var linkGenerator = CreateLinkGenerator(endpoint1, endpoint2); @@ -86,11 +86,11 @@ namespace Microsoft.AspNetCore.Routing var endpoint1 = EndpointFactory.CreateRouteEndpoint( "Home/Index/{id}", defaults: new { controller = "Home", action = "Index", }, - metadata: new[] { new RouteValuesAddressMetadata(routeName: null, new RouteValueDictionary(new { controller = "Home", action = "Index", })) }); + metadata: new[] { new RouteValuesAddressMetadata(new RouteValueDictionary(new { controller = "Home", action = "Index", })) }); var endpoint2 = EndpointFactory.CreateRouteEndpoint( "Home/Index/{id?}", defaults: new { controller = "Home", action = "Index", }, - metadata: new[] { new RouteValuesAddressMetadata(routeName: null, new RouteValueDictionary(new { controller = "Home", action = "Index", })) }); + metadata: new[] { new RouteValuesAddressMetadata(new RouteValueDictionary(new { controller = "Home", action = "Index", })) }); var linkGenerator = CreateLinkGenerator(endpoint1, endpoint2); @@ -116,11 +116,11 @@ namespace Microsoft.AspNetCore.Routing var endpoint1 = EndpointFactory.CreateRouteEndpoint( "Home/Index/{id}", defaults: new { controller = "Home", action = "Index", }, - metadata: new[] { new RouteValuesAddressMetadata(routeName: null, new RouteValueDictionary(new { controller = "Home", action = "Index", })) }); + metadata: new[] { new RouteValuesAddressMetadata(new RouteValueDictionary(new { controller = "Home", action = "Index", })) }); var endpoint2 = EndpointFactory.CreateRouteEndpoint( "Home/Index/{id?}", defaults: new { controller = "Home", action = "Index", }, - metadata: new[] { new RouteValuesAddressMetadata(routeName: null, new RouteValueDictionary(new { controller = "Home", action = "Index", })) }); + metadata: new[] { new RouteValuesAddressMetadata(new RouteValueDictionary(new { controller = "Home", action = "Index", })) }); var linkGenerator = CreateLinkGenerator(endpoint1, endpoint2); @@ -145,11 +145,11 @@ namespace Microsoft.AspNetCore.Routing var endpoint1 = EndpointFactory.CreateRouteEndpoint( "Home/Index/{id}", defaults: new { controller = "Home", action = "Index", }, - metadata: new[] { new RouteValuesAddressMetadata(routeName: null, new RouteValueDictionary(new { controller = "Home", action = "Index", })) }); + metadata: new[] { new RouteValuesAddressMetadata(new RouteValueDictionary(new { controller = "Home", action = "Index", })) }); var endpoint2 = EndpointFactory.CreateRouteEndpoint( "Home/Index/{id?}", defaults: new { controller = "Home", action = "Index", }, - metadata: new[] { new RouteValuesAddressMetadata(routeName: null, new RouteValueDictionary(new { controller = "Home", action = "Index", })) }); + metadata: new[] { new RouteValuesAddressMetadata(new RouteValueDictionary(new { controller = "Home", action = "Index", })) }); var linkGenerator = CreateLinkGenerator(endpoint1, endpoint2); @@ -177,11 +177,11 @@ namespace Microsoft.AspNetCore.Routing var endpoint1 = EndpointFactory.CreateRouteEndpoint( "Home/Index/{id}", defaults: new { controller = "Home", action = "Index", }, - metadata: new[] { new RouteValuesAddressMetadata(routeName: null, new RouteValueDictionary(new { controller = "Home", action = "Index", })) }); + metadata: new[] { new RouteValuesAddressMetadata(new RouteValueDictionary(new { controller = "Home", action = "Index", })) }); var endpoint2 = EndpointFactory.CreateRouteEndpoint( "Home/Index/{id?}", defaults: new { controller = "Home", action = "Index", }, - metadata: new[] { new RouteValuesAddressMetadata(routeName: null, new RouteValueDictionary(new { controller = "Home", action = "Index", })) }); + metadata: new[] { new RouteValuesAddressMetadata(new RouteValueDictionary(new { controller = "Home", action = "Index", })) }); var linkGenerator = CreateLinkGenerator(endpoint1, endpoint2); @@ -208,10 +208,10 @@ namespace Microsoft.AspNetCore.Routing // Arrange var endpoint1 = EndpointFactory.CreateRouteEndpoint( "{controller}/{action}/{id}", - metadata: new[] { new RouteValuesAddressMetadata(routeName: null, new RouteValueDictionary(new { controller = "Home", action = "In?dex", })) }); + metadata: new[] { new RouteValuesAddressMetadata(new RouteValueDictionary(new { controller = "Home", action = "In?dex", })) }); var endpoint2 = EndpointFactory.CreateRouteEndpoint( "{controller}/{action}/{id?}", - metadata: new[] { new RouteValuesAddressMetadata(routeName: null, new RouteValueDictionary(new { controller = "Home", action = "In?dex", })) }); + metadata: new[] { new RouteValuesAddressMetadata(new RouteValueDictionary(new { controller = "Home", action = "In?dex", })) }); var linkGenerator = CreateLinkGenerator(endpoint1, endpoint2); diff --git a/test/Microsoft.AspNetCore.Routing.Tests/RouteValuesAddressMetadataTests.cs b/test/Microsoft.AspNetCore.Routing.Tests/RouteValuesAddressMetadataTests.cs index f05e763484..1a237c2ad1 100644 --- a/test/Microsoft.AspNetCore.Routing.Tests/RouteValuesAddressMetadataTests.cs +++ b/test/Microsoft.AspNetCore.Routing.Tests/RouteValuesAddressMetadataTests.cs @@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Routing [Fact] public void DebuggerToString_NoNameAndRequiredValues_ReturnsString() { - var metadata = new RouteValuesAddressMetadata(null, null); + var metadata = new RouteValuesAddressMetadata(null, new Dictionary()); Assert.Equal("Name: - Required values: ", metadata.DebuggerToString()); }