Skip to content

Add more nullability to Mvc.Core #31076

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
1 commit merged into from
Mar 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public ActionDescriptor()
{
Id = Guid.NewGuid().ToString();
Properties = new Dictionary<object, object>();
RouteValues = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
RouteValues = new Dictionary<string, string?>(StringComparer.OrdinalIgnoreCase);
}

/// <summary>
Expand All @@ -33,7 +33,7 @@ public ActionDescriptor()
/// Gets or sets the collection of route values that must be provided by routing
/// for the action to be selected.
/// </summary>
public IDictionary<string, string> RouteValues { get; set; }
public IDictionary<string, string?> RouteValues { get; set; }

/// <summary>
/// Gets or sets the <see cref="Routing.AttributeRouteInfo"/>.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ public class ParameterDescriptor
/// <summary>
/// Gets or sets the <see cref="ModelBinding.BindingInfo"/> for the parameter.
/// </summary>
public BindingInfo BindingInfo { get; set; } = default!;
public BindingInfo? BindingInfo { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public ActionConstraintItem(IActionConstraintMetadata metadata)
/// <summary>
/// The <see cref="IActionConstraint"/> associated with <see cref="Metadata"/>.
/// </summary>
public IActionConstraint Constraint { get; set; } = default!;
public IActionConstraint? Constraint { get; set; }

/// <summary>
/// The <see cref="IActionConstraintMetadata"/> instance.
Expand All @@ -40,4 +40,4 @@ public ActionConstraintItem(IActionConstraintMetadata metadata)
/// </summary>
public bool IsReusable { get; set; }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public readonly struct ActionSelectorCandidate
/// <param name="constraints">
/// The list of <see cref="IActionConstraint"/> instances associated with <paramref name="action"/>.
/// </param>
public ActionSelectorCandidate(ActionDescriptor action, IReadOnlyList<IActionConstraint> constraints)
public ActionSelectorCandidate(ActionDescriptor action, IReadOnlyList<IActionConstraint>? constraints)
{
if (action == null)
{
Expand All @@ -38,6 +38,6 @@ public ActionSelectorCandidate(ActionDescriptor action, IReadOnlyList<IActionCon
/// <summary>
/// The list of <see cref="IActionConstraint"/> instances associated with <see name="Action"/>.
/// </summary>
public IReadOnlyList<IActionConstraint> Constraints { get; }
public IReadOnlyList<IActionConstraint>? Constraints { get; }
}
}
}
2 changes: 1 addition & 1 deletion src/Mvc/Mvc.Abstractions/src/Filters/FilterItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public FilterItem(FilterDescriptor descriptor, IFilterMetadata filter)
/// <summary>
/// Gets or sets the executable <see cref="IFilterMetadata"/> associated with <see cref="Descriptor"/>.
/// </summary>
public IFilterMetadata Filter { get; set; } = default!;
public IFilterMetadata? Filter { get; set; }

/// <summary>
/// Gets or sets a value indicating whether or not <see cref="Filter"/> can be reused across requests.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ private InputFormatterResult(bool hasError)
HasError = hasError;
}

