Skip to content

Commit 53357e9

Browse files
committed
Add nullable annotations to Microsoft.AspNetCore.Mvc.Abstractions
Contributes to #5680
1 parent af0a3ed commit 53357e9

Some content is hidden

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

53 files changed

+313
-333
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: 93 additions & 90 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; }
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; } = default!;
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.

0 commit comments

Comments
 (0)