Skip to content

Commit 8750cd1

Browse files
authored
Nullable followup for Routing (#23474)
* Nullable followup for routing. * Update nullability based on usage * Use nullable enable in a few files * More nullable
1 parent fd1f1c3 commit 8750cd1

32 files changed

+267
-211
lines changed

src/Http/Http.Abstractions/src/Routing/RouteValueDictionary.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ public bool TryGetValue(string key, out object? value)
512512
return TryGetValueSlow(key, out value);
513513
}
514514

515-
private bool TryGetValueSlow(string key, [NotNullWhen(true)] out object? value)
515+
private bool TryGetValueSlow(string key, out object? value)
516516
{
517517
if (_propertyStorage != null)
518518
{

src/Http/Routing.Abstractions/ref/Microsoft.AspNetCore.Routing.Abstractions.netcoreapp.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,35 @@ namespace Microsoft.AspNetCore.Routing
55
{
66
public partial interface IOutboundParameterTransformer : Microsoft.AspNetCore.Routing.IParameterPolicy
77
{
8-
string TransformOutbound(object value);
8+
string? TransformOutbound(object? value);
99
}
1010
public partial interface IParameterPolicy
1111
{
1212
}
1313
public partial interface IRouteConstraint : Microsoft.AspNetCore.Routing.IParameterPolicy
1414
{
15-
bool Match(Microsoft.AspNetCore.Http.HttpContext httpContext, Microsoft.AspNetCore.Routing.IRouter route, string routeKey, Microsoft.AspNetCore.Routing.RouteValueDictionary values, Microsoft.AspNetCore.Routing.RouteDirection routeDirection);
15+
bool Match(Microsoft.AspNetCore.Http.HttpContext? httpContext, Microsoft.AspNetCore.Routing.IRouter route, string routeKey, Microsoft.AspNetCore.Routing.RouteValueDictionary values, Microsoft.AspNetCore.Routing.RouteDirection routeDirection);
1616
}
1717
public partial interface IRouteHandler
1818
{
1919
Microsoft.AspNetCore.Http.RequestDelegate GetRequestHandler(Microsoft.AspNetCore.Http.HttpContext httpContext, Microsoft.AspNetCore.Routing.RouteData routeData);
2020
}
2121
public partial interface IRouter
2222
{
23-
Microsoft.AspNetCore.Routing.VirtualPathData GetVirtualPath(Microsoft.AspNetCore.Routing.VirtualPathContext context);
23+
Microsoft.AspNetCore.Routing.VirtualPathData? GetVirtualPath(Microsoft.AspNetCore.Routing.VirtualPathContext context);
2424
System.Threading.Tasks.Task RouteAsync(Microsoft.AspNetCore.Routing.RouteContext context);
2525
}
2626
public partial interface IRoutingFeature
2727
{
28-
Microsoft.AspNetCore.Routing.RouteData RouteData { get; set; }
28+
Microsoft.AspNetCore.Routing.RouteData? RouteData { get; set; }
2929
}
3030
public abstract partial class LinkGenerator
3131
{
3232
protected LinkGenerator() { }
33-
public abstract string GetPathByAddress<TAddress>(Microsoft.AspNetCore.Http.HttpContext httpContext, TAddress address, Microsoft.AspNetCore.Routing.RouteValueDictionary values, Microsoft.AspNetCore.Routing.RouteValueDictionary? ambientValues = null, Microsoft.AspNetCore.Http.PathString? pathBase = default(Microsoft.AspNetCore.Http.PathString?), Microsoft.AspNetCore.Http.FragmentString fragment = default(Microsoft.AspNetCore.Http.FragmentString), Microsoft.AspNetCore.Routing.LinkOptions? options = null);
34-
public abstract string GetPathByAddress<TAddress>(TAddress address, Microsoft.AspNetCore.Routing.RouteValueDictionary values, Microsoft.AspNetCore.Http.PathString pathBase = default(Microsoft.AspNetCore.Http.PathString), Microsoft.AspNetCore.Http.FragmentString fragment = default(Microsoft.AspNetCore.Http.FragmentString), Microsoft.AspNetCore.Routing.LinkOptions? options = null);
35-
public abstract string GetUriByAddress<TAddress>(Microsoft.AspNetCore.Http.HttpContext httpContext, TAddress address, Microsoft.AspNetCore.Routing.RouteValueDictionary values, Microsoft.AspNetCore.Routing.RouteValueDictionary? ambientValues = null, string? scheme = null, Microsoft.AspNetCore.Http.HostString? host = default(Microsoft.AspNetCore.Http.HostString?), Microsoft.AspNetCore.Http.PathString? pathBase = default(Microsoft.AspNetCore.Http.PathString?), Microsoft.AspNetCore.Http.FragmentString fragment = default(Microsoft.AspNetCore.Http.FragmentString), Microsoft.AspNetCore.Routing.LinkOptions? options = null);
36-
public abstract string GetUriByAddress<TAddress>(TAddress address, Microsoft.AspNetCore.Routing.RouteValueDictionary values, string scheme, Microsoft.AspNetCore.Http.HostString host, Microsoft.AspNetCore.Http.PathString pathBase = default(Microsoft.AspNetCore.Http.PathString), Microsoft.AspNetCore.Http.FragmentString fragment = default(Microsoft.AspNetCore.Http.FragmentString), Microsoft.AspNetCore.Routing.LinkOptions? options = null);
33+
public abstract string? GetPathByAddress<TAddress>(Microsoft.AspNetCore.Http.HttpContext httpContext, TAddress address, Microsoft.AspNetCore.Routing.RouteValueDictionary values, Microsoft.AspNetCore.Routing.RouteValueDictionary? ambientValues = null, Microsoft.AspNetCore.Http.PathString? pathBase = default(Microsoft.AspNetCore.Http.PathString?), Microsoft.AspNetCore.Http.FragmentString fragment = default(Microsoft.AspNetCore.Http.FragmentString), Microsoft.AspNetCore.Routing.LinkOptions? options = null);
34+
public abstract string? GetPathByAddress<TAddress>(TAddress address, Microsoft.AspNetCore.Routing.RouteValueDictionary values, Microsoft.AspNetCore.Http.PathString pathBase = default(Microsoft.AspNetCore.Http.PathString), Microsoft.AspNetCore.Http.FragmentString fragment = default(Microsoft.AspNetCore.Http.FragmentString), Microsoft.AspNetCore.Routing.LinkOptions? options = null);
35+
public abstract string? GetUriByAddress<TAddress>(Microsoft.AspNetCore.Http.HttpContext httpContext, TAddress address, Microsoft.AspNetCore.Routing.RouteValueDictionary values, Microsoft.AspNetCore.Routing.RouteValueDictionary? ambientValues = null, string? scheme = null, Microsoft.AspNetCore.Http.HostString? host = default(Microsoft.AspNetCore.Http.HostString?), Microsoft.AspNetCore.Http.PathString? pathBase = default(Microsoft.AspNetCore.Http.PathString?), Microsoft.AspNetCore.Http.FragmentString fragment = default(Microsoft.AspNetCore.Http.FragmentString), Microsoft.AspNetCore.Routing.LinkOptions? options = null);
36+
public abstract string? GetUriByAddress<TAddress>(TAddress address, Microsoft.AspNetCore.Routing.RouteValueDictionary values, string scheme, Microsoft.AspNetCore.Http.HostString host, Microsoft.AspNetCore.Http.PathString pathBase = default(Microsoft.AspNetCore.Http.PathString), Microsoft.AspNetCore.Http.FragmentString fragment = default(Microsoft.AspNetCore.Http.FragmentString), Microsoft.AspNetCore.Routing.LinkOptions? options = null);
3737
}
3838
public partial class LinkOptions
3939
{
@@ -57,13 +57,13 @@ public RouteData(Microsoft.AspNetCore.Routing.RouteValueDictionary values) { }
5757
public Microsoft.AspNetCore.Routing.RouteValueDictionary DataTokens { get { throw null; } }
5858
public System.Collections.Generic.IList<Microsoft.AspNetCore.Routing.IRouter> Routers { get { throw null; } }
5959
public Microsoft.AspNetCore.Routing.RouteValueDictionary Values { get { throw null; } }
60-
public Microsoft.AspNetCore.Routing.RouteData.RouteDataSnapshot PushState(Microsoft.AspNetCore.Routing.IRouter router, Microsoft.AspNetCore.Routing.RouteValueDictionary values, Microsoft.AspNetCore.Routing.RouteValueDictionary dataTokens) { throw null; }
60+
public Microsoft.AspNetCore.Routing.RouteData.RouteDataSnapshot PushState(Microsoft.AspNetCore.Routing.IRouter? router, Microsoft.AspNetCore.Routing.RouteValueDictionary? values, Microsoft.AspNetCore.Routing.RouteValueDictionary? dataTokens) { throw null; }
6161
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
6262
public readonly partial struct RouteDataSnapshot
6363
{
6464
private readonly object _dummy;
6565
private readonly int _dummyPrimitive;
66-
public RouteDataSnapshot(Microsoft.AspNetCore.Routing.RouteData routeData, Microsoft.AspNetCore.Routing.RouteValueDictionary dataTokens, System.Collections.Generic.IList<Microsoft.AspNetCore.Routing.IRouter> routers, Microsoft.AspNetCore.Routing.RouteValueDictionary values) { throw null; }
66+
public RouteDataSnapshot(Microsoft.AspNetCore.Routing.RouteData routeData, Microsoft.AspNetCore.Routing.RouteValueDictionary? dataTokens, System.Collections.Generic.IList<Microsoft.AspNetCore.Routing.IRouter>? routers, Microsoft.AspNetCore.Routing.RouteValueDictionary? values) { throw null; }
6767
public void Restore() { }
6868
}
6969
}

src/Http/Routing.Abstractions/src/IOutboundParameterTransformer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
namespace Microsoft.AspNetCore.Routing
@@ -14,6 +14,6 @@ public interface IOutboundParameterTransformer : IParameterPolicy
1414
/// </summary>
1515
/// <param name="value">The route value to transform.</param>
1616
/// <returns>The transformed value.</returns>
17-
string TransformOutbound(object value);
17+
string? TransformOutbound(object? value);
1818
}
1919
}

src/Http/Routing.Abstractions/src/IRouteConstraint.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public interface IRouteConstraint : IParameterPolicy
2424
/// </param>
2525
/// <returns><c>true</c> if the URL parameter contains a valid value; otherwise, <c>false</c>.</returns>
2626
bool Match(
27-
HttpContext httpContext,
27+
HttpContext? httpContext,
2828
IRouter route,
2929
string routeKey,
3030
RouteValueDictionary values,

src/Http/Routing.Abstractions/src/IRouter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ public interface IRouter
99
{
1010
Task RouteAsync(RouteContext context);
1111

12-
VirtualPathData GetVirtualPath(VirtualPathContext context);
12+
VirtualPathData? GetVirtualPath(VirtualPathContext context);
1313
}
1414
}

src/Http/Routing.Abstractions/src/IRoutingFeature.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4+
#nullable enable
5+
46
namespace Microsoft.AspNetCore.Routing
57
{
68
/// <summary>
@@ -11,6 +13,6 @@ public interface IRoutingFeature
1113
/// <summary>
1214
/// Gets or sets the <see cref="Routing.RouteData"/> associated with the current request.
1315
/// </summary>
14-
RouteData RouteData { get; set; }
16+
RouteData? RouteData { get; set; }
1517
}
1618
}

