Skip to content

Commit f5709b4

Browse files
authored
Add nullable annotations to Microsoft.AspNetCore.Mvc.Abstractions (#22993)
* Add nullable annotations to Microsoft.AspNetCore.Mvc.Abstractions Contributes to #5680 * Changes per PR comments * Changes per PR comments * Fixup
1 parent c566677 commit f5709b4

File tree

61 files changed

+344
-370
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+344
-370
lines changed

src/Mvc/Mvc.Abstractions/ref/Microsoft.AspNetCore.Mvc.Abstractions.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<Project Sdk="Microsoft.NET.Sdk">
33
<PropertyGroup>
44
<TargetFrameworks>$(DefaultNetCoreTargetFramework)</TargetFrameworks>
5+
<Nullable>annotations</Nullable>
56
</PropertyGroup>
67
<ItemGroup Condition="'$(TargetFramework)' == '$(DefaultNetCoreTargetFramework)'">
78
<Compile Include="Microsoft.AspNetCore.Mvc.Abstractions.netcoreapp.cs" />

src/Mvc/Mvc.Abstractions/ref/Microsoft.AspNetCore.Mvc.Abstractions.netcoreapp.cs

Lines changed: 96 additions & 93 deletions
Large diffs are not rendered by default.

src/Mvc/Mvc.Abstractions/src/Abstractions/ActionDescriptor.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,42 +38,42 @@ public ActionDescriptor()
3838
/// <summary>
3939
/// Gets or sets the <see cref="Routing.AttributeRouteInfo"/>.
4040
/// </summary>
41-
public AttributeRouteInfo AttributeRouteInfo { get; set; }
41+
public AttributeRouteInfo? AttributeRouteInfo { get; set; }
4242

4343
/// <summary>
4444
/// The set of constraints for this action. Must all be satisfied for the action to be selected.
4545
/// </summary>
46-
public IList<IActionConstraintMetadata> ActionConstraints { get; set; }
46+
public IList<IActionConstraintMetadata>? ActionConstraints { get; set; }
4747

4848
/// <summary>
4949
/// Gets or sets the endpoint metadata for this action.
5050
/// This API is meant for infrastructure and should not be used by application code.
5151
/// </summary>
52-
public IList<object> EndpointMetadata { get; set; }
52+
public IList<object> EndpointMetadata { get; set; } = Array.Empty<ParameterDescriptor>();
5353

5454
/// <summary>
5555
/// The set of parameters associated with this action.
5656
/// </summary>
57-
public IList<ParameterDescriptor> Parameters { get; set; }
57+
public IList<ParameterDescriptor> Parameters { get; set; } = Array.Empty<ParameterDescriptor>();
5858

5959
/// <summary>
6060
/// The set of properties which are model bound.
6161
/// </summary>
62-
public IList<ParameterDescriptor> BoundProperties { get; set; }
62+
public IList<ParameterDescriptor> BoundProperties { get; set; } = Array.Empty<ParameterDescriptor>();
6363

6464
/// <summary>
6565
/// The set of filters associated with this action.
6666
/// </summary>
67-
public IList<FilterDescriptor> FilterDescriptors { get; set; }
67+
public IList<FilterDescriptor> FilterDescriptors { get; set; } = Array.Empty<FilterDescriptor>();
6868

6969
/// <summary>
7070
/// A friendly name for this action.
7171
/// </summary>
72-
public virtual string DisplayName { get; set; }
72+
public virtual string? DisplayName { get; set; }
7373

7474
/// <summary>
7575
/// Stores arbitrary metadata properties associated with the <see cref="ActionDescriptor"/>.
7676
/// </summary>
77-
public IDictionary<object, object> Properties { get; set; }
77+
public IDictionary<object, object> Properties { get; set; } = default!;
7878
}
7979
}

src/Mvc/Mvc.Abstractions/src/Abstractions/ActionDescriptorExtensions.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,13 @@ public static T GetProperty<T>(this ActionDescriptor actionDescriptor)
2424
throw new ArgumentNullException(nameof(actionDescriptor));
2525
}
2626

27-
object value;
28-
if (actionDescriptor.Properties.TryGetValue(typeof(T), out value))
27+
if (actionDescriptor.Properties.TryGetValue(typeof(T), out var value))
2928
{
3029
return (T)value;
3130
}
3231
else
3332
{
34-
return default(T);
33+
return default!;
3534
}
3635
}
3736