private InputFormatterResult(object model)
private InputFormatterResult(object? model)
{
Model = model;
IsModelSet = true;
Expand Down Expand Up @@ -79,7 +79,7 @@ public static Task<InputFormatterResult> FailureAsync()
/// An <see cref="InputFormatterResult"/> indicating the <see cref="IInputFormatter.ReadAsync"/>
/// operation succeeded i.e. with <see cref="HasError"/> <c>false</c>.
/// </returns>
public static InputFormatterResult Success(object model)
public static InputFormatterResult Success(object? model)
{
return new InputFormatterResult(model);
}
Expand All @@ -93,7 +93,7 @@ public static InputFormatterResult Success(object model)
/// A <see cref="Task"/> that on completion provides an <see cref="InputFormatterResult"/> indicating the
/// <see cref="IInputFormatter.ReadAsync"/> operation succeeded i.e. with <see cref="HasError"/> <c>false</c>.
/// </returns>
public static Task<InputFormatterResult> SuccessAsync(object model)
public static Task<InputFormatterResult> SuccessAsync(object? model)
{
return Task.FromResult(Success(model));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ public interface IBinderTypeProviderMetadata : IBindingSourceMetadata
/// <summary>
/// A <see cref="Type"/> which implements either <see cref="IModelBinder"/>.
/// </summary>
Type BinderType { get; }
Type? BinderType { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ public interface IModelNameProvider
/// <summary>
/// Model name.
/// </summary>
string Name { get; }
string? Name { get; }
}
}
22 changes: 22 additions & 0 deletions src/Mvc/Mvc.Abstractions/src/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,27 @@
*REMOVED*virtual Microsoft.AspNetCore.Mvc.Filters.ActionExecutingContext.ActionArguments.get -> System.Collections.Generic.IDictionary<string!, object!>!
*REMOVED*virtual Microsoft.AspNetCore.Mvc.ModelBinding.ModelMetadata.BoundConstructorInvoker.get -> System.Func<object![]!, object!>?
*REMOVED*virtual Microsoft.AspNetCore.Mvc.ModelBinding.ModelMetadata.ContainerMetadata.get -> Microsoft.AspNetCore.Mvc.ModelBinding.ModelMetadata!
*REMOVED*Microsoft.AspNetCore.Mvc.Abstractions.ActionDescriptor.RouteValues.get -> System.Collections.Generic.IDictionary<string!, string!>!
*REMOVED*Microsoft.AspNetCore.Mvc.Abstractions.ParameterDescriptor.BindingInfo.get -> Microsoft.AspNetCore.Mvc.ModelBinding.BindingInfo!
*REMOVED*Microsoft.AspNetCore.Mvc.ActionConstraints.ActionConstraintItem.Constraint.get -> Microsoft.AspNetCore.Mvc.ActionConstraints.IActionConstraint!
*REMOVED*Microsoft.AspNetCore.Mvc.ActionConstraints.ActionSelectorCandidate.ActionSelectorCandidate(Microsoft.AspNetCore.Mvc.Abstractions.ActionDescriptor! action, System.Collections.Generic.IReadOnlyList<Microsoft.AspNetCore.Mvc.ActionConstraints.IActionConstraint!>! constraints) -> void
*REMOVED*Microsoft.AspNetCore.Mvc.ActionConstraints.ActionSelectorCandidate.Constraints.get -> System.Collections.Generic.IReadOnlyList<Microsoft.AspNetCore.Mvc.ActionConstraints.IActionConstraint!>!
*REMOVED*Microsoft.AspNetCore.Mvc.Filters.FilterItem.Filter.get -> Microsoft.AspNetCore.Mvc.Filters.IFilterMetadata!
*REMOVED*Microsoft.AspNetCore.Mvc.ModelBinding.IBinderTypeProviderMetadata.BinderType.get -> System.Type!
*REMOVED*Microsoft.AspNetCore.Mvc.ModelBinding.IModelNameProvider.Name.get -> string!
*REMOVED*Microsoft.AspNetCore.Mvc.Routing.AttributeRouteInfo.Name.get -> string!
*REMOVED*static Microsoft.AspNetCore.Mvc.Formatters.InputFormatterResult.Success(object! model) -> Microsoft.AspNetCore.Mvc.Formatters.InputFormatterResult!
*REMOVED*static Microsoft.AspNetCore.Mvc.Formatters.InputFormatterResult.SuccessAsync(object! model) -> System.Threading.Tasks.Task<Microsoft.AspNetCore.Mvc.Formatters.InputFormatterResult!>!
Microsoft.AspNetCore.Mvc.Abstractions.ActionDescriptor.RouteValues.get -> System.Collections.Generic.IDictionary<string!, string?>!
Microsoft.AspNetCore.Mvc.Abstractions.ParameterDescriptor.BindingInfo.get -> Microsoft.AspNetCore.Mvc.ModelBinding.BindingInfo?
Microsoft.AspNetCore.Mvc.ActionConstraints.ActionConstraintItem.Constraint.get -> Microsoft.AspNetCore.Mvc.ActionConstraints.IActionConstraint?
Microsoft.AspNetCore.Mvc.ActionConstraints.ActionSelectorCandidate.ActionSelectorCandidate(Microsoft.AspNetCore.Mvc.Abstractions.ActionDescriptor! action, System.Collections.Generic.IReadOnlyList<Microsoft.AspNetCore.Mvc.ActionConstraints.IActionConstraint!>? constraints) -> void
Microsoft.AspNetCore.Mvc.ActionConstraints.ActionSelectorCandidate.Constraints.get -> System.Collections.Generic.IReadOnlyList<Microsoft.AspNetCore.Mvc.ActionConstraints.IActionConstraint!>?
Microsoft.AspNetCore.Mvc.Filters.ActionExecutingContext.ActionExecutingContext(Microsoft.AspNetCore.Mvc.ActionContext! actionContext, System.Collections.Generic.IList<Microsoft.AspNetCore.Mvc.Filters.IFilterMetadata!>! filters, System.Collections.Generic.IDictionary<string!, object?>! actionArguments, object! controller) -> void
Microsoft.AspNetCore.Mvc.Filters.FilterItem.Filter.get -> Microsoft.AspNetCore.Mvc.Filters.IFilterMetadata?
Microsoft.AspNetCore.Mvc.Formatters.OutputFormatterWriteContext.OutputFormatterWriteContext(Microsoft.AspNetCore.Http.HttpContext! httpContext, System.Func<System.IO.Stream!, System.Text.Encoding!, System.IO.TextWriter!>! writerFactory, System.Type? objectType, object? object) -> void
Microsoft.AspNetCore.Mvc.ModelBinding.IBinderTypeProviderMetadata.BinderType.get -> System.Type?
Microsoft.AspNetCore.Mvc.ModelBinding.IModelNameProvider.Name.get -> string?
Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary.SetModelValue(string! key, object? rawValue, string? attemptedValue) -> void
Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary.this[string! key].get -> Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateEntry?
Microsoft.AspNetCore.Mvc.ModelBinding.Validation.ClientValidatorItem.ClientValidatorItem(object? validatorMetadata) -> void
Expand All @@ -53,6 +72,7 @@ Microsoft.AspNetCore.Mvc.ModelBinding.Validation.ValidationEntry.ValidationEntry
Microsoft.AspNetCore.Mvc.ModelBinding.Validation.ValidationEntry.ValidationEntry(Microsoft.AspNetCore.Mvc.ModelBinding.ModelMetadata! metadata, string! key, object? model) -> void
Microsoft.AspNetCore.Mvc.ModelBinding.Validation.ValidatorItem.Validator.get -> Microsoft.AspNetCore.Mvc.ModelBinding.Validation.IModelValidator?
Microsoft.AspNetCore.Mvc.ModelBinding.ValueProviderResult.ValueProviderResult(Microsoft.Extensions.Primitives.StringValues values, System.Globalization.CultureInfo? culture) -> void
Microsoft.AspNetCore.Mvc.Routing.AttributeRouteInfo.Name.get -> string?
abstract Microsoft.AspNetCore.Mvc.ModelBinding.ModelBindingContext.BinderModelName.get -> string?
abstract Microsoft.AspNetCore.Mvc.ModelBinding.ModelBindingContext.BindingSource.get -> Microsoft.AspNetCore.Mvc.ModelBinding.BindingSource?
abstract Microsoft.AspNetCore.Mvc.ModelBinding.ModelBindingContext.EnterNestedScope(Microsoft.AspNetCore.Mvc.ModelBinding.ModelMetadata! modelMetadata, string! fieldName, string! modelName, object? model) -> Microsoft.AspNetCore.Mvc.ModelBinding.ModelBindingContext.NestedScope
Expand All @@ -75,6 +95,8 @@ abstract Microsoft.AspNetCore.Mvc.ModelBinding.ModelMetadata.PropertyGetter.get
abstract Microsoft.AspNetCore.Mvc.ModelBinding.ModelMetadata.PropertySetter.get -> System.Action<object!, object?>?
abstract Microsoft.AspNetCore.Mvc.ModelBinding.ModelMetadata.SimpleDisplayProperty.get -> string?
abstract Microsoft.AspNetCore.Mvc.ModelBinding.ModelMetadata.TemplateHint.get -> string?
static Microsoft.AspNetCore.Mvc.Formatters.InputFormatterResult.Success(object? model) -> Microsoft.AspNetCore.Mvc.Formatters.InputFormatterResult!
static Microsoft.AspNetCore.Mvc.Formatters.InputFormatterResult.SuccessAsync(object? model) -> System.Threading.Tasks.Task<Microsoft.AspNetCore.Mvc.Formatters.InputFormatterResult!>!
virtual Microsoft.AspNetCore.Mvc.Filters.ActionExecutedContext.Result.get -> Microsoft.AspNetCore.Mvc.IActionResult?
virtual Microsoft.AspNetCore.Mvc.Filters.ActionExecutingContext.ActionArguments.get -> System.Collections.Generic.IDictionary<string!, object?>!
virtual Microsoft.AspNetCore.Mvc.ModelBinding.ModelMetadata.BoundConstructorInvoker.get -> System.Func<object?[]!, object!>?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class AttributeRouteInfo
/// to generate a link by referring to the route by name instead of attempting to match a
/// route by provided route data.
/// </summary>
public string Name { get; set; } = default!;
public string? Name { get; set; }

/// <summary>
/// Gets or sets a value that determines if the route entry associated with this model participates in link generation.
Expand Down
6 changes: 3 additions & 3 deletions src/Mvc/Mvc.Core/src/AcceptVerbsAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ public AcceptVerbsAttribute(params string[] methods)
/// <summary>
/// The route template. May be null.
/// </summary>
public string Route { get; set; }
public string? Route { get; set; }

/// <inheritdoc />
string IRouteTemplateProvider.Template => Route;
string? IRouteTemplateProvider.Template => Route;

/// <summary>
/// Gets the route order. The order determines the order of route execution. Routes with a lower
Expand All @@ -69,6 +69,6 @@ public int Order
int? IRouteTemplateProvider.Order => _order;

/// <inheritdoc />
public string Name { get; set; }
public string? Name { get; set; }
}
}
16 changes: 8 additions & 8 deletions src/Mvc/Mvc.Core/src/AcceptedAtActionResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ public class AcceptedAtActionResult : ObjectResult
/// <param name="routeValues">The route data to use for generating the URL.</param>
/// <param name="value">The value to format in the entity body.</param>
public AcceptedAtActionResult(
string actionName,
string controllerName,
object routeValues,
[ActionResultObjectValue] object value)
string? actionName,
string? controllerName,
object? routeValues,
[ActionResultObjectValue] object? value)
: base(value)
{
ActionName = actionName;
Expand All @@ -44,22 +44,22 @@ public AcceptedAtActionResult(
/// <summary>
/// Gets or sets the <see cref="IUrlHelper" /> used to generate URLs.
/// </summary>
public IUrlHelper UrlHelper { get; set; }
public IUrlHelper? UrlHelper { get; set; }

/// <summary>
/// Gets or sets the name of the action to use for generating the URL.
/// </summary>
public string ActionName { get; set; }
public string? ActionName { get; set; }

/// <summary>
/// Gets or sets the name of the controller to use for generating the URL.
/// </summary>
public string ControllerName { get; set; }
public string? ControllerName { get; set; }

/// <summary>
/// Gets or sets the route data to use for generating the URL.
/// </summary>
public RouteValueDictionary RouteValues { get; set; }
public RouteValueDictionary? RouteValues { get; set; }

/// <inheritdoc />
public override void OnFormatting(ActionContext context)
Expand Down
14 changes: 7 additions & 7 deletions src/Mvc/Mvc.Core/src/AcceptedAtRouteResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class AcceptedAtRouteResult : ObjectResult
/// </summary>
/// <param name="routeValues">The route data to use for generating the URL.</param>
/// <param name="value">The value to format in the entity body.</param>
public AcceptedAtRouteResult(object routeValues, [ActionResultObjectValue] object value)
public AcceptedAtRouteResult(object? routeValues, [ActionResultObjectValue] object? value)
: this(routeName: null, routeValues: routeValues, value: value)
{
}
Expand All @@ -39,9 +39,9 @@ public AcceptedAtRouteResult(object routeValues, [ActionResultObjectValue] objec
/// <param name="routeValues">The route data to use for generating the URL.</param>
/// <param name="value">The value to format in the entity body.</param>
public AcceptedAtRouteResult(
string routeName,
object routeValues,
[ActionResultObjectValue] object value)
string? routeName,
object? routeValues,
[ActionResultObjectValue] object? value)
: base(value)
{
RouteName = routeName;
Expand All @@ -52,17 +52,17 @@ public AcceptedAtRouteResult(
/// <summary>
/// Gets or sets the <see cref="IUrlHelper" /> used to generate URLs.
/// </summary>
public IUrlHelper UrlHelper { get; set; }
public IUrlHelper? UrlHelper { get; set; }

/// <summary>
/// Gets or sets the name of the route to use for generating the URL.
/// </summary>
public string RouteName { get; set; }
public string? RouteName { get; set; }

/// <summary>
/// Gets or sets the route data to use for generating the URL.
/// </summary>
public RouteValueDictionary RouteValues { get; set; }
public RouteValueDictionary? RouteValues { get; set; }

/// <inheritdoc />
public override void OnFormatting(ActionContext context)
Expand Down
9 changes: 4 additions & 5 deletions src/Mvc/Mvc.Core/src/AcceptedResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public AcceptedResult()
/// </summary>
/// <param name="location">The location at which the status of requested content can be monitored.</param>
/// <param name="value">The value to format in the entity body.</param>
public AcceptedResult(string location, [ActionResultObjectValue] object value)
public AcceptedResult(string? location, [ActionResultObjectValue] object? value)
: base(value)
{
Location = location;
Expand All @@ -43,10 +43,9 @@ public AcceptedResult(string location, [ActionResultObjectValue] object value)
/// Initializes a new instance of the <see cref="AcceptedResult"/> class with the values
/// provided.
/// </summary>
/// <param name="locationUri">The location at which the status of requested content can be monitored
/// It is an optional parameter and may be null</param>
/// <param name="locationUri">The location at which the status of requested content can be monitored.</param>
/// <param name="value">The value to format in the entity body.</param>
public AcceptedResult(Uri locationUri, [ActionResultObjectValue] object value)
public AcceptedResult(Uri locationUri, [ActionResultObjectValue] object? value)
: base(value)
{
if (locationUri == null)
Expand All @@ -69,7 +68,7 @@ public AcceptedResult(Uri locationUri, [ActionResultObjectValue] object value)
/// <summary>
/// Gets or sets the location at which the status of the requested content can be monitored.
/// </summary>
public string Location { get; set; }
public string? Location { get; set; }

/// <inheritdoc />
public override void OnFormatting(ActionContext context)
Expand Down
Loading