src/Http/Routing.Abstractions/src/LinkGenerator.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ namespace Microsoft.AspNetCore.Routing
1111
/// <remarks>
1212
/// <para>
1313
/// Generating URIs in endpoint routing occurs in two phases. First, an address is bound to a list of
14-
/// endpoints that match the address. Secondly, each endpoint's <c>RoutePattern</c> is evaluated, until
14+
/// endpoints that match the address. Secondly, each endpoint's <c>RoutePattern</c> is evaluated, until
1515
/// a route pattern that matches the supplied values is found. The resulting output is combined with
1616
/// the other URI parts supplied to the link generator and returned.
1717
/// </para>
1818
/// <para>
1919
/// The methods provided by the <see cref="LinkGenerator"/> type are general infrastructure, and support
20-
/// the standard link generator functionality for any type of address. The most convenient way to use
20+
/// the standard link generator functionality for any type of address. The most convenient way to use
2121
/// <see cref="LinkGenerator"/> is through extension methods that perform operations for a specific
2222
/// address type.
2323
/// </para>
@@ -30,7 +30,7 @@ public abstract class LinkGenerator
3030
/// <typeparam name="TAddress">The address type.</typeparam>
3131
/// <param name="httpContext">The <see cref="HttpContext"/> associated with the current request.</param>
3232
/// <param name="address">The address value. Used to resolve endpoints.</param>
33-
/// <param name="values">The route values. Used to expand parameters in the route template. Optional.</param>
33+
/// <param name="values">The route values. Used to expand parameters in the route template.</param>
3434
/// <param name="ambientValues">The values associated with the current request. Optional.</param>
3535
/// <param name="pathBase">
3636
/// An optional URI path base. Prepended to the path in the resulting URI. If not provided, the value of <see cref="HttpRequest.PathBase"/> will be used.
@@ -41,7 +41,7 @@ public abstract class LinkGenerator
4141
/// names from <c>RouteOptions</c>.
4242
/// </param>
4343
/// <returns>A URI with an absolute path, or <c>null</c>.</returns>
44-
public abstract string GetPathByAddress<TAddress>(
44+
public abstract string? GetPathByAddress<TAddress>(
4545
HttpContext httpContext,
4646
TAddress address,
4747
RouteValueDictionary values,
@@ -55,15 +55,15 @@ public abstract string GetPathByAddress<TAddress>(
5555
/// </summary>
5656
/// <typeparam name="TAddress">The address type.</typeparam>
5757
/// <param name="address">The address value. Used to resolve endpoints.</param>
58-
/// <param name="values">The route values. Used to expand parameters in the route template. Optional.</param>
58+
/// <param name="values">The route values. Used to expand parameters in the route template.</param>
5959
/// <param name="pathBase">An optional URI path base. Prepended to the path in the resulting URI.</param>
6060
/// <param name="fragment">An optional URI fragment. Appended to the resulting URI.</param>
6161
/// <param name="options">
6262
/// An optional <see cref="LinkOptions"/>. Settings on provided object override the settings with matching
6363
/// names from <c>RouteOptions</c>.
6464
/// </param>
6565
/// <returns>A URI with an absolute path, or <c>null</c>.</returns>
66-
public abstract string GetPathByAddress<TAddress>(
66+
public abstract string? GetPathByAddress<TAddress>(
6767
TAddress address,
6868
RouteValueDictionary values,
6969
PathString pathBase = default,
@@ -76,7 +76,7 @@ public abstract string GetPathByAddress<TAddress>(
7676
/// <typeparam name="TAddress">The address type.</typeparam>
7777
/// <param name="httpContext">The <see cref="HttpContext"/> associated with the current request.</param>
7878
/// <param name="address">The address value. Used to resolve endpoints.</param>
79-
/// <param name="values">The route values. Used to expand parameters in the route template. Optional.</param>
79+
/// <param name="values">The route values. Used to expand parameters in the route template.</param>
8080
/// <param name="ambientValues">The values associated with the current request. Optional.</param>
8181
/// <param name="scheme">
8282
/// The URI scheme, applied to the resulting URI. Optional. If not provided, the value of <see cref="HttpRequest.Scheme"/> will be used.
@@ -102,7 +102,7 @@ public abstract string GetPathByAddress<TAddress>(
102102
/// your deployment environment.
103103
/// </para>
104104
/// </remarks>
105-
public abstract string GetUriByAddress<TAddress>(
105+
public abstract string? GetUriByAddress<TAddress>(
106106
HttpContext httpContext,
107107
TAddress address,
108108
RouteValueDictionary values,
@@ -118,7 +118,7 @@ public abstract string GetUriByAddress<TAddress>(
118118
/// </summary>
119119
/// <typeparam name="TAddress">The address type.</typeparam>
120120
/// <param name="address">The address value. Used to resolve endpoints.</param>
121-
/// <param name="values">The route values. Used to expand parameters in the route template. Optional.</param>
121+
/// <param name="values">The route values. Used to expand parameters in the route template.</param>
122122
/// <param name="scheme">The URI scheme, applied to the resulting URI.</param>
123123
/// <param name="host">
124124
/// The URI host/authority, applied to the resulting URI.
@@ -139,7 +139,7 @@ public abstract string GetUriByAddress<TAddress>(
139139
/// your deployment environment.
140140
/// </para>
141141
/// </remarks>
142-
public abstract string GetUriByAddress<TAddress>(
142+
public abstract string? GetUriByAddress<TAddress>(
143143
TAddress address,
144144
RouteValueDictionary values,
145145
string scheme,

0 commit comments

Comments
 (0)