src/Mvc/Mvc.Abstractions/src/Abstractions/ActionInvokerProviderContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@ public ActionInvokerProviderContext(ActionContext actionContext)
3232
/// <summary>
3333
/// Gets or sets the <see cref="IActionInvoker"/> that will be used to invoke <see cref="ActionContext" />
3434
/// </summary>
35-
public IActionInvoker Result { get; set; }
35+
public IActionInvoker? Result { get; set; }
3636
}
3737
}

src/Mvc/Mvc.Abstractions/src/Abstractions/ParameterDescriptor.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ public class ParameterDescriptor
1414
/// <summary>
1515
/// Gets or sets the parameter name.
1616
/// </summary>
17-
public string Name { get; set; }
17+
public string Name { get; set; } = default!;
1818

1919
/// <summary>
2020
/// Gets or sets the type of the parameter.
2121
/// </summary>
22-
public Type ParameterType { get; set; }
22+
public Type ParameterType { get; set; } = default!;
2323

2424
/// <summary>
2525
/// Gets or sets the <see cref="ModelBinding.BindingInfo"/> for the parameter.
2626
/// </summary>
27-
public BindingInfo BindingInfo { get; set; }
27+
public BindingInfo BindingInfo { get; set; } = default!;
2828
}
2929
}

src/Mvc/Mvc.Abstractions/src/ActionConstraints/ActionConstraintContext.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
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+
using System;
45
using System.Collections.Generic;
56
using Microsoft.AspNetCore.Routing;
67

@@ -15,16 +16,16 @@ public class ActionConstraintContext
1516
/// The list of <see cref="ActionSelectorCandidate"/>. This includes all actions that are valid for the current
1617
/// request, as well as their constraints.
1718
/// </summary>
18-
public IReadOnlyList<ActionSelectorCandidate> Candidates { get; set; }
19+
public IReadOnlyList<ActionSelectorCandidate> Candidates { get; set; } = Array.Empty<ActionSelectorCandidate>();
1920

2021
/// <summary>
2122
/// The current <see cref="ActionSelectorCandidate"/>.
2223
/// </summary>
23-
public ActionSelectorCandidate CurrentCandidate { get; set; }
24+
public ActionSelectorCandidate CurrentCandidate { get; set; } = default!;
2425

2526
/// <summary>
2627
/// The <see cref="RouteContext"/>.
2728
/// </summary>
28-
public RouteContext RouteContext { get; set; }
29+
public RouteContext RouteContext { get; set; } = default!;
2930
}
3031
}

src/Mvc/Mvc.Abstractions/src/ActionConstraints/ActionConstraintItem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public ActionConstraintItem(IActionConstraintMetadata metadata)
2828
/// <summary>
2929
/// The <see cref="IActionConstraint"/> associated with <see cref="Metadata"/>.
3030
/// </summary>
31-
public IActionConstraint Constraint { get; set; }
31+
public IActionConstraint Constraint { get; set; } = default!;
3232

3333
/// <summary>
3434
/// The <see cref="IActionConstraintMetadata"/> instance.

src/Mvc/Mvc.Abstractions/src/ActionContext.cs

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ public ActionContext()
3131
/// <param name="actionContext">The <see cref="ActionContext"/> to copy.</param>
3232
public ActionContext(ActionContext actionContext)
3333
: this(
34-
actionContext?.HttpContext,
35-
actionContext?.RouteData,
36-
actionContext?.ActionDescriptor,
37-
actionContext?.ModelState)
34+
actionContext.HttpContext,
35+
actionContext.RouteData,
36+
actionContext.ActionDescriptor,
37+
actionContext.ModelState)
3838
{
3939
}
4040

@@ -97,39 +97,27 @@ public ActionContext(
9797
/// <remarks>
9898
/// The property setter is provided for unit test purposes only.
9999
/// </remarks>
100-
public ActionDescriptor ActionDescriptor
101-
{
102-
get; set;
103-
}
100+
public ActionDescriptor ActionDescriptor { get; set; } = default!;
104101

105102
/// <summary>
106103
/// Gets or sets the <see cref="Http.HttpContext"/> for the current request.
107104
/// </summary>
108105
/// <remarks>
109106
/// The property setter is provided for unit test purposes only.
110107
/// </remarks>
111-
public HttpContext HttpContext
112-
{
113-
get; set;
114-
}
108+
public HttpContext HttpContext { get; set; } = default!;
115109

116110
/// <summary>
117111
/// Gets the <see cref="ModelStateDictionary"/>.
118112
/// </summary>
119-
public ModelStateDictionary ModelState
120-
{
121-
get;
122-
}
113+
public ModelStateDictionary ModelState { get; } = default!;
123114

124115
/// <summary>
125116
/// Gets or sets the <see cref="AspNetCore.Routing.RouteData"/> for the current request.
126117
/// </summary>
127118
/// <remarks>
128119
/// The property setter is provided for unit test purposes only.
129120
/// </remarks>
130-
public RouteData RouteData
131-
{
132-
get; set;
133-
}
121+
public RouteData RouteData { get; set; } = default!;
134122
}
135123
}

src/Mvc/Mvc.Abstractions/src/ApiExplorer/ApiDescription.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ public class ApiDescription
1616
/// <summary>
1717
/// Gets or sets <see cref="ActionDescriptor"/> for this api.
1818
/// </summary>
19-
public ActionDescriptor ActionDescriptor { get; set; }
19+
public ActionDescriptor ActionDescriptor { get; set; } = default!;
2020

2121
/// <summary>
2222
/// Gets or sets group name for this api.
2323
/// </summary>
24-
public string GroupName { get; set; }
24+
public string? GroupName { get; set; }
2525

2626
/// <summary>
2727
/// Gets or sets the supported HTTP method for this api, or null if all HTTP methods are supported.
2828
/// </summary>
29-
public string HttpMethod { get; set; }
29+
public string? HttpMethod { get; set; }
3030

3131
/// <summary>
3232
/// Gets a list of <see cref="ApiParameterDescription"/> for this api.
@@ -41,7 +41,7 @@ public class ApiDescription
4141
/// <summary>
4242
/// Gets or sets relative url path template (relative to application root) for this api.
4343
/// </summary>
44-
public string RelativePath { get; set; }
44+
public string RelativePath { get; set; } = default!;
4545

4646
/// <summary>
4747
/// Gets the list of possible formats for a request.

src/Mvc/Mvc.Abstractions/src/ApiExplorer/ApiParameterDescription.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,37 +15,37 @@ public class ApiParameterDescription
1515
/// <summary>
1616
/// Gets or sets the <see cref="ModelMetadata"/>.
1717
/// </summary>
18-
public ModelMetadata ModelMetadata { get; set; }
18+
public ModelMetadata ModelMetadata { get; set; } = default!;
1919

2020
/// <summary>
2121
/// Gets or sets the name.
2222
/// </summary>
23-
public string Name { get; set; }
23+
public string Name { get; set; } = default!;
2424

2525
/// <summary>
2626
/// Gets or sets the <see cref="ApiParameterRouteInfo"/>.
2727
/// </summary>
28-
public ApiParameterRouteInfo RouteInfo { get; set; }
28+
public ApiParameterRouteInfo? RouteInfo { get; set; }
2929

3030
/// <summary>
3131
/// Gets or sets the <see cref="BindingSource"/>.
3232
/// </summary>
33-
public BindingSource Source { get; set; }
33+
public BindingSource Source { get; set; } = default!;
3434

3535
/// <summary>
3636
/// Gets or sets the <see cref="BindingInfo"/>.
3737
/// </summary>
38-
public BindingInfo BindingInfo { get; set; }
38+
public BindingInfo? BindingInfo { get; set; }
3939

4040
/// <summary>
4141
/// Gets or sets the parameter type.
4242
/// </summary>
43-
public Type Type { get; set; }
43+
public Type Type { get; set; } = default!;
4444

4545
/// <summary>
4646
/// Gets or sets the parameter descriptor.
4747
/// </summary>
48-
public ParameterDescriptor ParameterDescriptor { get; set; }
48+
public ParameterDescriptor ParameterDescriptor { get; set; } = default!;
4949

5050
/// <summary>
5151
/// Gets or sets a value that determines if the parameter is required.
@@ -63,6 +63,6 @@ public class ApiParameterDescription
6363
/// <summary>
6464
/// Gets or sets the default value for a parameter.
6565
/// </summary>
66-
public object DefaultValue { get; set; }
66+
public object? DefaultValue { get; set; }
6767
}
6868
}

src/Mvc/Mvc.Abstractions/src/ApiExplorer/ApiParameterRouteInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ public class ApiParameterRouteInfo
1818
/// Route constraints are only applied when a value is bound from a URL's path. See
1919
/// <see cref="ApiParameterDescription.Source"/> for the data source considered.
2020
/// </remarks>
21-
public IEnumerable<IRouteConstraint> Constraints { get; set; }
21+
public IEnumerable<IRouteConstraint>? Constraints { get; set; }
2222

2323
/// <summary>
2424
/// Gets or sets the default value for the parameter.
2525
/// </summary>
26-
public object DefaultValue { get; set; }
26+
public object? DefaultValue { get; set; }
2727

2828
/// <summary>
2929
/// Gets a value indicating whether not a parameter is considered optional by routing.

src/Mvc/Mvc.Abstractions/src/ApiExplorer/ApiRequestFormat.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ public class ApiRequestFormat
1313
/// <summary>
1414
/// The formatter used to read this request.
1515
/// </summary>
16-
public IInputFormatter Formatter { get; set; }
16+
public IInputFormatter Formatter { get; set; } = default!;
1717

1818
/// <summary>
1919
/// The media type of the request.
2020
/// </summary>
21-
public string MediaType { get; set; }
21+
public string MediaType { get; set; } = default!;
2222
}
2323
}

src/Mvc/Mvc.Abstractions/src/ApiExplorer/ApiResponseFormat.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ public class ApiResponseFormat
1313
/// <summary>
1414
/// Gets or sets the formatter used to output this response.
1515
/// </summary>
16-
public IOutputFormatter Formatter { get; set; }
16+
public IOutputFormatter Formatter { get; set; } = default!;
1717

1818
/// <summary>
1919
/// Gets or sets the media type of the response.
2020
/// </summary>
21-
public string MediaType { get; set; }
21+
public string MediaType { get; set; } = default!;
2222
}
2323
}

src/Mvc/Mvc.Abstractions/src/ApiExplorer/ApiResponseType.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class ApiResponseType
2323
/// <remarks>
2424
/// Will be null if <see cref="Type"/> is null or void.
2525
/// </remarks>
26-
public ModelMetadata ModelMetadata { get; set; }
26+
public ModelMetadata? ModelMetadata { get; set; }
2727

2828
/// <summary>
2929
/// Gets or sets the CLR data type of the response or null.
@@ -33,7 +33,7 @@ public class ApiResponseType
3333
/// <c>Microsoft.AspNetCore.Mvc.ProducesAttribute</c> or <c>Microsoft.AspNetCore.Mvc.ProducesResponseTypeAttribute</c> on an action method
3434
/// to specify a response type.
3535
/// </remarks>
36-
public Type Type { get; set; }
36+
public Type? Type { get; set; }
3737

3838
/// <summary>
3939
/// Gets or sets the HTTP response status code.

src/Mvc/Mvc.Abstractions/src/Filters/ActionExecutedContext.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ namespace Microsoft.AspNetCore.Mvc.Filters
1212
/// </summary>
1313
public class ActionExecutedContext : FilterContext
1414
{
15-
private Exception _exception;
16-
private ExceptionDispatchInfo _exceptionDispatchInfo;
15+
private Exception? _exception;
16+
private ExceptionDispatchInfo? _exceptionDispatchInfo;
1717

1818
/// <summary>
1919
/// Instantiates a new <see cref="ActionExecutingContext"/> instance.
@@ -44,7 +44,7 @@ public ActionExecutedContext(
4444
/// Gets or sets the <see cref="System.Exception"/> caught while executing the action or action filters, if
4545
/// any.
4646
/// </summary>
47-
public virtual Exception Exception
47+
public virtual Exception? Exception
4848
{
4949
get
5050
{
@@ -69,7 +69,7 @@ public virtual Exception Exception
6969
/// Gets or sets the <see cref="System.Runtime.ExceptionServices.ExceptionDispatchInfo"/> for the
7070
/// <see cref="Exception"/>, if an <see cref="System.Exception"/> was caught and this information captured.
7171
/// </summary>
72-
public virtual ExceptionDispatchInfo ExceptionDispatchInfo
72+
public virtual ExceptionDispatchInfo? ExceptionDispatchInfo
7373
{
7474
get
7575
{
@@ -91,6 +91,6 @@ public virtual ExceptionDispatchInfo ExceptionDispatchInfo
9191
/// <summary>
9292
/// Gets or sets the <see cref="IActionResult"/>.
9393
/// </summary>
94-
public virtual IActionResult Result { get; set; }
94+
public virtual IActionResult Result { get; set; } = default!;
9595
}
9696
}

src/Mvc/Mvc.Abstractions/src/Filters/ActionExecutingContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public ActionExecutingContext(
4141
/// Gets or sets the <see cref="IActionResult"/> to execute. Setting <see cref="Result"/> to a non-<c>null</c>
4242
/// value inside an action filter will short-circuit the action and any remaining action filters.
4343
/// </summary>
44-
public virtual IActionResult Result { get; set; }
44+
public virtual IActionResult? Result { get; set; }
4545

4646
/// <summary>
4747
/// Gets the arguments to pass when invoking the action. Keys are parameter names.

0 commit comments

Comments
 (0)