diff --git a/src/Mvc/Mvc.Abstractions/ref/Microsoft.AspNetCore.Mvc.Abstractions.csproj b/src/Mvc/Mvc.Abstractions/ref/Microsoft.AspNetCore.Mvc.Abstractions.csproj
index ce0671621e..2ae7b2695e 100644
--- a/src/Mvc/Mvc.Abstractions/ref/Microsoft.AspNetCore.Mvc.Abstractions.csproj
+++ b/src/Mvc/Mvc.Abstractions/ref/Microsoft.AspNetCore.Mvc.Abstractions.csproj
@@ -2,6 +2,7 @@
$(DefaultNetCoreTargetFramework)
+ annotations
diff --git a/src/Mvc/Mvc.Abstractions/ref/Microsoft.AspNetCore.Mvc.Abstractions.netcoreapp.cs b/src/Mvc/Mvc.Abstractions/ref/Microsoft.AspNetCore.Mvc.Abstractions.netcoreapp.cs
index 84ca15ad39..267c99ef8a 100644
--- a/src/Mvc/Mvc.Abstractions/ref/Microsoft.AspNetCore.Mvc.Abstractions.netcoreapp.cs
+++ b/src/Mvc/Mvc.Abstractions/ref/Microsoft.AspNetCore.Mvc.Abstractions.netcoreapp.cs
@@ -33,10 +33,10 @@ namespace Microsoft.AspNetCore.Mvc.Abstractions
public partial class ActionDescriptor
{
public ActionDescriptor() { }
- public System.Collections.Generic.IList ActionConstraints { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
- public Microsoft.AspNetCore.Mvc.Routing.AttributeRouteInfo AttributeRouteInfo { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
+ public System.Collections.Generic.IList? ActionConstraints { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
+ public Microsoft.AspNetCore.Mvc.Routing.AttributeRouteInfo? AttributeRouteInfo { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
public System.Collections.Generic.IList BoundProperties { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
- public virtual string DisplayName { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
+ public virtual string? DisplayName { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
public System.Collections.Generic.IList
diff --git a/src/Mvc/Mvc.Abstractions/src/ModelBinding/BindingInfo.cs b/src/Mvc/Mvc.Abstractions/src/ModelBinding/BindingInfo.cs
index 38fbc894a9..b7379ae4e0 100644
--- a/src/Mvc/Mvc.Abstractions/src/ModelBinding/BindingInfo.cs
+++ b/src/Mvc/Mvc.Abstractions/src/ModelBinding/BindingInfo.cs
@@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
///
public class BindingInfo
{
- private Type _binderType;
+ private Type? _binderType;
///
/// Creates a new .
@@ -44,12 +44,12 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
///
/// Gets or sets the .
///
- public BindingSource BindingSource { get; set; }
+ public BindingSource? BindingSource { get; set; }
///
/// Gets or sets the binder model name.
///
- public string BinderModelName { get; set; }
+ public string? BinderModelName { get; set; }
///
/// Gets or sets the of the implementation used to bind the
@@ -59,7 +59,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
/// Also set if the specified implementation does not
/// use values from form data, route values or the query string.
///
- public Type BinderType
+ public Type? BinderType
{
get => _binderType;
set
@@ -80,13 +80,13 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
///
/// Gets or sets the .
///
- public IPropertyFilterProvider PropertyFilterProvider { get; set; }
+ public IPropertyFilterProvider? PropertyFilterProvider { get; set; }
///
/// Gets or sets a predicate which determines whether or not the model should be bound based on state
/// from the current request.
///
- public Func RequestPredicate { get; set; }
+ public Func? RequestPredicate { get; set; }
///
/// Gets or sets the value which decides if empty bodies are treated as valid inputs.
@@ -104,7 +104,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
/// A collection of attributes which are used to construct
///
/// A new instance of .
- public static BindingInfo GetBindingInfo(IEnumerable attributes)
+ public static BindingInfo? GetBindingInfo(IEnumerable attributes)
{
var bindingInfo = new BindingInfo();
var isBindingInfoPresent = false;
@@ -182,7 +182,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
/// A collection of attributes which are used to construct .
/// The .
/// A new instance of if any binding metadata was discovered; otherwise or .
- public static BindingInfo GetBindingInfo(IEnumerable attributes, ModelMetadata modelMetadata)
+ public static BindingInfo? GetBindingInfo(IEnumerable attributes, ModelMetadata modelMetadata)
{
if (attributes == null)
{
diff --git a/src/Mvc/Mvc.Abstractions/src/ModelBinding/BindingSource.cs b/src/Mvc/Mvc.Abstractions/src/ModelBinding/BindingSource.cs
index 97105efe3c..ea06036844 100644
--- a/src/Mvc/Mvc.Abstractions/src/ModelBinding/BindingSource.cs
+++ b/src/Mvc/Mvc.Abstractions/src/ModelBinding/BindingSource.cs
@@ -12,7 +12,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
/// A metadata object representing a source of data for model binding.
///
[DebuggerDisplay("Source: {DisplayName}")]
- public class BindingSource : IEquatable
+ public class BindingSource : IEquatable
{
///
/// A for the request body.
@@ -210,13 +210,13 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
}
///
- public bool Equals(BindingSource other)
+ public bool Equals(BindingSource? other)
{
return string.Equals(other?.Id, Id, StringComparison.Ordinal);
}
///
- public override bool Equals(object obj)
+ public override bool Equals(object? obj)
{
return Equals(obj as BindingSource);
}
@@ -228,7 +228,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
}
///
- public static bool operator ==(BindingSource s1, BindingSource s2)
+ public static bool operator ==(BindingSource? s1, BindingSource? s2)
{
if (s1 is null)
{
@@ -239,7 +239,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
}
///
- public static bool operator !=(BindingSource s1, BindingSource s2)
+ public static bool operator !=(BindingSource? s1, BindingSource? s2)
{
return !(s1 == s2);
}
diff --git a/src/Mvc/Mvc.Abstractions/src/ModelBinding/CompositeBindingSource.cs b/src/Mvc/Mvc.Abstractions/src/ModelBinding/CompositeBindingSource.cs
index 886deb9951..99044400b5 100644
--- a/src/Mvc/Mvc.Abstractions/src/ModelBinding/CompositeBindingSource.cs
+++ b/src/Mvc/Mvc.Abstractions/src/ModelBinding/CompositeBindingSource.cs
@@ -89,7 +89,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
///
public override bool CanAcceptDataFrom(BindingSource bindingSource)
{
- if (bindingSource == null)
+ if (bindingSource is null)
{
throw new ArgumentNullException(nameof(bindingSource));
}
diff --git a/src/Mvc/Mvc.Abstractions/src/ModelBinding/IBindingSourceMetadata.cs b/src/Mvc/Mvc.Abstractions/src/ModelBinding/IBindingSourceMetadata.cs
index 4a1ed31275..8639ce826e 100644
--- a/src/Mvc/Mvc.Abstractions/src/ModelBinding/IBindingSourceMetadata.cs
+++ b/src/Mvc/Mvc.Abstractions/src/ModelBinding/IBindingSourceMetadata.cs
@@ -15,6 +15,6 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
/// The is metadata which can be used to determine which data
/// sources are valid for model binding of a property or parameter.
///
- BindingSource BindingSource { get; }
+ BindingSource? BindingSource { get; }
}
}
\ No newline at end of file
diff --git a/src/Mvc/Mvc.Abstractions/src/ModelBinding/Metadata/ModelBindingMessageProvider.cs b/src/Mvc/Mvc.Abstractions/src/ModelBinding/Metadata/ModelBindingMessageProvider.cs
index c91bfe4cb0..7992450f37 100644
--- a/src/Mvc/Mvc.Abstractions/src/ModelBinding/Metadata/ModelBindingMessageProvider.cs
+++ b/src/Mvc/Mvc.Abstractions/src/ModelBinding/Metadata/ModelBindingMessageProvider.cs
@@ -17,28 +17,28 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Metadata
///
/// Default is "A value for the '{0}' parameter or property was not provided.".
///
- public virtual Func MissingBindRequiredValueAccessor { get; }
+ public virtual Func MissingBindRequiredValueAccessor { get; } = default!;
///
/// Error message the model binding system adds when either the key or the value of a
/// is bound but not both.
///
/// Default is "A value is required.".
- public virtual Func MissingKeyOrValueAccessor { get; }
+ public virtual Func MissingKeyOrValueAccessor { get; } = default!;
///
/// Error message the model binding system adds when no value is provided for the request body,
/// but a value is required.
///
/// Default is "A non-empty request body is required.".
- public virtual Func MissingRequestBodyRequiredValueAccessor { get; }
+ public virtual Func MissingRequestBodyRequiredValueAccessor { get; } = default!;
///
/// Error message the model binding system adds when a null value is bound to a
/// non- property.
///
/// Default is "The value '{0}' is invalid.".
- public virtual Func ValueMustNotBeNullAccessor { get; }
+ public virtual Func ValueMustNotBeNullAccessor { get; } = default!;
///
/// Error message the model binding system adds when is of type
@@ -46,7 +46,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Metadata
/// with a property.
///
/// Default is "The value '{0}' is not valid for {1}.".
- public virtual Func AttemptedValueIsInvalidAccessor { get; }
+ public virtual Func AttemptedValueIsInvalidAccessor { get; } = default!;
///
/// Error message the model binding system adds when is of type
@@ -54,7 +54,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Metadata
/// with a collection element or action parameter.
///
/// Default is "The value '{0}' is not valid.".
- public virtual Func NonPropertyAttemptedValueIsInvalidAccessor { get; }
+ public virtual Func NonPropertyAttemptedValueIsInvalidAccessor { get; } = default!;
///
/// Error message the model binding system adds when is of type
@@ -62,7 +62,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Metadata
/// with a property.
///
/// Default is "The supplied value is invalid for {0}.".
- public virtual Func UnknownValueIsInvalidAccessor { get; }
+ public virtual Func UnknownValueIsInvalidAccessor { get; } = default!;
///
/// Error message the model binding system adds when is of type
@@ -70,21 +70,21 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Metadata
/// with a collection element or action parameter.
///
/// Default is "The supplied value is invalid.".
- public virtual Func NonPropertyUnknownValueIsInvalidAccessor { get; }
+ public virtual Func NonPropertyUnknownValueIsInvalidAccessor { get; } = default!;
///
/// Fallback error message HTML and tag helpers display when a property is invalid but the
/// s have nulls.
///
/// Default is "The value '{0}' is invalid.".
- public virtual Func ValueIsInvalidAccessor { get; }
+ public virtual Func ValueIsInvalidAccessor { get; } = default!;
///
/// Error message HTML and tag helpers add for client-side validation of numeric formats. Visible in the
/// browser if the field for a float (for example) property does not have a correctly-formatted value.
///
/// Default is "The field {0} must be a number.".
- public virtual Func ValueMustBeANumberAccessor { get; }
+ public virtual Func ValueMustBeANumberAccessor { get; } = default!;
///
/// Error message HTML and tag helpers add for client-side validation of numeric formats. Visible in the
@@ -92,6 +92,6 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Metadata
/// correctly-formatted value.
///
/// Default is "The field must be a number.".
- public virtual Func NonPropertyValueMustBeANumberAccessor { get; }
+ public virtual Func NonPropertyValueMustBeANumberAccessor { get; } = default!;
}
}
diff --git a/src/Mvc/Mvc.Abstractions/src/ModelBinding/Metadata/ModelMetadataIdentity.cs b/src/Mvc/Mvc.Abstractions/src/ModelBinding/Metadata/ModelMetadataIdentity.cs
index 9b1cf4fec2..5fff9bad3d 100644
--- a/src/Mvc/Mvc.Abstractions/src/ModelBinding/Metadata/ModelMetadataIdentity.cs
+++ b/src/Mvc/Mvc.Abstractions/src/ModelBinding/Metadata/ModelMetadataIdentity.cs
@@ -4,7 +4,6 @@
using System;
using System.Reflection;
using Microsoft.AspNetCore.Mvc.Abstractions;
-using Microsoft.Extensions.Internal;
namespace Microsoft.AspNetCore.Mvc.ModelBinding.Metadata
{
@@ -15,9 +14,9 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Metadata
{
private ModelMetadataIdentity(
Type modelType,
- string name = null,
- Type containerType = null,
- object fieldInfo = null)
+ string? name = null,
+ Type? containerType = null,
+ object? fieldInfo = null)
{
ModelType = modelType;
Name = name;
@@ -107,7 +106,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Metadata
/// The .
/// A .
public static ModelMetadataIdentity ForParameter(ParameterInfo parameter)
- => ForParameter(parameter, parameter?.ParameterType);
+ => ForParameter(parameter, parameter.ParameterType);
///
/// Creates a for the provided parameter with the specified
@@ -135,7 +134,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Metadata
/// Gets the defining the model property represented by the current
/// instance, or null if the current instance does not represent a property.
///
- public Type ContainerType { get; }
+ public Type? ContainerType { get; }
///
/// Gets the represented by the current instance.
@@ -168,21 +167,21 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Metadata
/// Gets the name of the current instance if it represents a parameter or property, or null if
/// the current instance represents a type.
///
- public string Name { get; }
+ public string? Name { get; }
- private object FieldInfo { get; }
+ private object? FieldInfo { get; }
///
/// Gets a descriptor for the parameter, or null if this instance
/// does not represent a parameter.
///
- public ParameterInfo ParameterInfo => FieldInfo as ParameterInfo;
+ public ParameterInfo? ParameterInfo => FieldInfo as ParameterInfo;
///
/// Gets a descriptor for the property, or null if this instance
/// does not represent a property.
///
- public PropertyInfo PropertyInfo => FieldInfo as PropertyInfo;
+ public PropertyInfo? PropertyInfo => FieldInfo as PropertyInfo;
///
public bool Equals(ModelMetadataIdentity other)
@@ -196,7 +195,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Metadata
}
///
- public override bool Equals(object obj)
+ public override bool Equals(object? obj)
{
var other = obj as ModelMetadataIdentity?;
return other.HasValue && Equals(other.Value);
@@ -205,13 +204,13 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Metadata
///
public override int GetHashCode()
{
- var hash = new HashCodeCombiner();
+ var hash = new HashCode();
hash.Add(ContainerType);
hash.Add(ModelType);
hash.Add(Name, StringComparer.Ordinal);
hash.Add(ParameterInfo);
hash.Add(PropertyInfo);
- return hash;
+ return hash.ToHashCode();
}
}
}
\ No newline at end of file
diff --git a/src/Mvc/Mvc.Abstractions/src/ModelBinding/ModelBinderProviderContext.cs b/src/Mvc/Mvc.Abstractions/src/ModelBinding/ModelBinderProviderContext.cs
index 6228923e70..c35c8c4814 100644
--- a/src/Mvc/Mvc.Abstractions/src/ModelBinding/ModelBinderProviderContext.cs
+++ b/src/Mvc/Mvc.Abstractions/src/ModelBinding/ModelBinderProviderContext.cs
@@ -48,6 +48,6 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
///
/// Gets the .
///
- public virtual IServiceProvider Services { get; }
+ public virtual IServiceProvider Services { get; } = default!;
}
}
\ No newline at end of file
diff --git a/src/Mvc/Mvc.Abstractions/src/ModelBinding/ModelBindingContext.cs b/src/Mvc/Mvc.Abstractions/src/ModelBinding/ModelBindingContext.cs
index 915ea38085..3dfd4790f3 100644
--- a/src/Mvc/Mvc.Abstractions/src/ModelBinding/ModelBindingContext.cs
+++ b/src/Mvc/Mvc.Abstractions/src/ModelBinding/ModelBindingContext.cs
@@ -39,7 +39,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
///
/// Gets the associated with this context.
///
- public virtual HttpContext HttpContext => ActionContext?.HttpContext;
+ public virtual HttpContext HttpContext => ActionContext?.HttpContext!;
///
/// Gets or sets an indication that the current binder is handling the top-level object.
@@ -71,7 +71,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
/// Gets or sets the name of the top-level model. This is not reset to when value
/// providers have no match for that model.
///
- public string OriginalModelName { get; protected set; }
+ public string OriginalModelName { get; protected set; } = default!;
///
/// Gets or sets the used to capture values
diff --git a/src/Mvc/Mvc.Abstractions/src/ModelBinding/ModelBindingResult.cs b/src/Mvc/Mvc.Abstractions/src/ModelBinding/ModelBindingResult.cs
index 2bfc3dd5fd..3ab9c0ba4f 100644
--- a/src/Mvc/Mvc.Abstractions/src/ModelBinding/ModelBindingResult.cs
+++ b/src/Mvc/Mvc.Abstractions/src/ModelBinding/ModelBindingResult.cs
@@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
-using Microsoft.Extensions.Internal;
namespace Microsoft.AspNetCore.Mvc.ModelBinding
{
@@ -19,7 +18,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
{
return new ModelBindingResult(model: null, isModelSet: false);
}
-
+
///
/// Creates a representing a successful model binding operation.
///
@@ -27,10 +26,10 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
/// A representing a successful model bind.
public static ModelBindingResult Success(object model)
{
- return new ModelBindingResult( model, isModelSet: true);
+ return new ModelBindingResult(model, isModelSet: true);
}
- private ModelBindingResult(object model, bool isModelSet)
+ private ModelBindingResult(object? model, bool isModelSet)
{
Model = model;
IsModelSet = isModelSet;
@@ -39,7 +38,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
///
/// Gets the model associated with this context.
///
- public object Model { get; }
+ public object? Model { get; }
///
///
@@ -53,7 +52,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
public bool IsModelSet { get; }
///
- public override bool Equals(object obj)
+ public override bool Equals(object? obj)
{
var other = obj as ModelBindingResult?;
if (other == null)
@@ -69,11 +68,11 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
///
public override int GetHashCode()
{
- var hashCodeCombiner = HashCodeCombiner.Start();
+ var hashCodeCombiner = new HashCode();
hashCodeCombiner.Add(IsModelSet);
hashCodeCombiner.Add(Model);
- return hashCodeCombiner.CombinedHash;
+ return hashCodeCombiner.ToHashCode();
}
///
diff --git a/src/Mvc/Mvc.Abstractions/src/ModelBinding/ModelError.cs b/src/Mvc/Mvc.Abstractions/src/ModelBinding/ModelError.cs
index 0473e20d5d..d30796e081 100644
--- a/src/Mvc/Mvc.Abstractions/src/ModelBinding/ModelError.cs
+++ b/src/Mvc/Mvc.Abstractions/src/ModelBinding/ModelError.cs
@@ -25,7 +25,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
///
/// The .
/// The error message.
- public ModelError(Exception exception, string errorMessage)
+ public ModelError(Exception exception, string? errorMessage)
: this(errorMessage)
{
Exception = exception ?? throw new ArgumentNullException(nameof(exception));
@@ -35,7 +35,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
/// Initializes a new instance of with the specified .
///
/// The error message.
- public ModelError(string errorMessage)
+ public ModelError(string? errorMessage)
{
ErrorMessage = errorMessage ?? string.Empty;
}
@@ -43,7 +43,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
///
/// Gets the associated with this instance.
///
- public Exception Exception { get; }
+ public Exception? Exception { get; }
///
/// Gets the error message associated with this instance.
diff --git a/src/Mvc/Mvc.Abstractions/src/ModelBinding/ModelMetadata.cs b/src/Mvc/Mvc.Abstractions/src/ModelBinding/ModelMetadata.cs
index 4733f732cd..f04cac166e 100644
--- a/src/Mvc/Mvc.Abstractions/src/ModelBinding/ModelMetadata.cs
+++ b/src/Mvc/Mvc.Abstractions/src/ModelBinding/ModelMetadata.cs
@@ -17,7 +17,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
/// A metadata representation of a model type, property or parameter.
///
[DebuggerDisplay("{DebuggerToString(),nq}")]
- public abstract class ModelMetadata : IEquatable, IModelMetadataProvider
+ public abstract class ModelMetadata : IEquatable, IModelMetadataProvider
{
///
/// The default value of .
@@ -40,7 +40,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
///
/// Gets the type containing the property if this metadata is for a property; otherwise.
///
- public Type ContainerType => Identity.ContainerType;
+ public Type? ContainerType => Identity.ContainerType;
///
/// Gets the metadata for if this metadata is for a property;
@@ -68,17 +68,17 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
/// Gets the name of the parameter or property if this metadata is for a parameter or property;
/// otherwise i.e. if this is the metadata for a type.
///
- public string Name => Identity.Name;
+ public string? Name => Identity.Name;
///
/// Gets the name of the parameter if this metadata is for a parameter; otherwise.
///
- public string ParameterName => MetadataKind == ModelMetadataKind.Parameter ? Identity.Name : null;
+ public string? ParameterName => MetadataKind == ModelMetadataKind.Parameter ? Identity.Name : null;
///
/// Gets the name of the property if this metadata is for a property; otherwise.
///
- public string PropertyName => MetadataKind == ModelMetadataKind.Property ? Identity.Name : null;
+ public string? PropertyName => MetadataKind == ModelMetadataKind.Property ? Identity.Name : null;
///
/// Gets the key for the current instance.
@@ -155,7 +155,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
/// implements but not . null otherwise i.e. when
/// is false.
///
- public abstract ModelMetadata ElementMetadata { get; }
+ public abstract ModelMetadata? ElementMetadata { get; }
///
/// Gets the ordered and grouped display names and values of all values in
@@ -318,7 +318,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
/// validated. If null, properties with this are validated.
///
/// Defaults to null.
- public virtual IPropertyValidationFilter PropertyValidationFilter => null;
+ public virtual IPropertyValidationFilter? PropertyValidationFilter => null;
///
/// Gets a value that indicates whether properties or elements of the model should be validated.
@@ -343,7 +343,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
/// Gets the for elements of if that
/// implements .
///
- public Type ElementType { get; private set; }
+ public Type? ElementType { get; private set; }
///
/// Gets a value indicating whether is a complex type.
@@ -389,7 +389,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
///
/// Identical to unless is true.
///
- public Type UnderlyingOrModelType { get; private set; }
+ public Type UnderlyingOrModelType { get; private set; } = default!;
///
/// Gets a property getter delegate to get the property value from a model object.
@@ -415,7 +415,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
}
///
- public bool Equals(ModelMetadata other)
+ public bool Equals(ModelMetadata? other)
{
if (object.ReferenceEquals(this, other))
{
@@ -433,7 +433,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
}
///
- public override bool Equals(object obj)
+ public override bool Equals(object? obj)
{
return Equals(obj as ModelMetadata);
}
@@ -469,14 +469,14 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
else if (ModelType.IsArray)
{
IsEnumerableType = true;
- ElementType = ModelType.GetElementType();
+ ElementType = ModelType.GetElementType()!;
}
else
{
IsEnumerableType = true;
var enumerableType = ClosedGenericMatcher.ExtractGenericInterface(ModelType, typeof(IEnumerable<>));
- ElementType = enumerableType?.GenericTypeArguments[0];
+ ElementType = enumerableType?.GenericTypeArguments[0]!;
if (ElementType == null)
{
@@ -497,7 +497,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
case ModelMetadataKind.Parameter:
return $"ModelMetadata (Parameter: '{ParameterName}' Type: '{ModelType.Name}')";
case ModelMetadataKind.Property:
- return $"ModelMetadata (Property: '{ContainerType.Name}.{PropertyName}' Type: '{ModelType.Name}')";
+ return $"ModelMetadata (Property: '{ContainerType!.Name}.{PropertyName}' Type: '{ModelType.Name}')";
case ModelMetadataKind.Type:
return $"ModelMetadata (Type: '{ModelType.Name}')";
default:
diff --git a/src/Mvc/Mvc.Abstractions/src/ModelBinding/ModelPropertyCollection.cs b/src/Mvc/Mvc.Abstractions/src/ModelBinding/ModelPropertyCollection.cs
index 733da709ba..797e1b9514 100644
--- a/src/Mvc/Mvc.Abstractions/src/ModelBinding/ModelPropertyCollection.cs
+++ b/src/Mvc/Mvc.Abstractions/src/ModelBinding/ModelPropertyCollection.cs
@@ -32,7 +32,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
/// The instance for the property specified by , or
/// null if no match can be found.
///
- public ModelMetadata this[string propertyName]
+ public ModelMetadata? this[string propertyName]
{
get
{
diff --git a/src/Mvc/Mvc.Abstractions/src/ModelBinding/ModelStateDictionary.cs b/src/Mvc/Mvc.Abstractions/src/ModelBinding/ModelStateDictionary.cs
index 48b8b9ee3a..24581e0510 100644
--- a/src/Mvc/Mvc.Abstractions/src/ModelBinding/ModelStateDictionary.cs
+++ b/src/Mvc/Mvc.Abstractions/src/ModelBinding/ModelStateDictionary.cs
@@ -5,6 +5,7 @@ using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
+using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Mvc.Formatters;
@@ -166,7 +167,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
}
TryGetValue(key, out var entry);
- return entry;
+ return entry!;
}
}
@@ -305,15 +306,15 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
}
else if (entry == null)
{
- errorMessage = messageProvider.UnknownValueIsInvalidAccessor(name);
+ errorMessage = messageProvider.UnknownValueIsInvalidAccessor(name!);
}
else if (name == null)
{
- errorMessage = messageProvider.NonPropertyAttemptedValueIsInvalidAccessor(entry.AttemptedValue);
+ errorMessage = messageProvider.NonPropertyAttemptedValueIsInvalidAccessor(entry.AttemptedValue!);
}
else
{
- errorMessage = messageProvider.AttemptedValueIsInvalidAccessor(entry.AttemptedValue, name);
+ errorMessage = messageProvider.AttemptedValueIsInvalidAccessor(entry.AttemptedValue!, name);
}
return TryAddModelError(key, errorMessage);
@@ -511,7 +512,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
///
/// The values of in a comma-separated .
///
- public void SetModelValue(string key, object rawValue, string attemptedValue)
+ public void SetModelValue(string key, object? rawValue, string attemptedValue)
{
if (key == null)
{
@@ -540,7 +541,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
}
// Avoid creating a new array for rawValue if there's only one value.
- object rawValue;
+ object? rawValue;
if (valueProviderResult == ValueProviderResult.None)
{
rawValue = null;
@@ -573,10 +574,8 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
}
}
- private ModelStateNode GetNode(string key)
+ private ModelStateNode? GetNode(string key)
{
- Debug.Assert(key != null);
-
var current = _root;
if (key.Length > 0)
{
@@ -661,7 +660,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
return new StringSegment(key, keyStart, index - keyStart);
}
- private static ModelValidationState? GetValidity(ModelStateNode node)
+ private static ModelValidationState? GetValidity(ModelStateNode? node)
{
if (node == null)
{
@@ -774,7 +773,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
}
///
- public bool TryGetValue(string key, out ModelStateEntry value)
+ public bool TryGetValue(string key, [NotNullWhen(true)] out ModelStateEntry? value)
{
if (key == null)
{
@@ -893,11 +892,11 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
SubKey = subKey;
}
- public List ChildNodes { get; set; }
+ public List? ChildNodes { get; set; }
- public override IReadOnlyList Children => ChildNodes;
+ public override IReadOnlyList? Children => ChildNodes;
- public string Key { get; set; }
+ public string Key { get; set; } = default!;
public StringSegment SubKey { get; }
@@ -931,9 +930,9 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public ModelStateNode GetNode(StringSegment subKey)
+ public ModelStateNode? GetNode(StringSegment subKey)
{
- ModelStateNode modelStateNode = null;
+ ModelStateNode? modelStateNode = null;
if (subKey.Length == 0)
{
modelStateNode = this;
@@ -981,7 +980,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
return modelStateNode;
}
- public override ModelStateEntry GetModelStateForProperty(string propertyName)
+ public override ModelStateEntry? GetModelStateForProperty(string propertyName)
=> GetNode(new StringSegment(propertyName));
private int BinarySearch(StringSegment searchKey)
@@ -1068,9 +1067,9 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
///
public struct Enumerator : IEnumerator>
{
- private readonly ModelStateNode _rootNode;
+ private readonly ModelStateNode? _rootNode;
private ModelStateNode _modelStateNode;
- private List _nodes;
+ private List? _nodes;
private int _index;
private bool _visitedRoot;
@@ -1093,7 +1092,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
_index = -1;
_rootNode = dictionary.GetNode(prefix);
- _modelStateNode = null;
+ _modelStateNode = default!;
_nodes = null;
_visitedRoot = false;
}
@@ -1141,7 +1140,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
while (_nodes.Count > 0)
{
var node = _nodes[0];
- if (_index == node.ChildNodes.Count - 1)
+ if (_index == node.ChildNodes!.Count - 1)
{
// We've exhausted the current sublist.
_nodes.RemoveAt(0);
@@ -1173,9 +1172,9 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
public void Reset()
{
_index = -1;
- _nodes.Clear();
+ _nodes?.Clear();
_visitedRoot = false;
- _modelStateNode = null;
+ _modelStateNode = default!;
}
}
@@ -1218,7 +1217,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
public KeyEnumerator(ModelStateDictionary dictionary, string prefix)
{
_prefixEnumerator = new Enumerator(dictionary, prefix);
- Current = null;
+ Current = default!;
}
///
@@ -1240,7 +1239,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
}
else
{
- Current = null;
+ Current = default!;
}
return result;
@@ -1250,7 +1249,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
public void Reset()
{
_prefixEnumerator.Reset();
- Current = null;
+ Current = default!;
}
}
@@ -1293,7 +1292,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
public ValueEnumerator(ModelStateDictionary dictionary, string prefix)
{
_prefixEnumerator = new Enumerator(dictionary, prefix);
- Current = null;
+ Current = default!;
}
///
@@ -1315,7 +1314,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
}
else
{
- Current = null;
+ Current = default!;
}
return result;
@@ -1325,7 +1324,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
public void Reset()
{
_prefixEnumerator.Reset();
- Current = null;
+ Current = default!;
}
}
}
diff --git a/src/Mvc/Mvc.Abstractions/src/ModelBinding/ModelStateEntry.cs b/src/Mvc/Mvc.Abstractions/src/ModelBinding/ModelStateEntry.cs
index b73eab4f77..d56ef3dd81 100644
--- a/src/Mvc/Mvc.Abstractions/src/ModelBinding/ModelStateEntry.cs
+++ b/src/Mvc/Mvc.Abstractions/src/ModelBinding/ModelStateEntry.cs
@@ -10,17 +10,17 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
///
public abstract class ModelStateEntry
{
- private ModelErrorCollection _errors;
+ private ModelErrorCollection? _errors;
///
/// Gets the raw value from the request associated with this entry.
///
- public object RawValue { get; set; }
+ public object? RawValue { get; set; }
///
/// Gets the set of values contained in , joined into a comma-separated string.
///
- public string AttemptedValue { get; set; }
+ public string? AttemptedValue { get; set; }
///
/// Gets the for this entry.
@@ -61,7 +61,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
/// This method returns any existing entry, even those with with value
/// .
///
- public abstract ModelStateEntry GetModelStateForProperty(string propertyName);
+ public abstract ModelStateEntry? GetModelStateForProperty(string propertyName);
///
/// Gets the values for sub-properties.
@@ -70,6 +70,6 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
/// This property returns all existing entries, even those with with value
/// .
///
- public abstract IReadOnlyList Children { get; }
+ public abstract IReadOnlyList? Children { get; }
}
}
diff --git a/src/Mvc/Mvc.Abstractions/src/ModelBinding/Validation/ClientValidatorItem.cs b/src/Mvc/Mvc.Abstractions/src/ModelBinding/Validation/ClientValidatorItem.cs
index e346509701..be8552d8df 100644
--- a/src/Mvc/Mvc.Abstractions/src/ModelBinding/Validation/ClientValidatorItem.cs
+++ b/src/Mvc/Mvc.Abstractions/src/ModelBinding/Validation/ClientValidatorItem.cs
@@ -30,12 +30,12 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Validation
///
/// Gets the metadata associated with the .
///
- public object ValidatorMetadata { get; }
+ public object ValidatorMetadata { get; } = default!;
///
/// Gets or sets the .
///
- public IClientModelValidator Validator { get; set; }
+ public IClientModelValidator Validator { get; set; } = default!;
///
/// Gets or sets a value indicating whether or not can be reused across requests.
diff --git a/src/Mvc/Mvc.Abstractions/src/ModelBinding/Validation/ValidationEntry.cs b/src/Mvc/Mvc.Abstractions/src/ModelBinding/Validation/ValidationEntry.cs
index a873273ca7..cedca096a4 100644
--- a/src/Mvc/Mvc.Abstractions/src/ModelBinding/Validation/ValidationEntry.cs
+++ b/src/Mvc/Mvc.Abstractions/src/ModelBinding/Validation/ValidationEntry.cs
@@ -10,8 +10,8 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Validation
///
public struct ValidationEntry
{
- private object _model;
- private Func _modelAccessor;
+ private object? _model;
+ private Func? _modelAccessor;
///
/// Creates a new .
@@ -79,7 +79,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Validation
///
/// The model object.
///
- public object Model
+ public object? Model
{
get
{
diff --git a/src/Mvc/Mvc.Abstractions/src/ModelBinding/Validation/ValidationStateDictionary.cs b/src/Mvc/Mvc.Abstractions/src/ModelBinding/Validation/ValidationStateDictionary.cs
index 11179b014d..2d40811d5c 100644
--- a/src/Mvc/Mvc.Abstractions/src/ModelBinding/Validation/ValidationStateDictionary.cs
+++ b/src/Mvc/Mvc.Abstractions/src/ModelBinding/Validation/ValidationStateDictionary.cs
@@ -4,7 +4,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
-using System.Runtime.CompilerServices;
+using System.Diagnostics.CodeAnalysis;
namespace Microsoft.AspNetCore.Mvc.ModelBinding.Validation
{
@@ -25,8 +25,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Validation
_inner = new Dictionary(ReferenceEqualityComparer.Instance);
}
- ///
- public ValidationStateEntry this[object key]
+ public ValidationStateEntry? this[object key]
{
get
{
@@ -36,10 +35,19 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Validation
set
{
- _inner[key] = value;
+ _inner[key] = value!;
}
}
+ ///
+ ValidationStateEntry IDictionary.this[object key]
+ {
+ get => this[key]!;
+ set => this[key] = value;
+ }
+
+ ValidationStateEntry IReadOnlyDictionary.this[object key] => this[key]!;
+
///
public int Count => _inner.Count;
@@ -115,7 +123,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Validation
}
///
- public bool TryGetValue(object key, out ValidationStateEntry value)
+ public bool TryGetValue(object key, [MaybeNullWhen(false)] out ValidationStateEntry value)
{
return _inner.TryGetValue(key, out value);
}
@@ -125,30 +133,5 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Validation
{
return ((IDictionary)_inner).GetEnumerator();
}
-
- private class ReferenceEqualityComparer : IEqualityComparer
- {
- private static readonly bool IsMono = Type.GetType("Mono.Runtime") != null;
-
- public static readonly ReferenceEqualityComparer Instance = new ReferenceEqualityComparer();
-
- public new bool Equals(object x, object y)
- {
- return Object.ReferenceEquals(x, y);
- }
-
- public int GetHashCode(object obj)
- {
- // RuntimeHelpers.GetHashCode sometimes crashes the runtime on Mono 4.0.4
- // See: https://github.com/aspnet/External/issues/45
- // The workaround here is to just not hash anything, and fall back to an equality check.
- if (IsMono)
- {
- return 0;
- }
-
- return RuntimeHelpers.GetHashCode(obj);
- }
- }
}
}
\ No newline at end of file
diff --git a/src/Mvc/Mvc.Abstractions/src/ModelBinding/Validation/ValidationStateEntry.cs b/src/Mvc/Mvc.Abstractions/src/ModelBinding/Validation/ValidationStateEntry.cs
index 970cbb8dfa..ee94334283 100644
--- a/src/Mvc/Mvc.Abstractions/src/ModelBinding/Validation/ValidationStateEntry.cs
+++ b/src/Mvc/Mvc.Abstractions/src/ModelBinding/Validation/ValidationStateEntry.cs
@@ -12,12 +12,12 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Validation
///
/// Gets or sets the model prefix associated with the entry.
///
- public string Key { get; set; }
+ public string Key { get; set; } = default!;
///
/// Gets or sets the associated with the entry.
///
- public ModelMetadata Metadata { get; set; }
+ public ModelMetadata Metadata { get; set; } = default!;
///
/// Gets or sets a value indicating whether the associated model object should be validated.
@@ -28,6 +28,6 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Validation
/// Gets or sets an for enumerating child entries of the associated
/// model object.
///
- public IValidationStrategy Strategy { get; set; }
+ public IValidationStrategy Strategy { get; set; } = default!;
}
}
diff --git a/src/Mvc/Mvc.Abstractions/src/ModelBinding/Validation/ValidatorItem.cs b/src/Mvc/Mvc.Abstractions/src/ModelBinding/Validation/ValidatorItem.cs
index 8592eeca71..ca8b291e1a 100644
--- a/src/Mvc/Mvc.Abstractions/src/ModelBinding/Validation/ValidatorItem.cs
+++ b/src/Mvc/Mvc.Abstractions/src/ModelBinding/Validation/ValidatorItem.cs
@@ -30,12 +30,12 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Validation
///
/// Gets the metadata associated with the .
///
- public object ValidatorMetadata { get; }
+ public object ValidatorMetadata { get; } = default!;
///
/// Gets or sets the .
///
- public IModelValidator Validator { get; set; }
+ public IModelValidator Validator { get; set; } = default!;
///
/// Gets or sets a value indicating whether or not can be reused across requests.
diff --git a/src/Mvc/Mvc.Abstractions/src/ModelBinding/ValueProviderResult.cs b/src/Mvc/Mvc.Abstractions/src/ModelBinding/ValueProviderResult.cs
index 3a0b8e1fa8..e5b088b4a0 100644
--- a/src/Mvc/Mvc.Abstractions/src/ModelBinding/ValueProviderResult.cs
+++ b/src/Mvc/Mvc.Abstractions/src/ModelBinding/ValueProviderResult.cs
@@ -69,7 +69,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
/// to get a single value for processing regardless of whether a single or multiple values were provided
/// in the request.
///
- public string FirstValue
+ public string? FirstValue
{
get
{
@@ -87,7 +87,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
public int Length => Values.Count;
///
- public override bool Equals(object obj)
+ public override bool Equals(object? obj)
{
var other = obj as ValueProviderResult?;
return other.HasValue && Equals(other.Value);
diff --git a/src/Mvc/Mvc.Abstractions/src/Routing/AttributeRouteInfo.cs b/src/Mvc/Mvc.Abstractions/src/Routing/AttributeRouteInfo.cs
index f2fc4ea77b..1aae06847e 100644
--- a/src/Mvc/Mvc.Abstractions/src/Routing/AttributeRouteInfo.cs
+++ b/src/Mvc/Mvc.Abstractions/src/Routing/AttributeRouteInfo.cs
@@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Mvc.Routing
///
/// The route template. May be null if the action has no attribute routes.
///
- public string Template { get; set; }
+ public string? Template { get; set; }
///
/// Gets the order of the route associated with a given action. This property determines
@@ -27,7 +27,7 @@ namespace Microsoft.AspNetCore.Mvc.Routing
/// to generate a link by referring to the route by name instead of attempting to match a
/// route by provided route data.
///
- public string Name { get; set; }
+ public string Name { get; set; } = default!;
///
/// Gets or sets a value that determines if the route entry associated with this model participates in link generation.
diff --git a/src/Mvc/Mvc.Abstractions/src/Routing/UrlActionContext.cs b/src/Mvc/Mvc.Abstractions/src/Routing/UrlActionContext.cs
index 8260b6b680..09853000d0 100644
--- a/src/Mvc/Mvc.Abstractions/src/Routing/UrlActionContext.cs
+++ b/src/Mvc/Mvc.Abstractions/src/Routing/UrlActionContext.cs
@@ -11,7 +11,7 @@ namespace Microsoft.AspNetCore.Mvc.Routing
///
/// The name of the action method that uses to generate URLs.
///
- public string Action
+ public string? Action
{
get;
set;
@@ -20,7 +20,7 @@ namespace Microsoft.AspNetCore.Mvc.Routing
///
/// The name of the controller that uses to generate URLs.
///
- public string Controller
+ public string? Controller
{
get;
set;
@@ -30,7 +30,7 @@ namespace Microsoft.AspNetCore.Mvc.Routing
/// The object that contains the route values that
/// uses to generate URLs.
///
- public object Values
+ public object? Values
{
get;
set;
@@ -40,7 +40,7 @@ namespace Microsoft.AspNetCore.Mvc.Routing
/// The protocol for the URLs that generates,
/// such as "http" or "https"
///
- public string Protocol
+ public string? Protocol
{
get;
set;
@@ -49,7 +49,7 @@ namespace Microsoft.AspNetCore.Mvc.Routing
///
/// The host name for the URLs that generates.
///
- public string Host
+ public string? Host
{
get;
set;
@@ -58,7 +58,7 @@ namespace Microsoft.AspNetCore.Mvc.Routing
///
/// The fragment for the URLs that generates.
///
- public string Fragment
+ public string? Fragment
{
get;
set;
diff --git a/src/Mvc/Mvc.Abstractions/src/Routing/UrlRouteContext.cs b/src/Mvc/Mvc.Abstractions/src/Routing/UrlRouteContext.cs
index 706414f958..d713e69212 100644
--- a/src/Mvc/Mvc.Abstractions/src/Routing/UrlRouteContext.cs
+++ b/src/Mvc/Mvc.Abstractions/src/Routing/UrlRouteContext.cs
@@ -11,7 +11,7 @@ namespace Microsoft.AspNetCore.Mvc.Routing
///
/// The name of the route that uses to generate URLs.
///
- public string RouteName
+ public string? RouteName
{
get;
set;
@@ -21,7 +21,7 @@ namespace Microsoft.AspNetCore.Mvc.Routing
/// The object that contains the route values that
/// uses to generate URLs.
///
- public object Values
+ public object? Values
{
get;
set;
@@ -31,7 +31,7 @@ namespace Microsoft.AspNetCore.Mvc.Routing
/// The protocol for the URLs that generates,
/// such as "http" or "https"
///
- public string Protocol
+ public string? Protocol
{
get;
set;
@@ -40,7 +40,7 @@ namespace Microsoft.AspNetCore.Mvc.Routing
///
/// The host name for the URLs that generates.
///
- public string Host
+ public string? Host
{
get;
set;
@@ -49,7 +49,7 @@ namespace Microsoft.AspNetCore.Mvc.Routing
///
/// The fragment for the URLs that generates.
///
- public string Fragment
+ public string? Fragment
{
get;
set;
diff --git a/src/Mvc/Mvc.ApiExplorer/src/DefaultApiDescriptionProvider.cs b/src/Mvc/Mvc.ApiExplorer/src/DefaultApiDescriptionProvider.cs
index bbc1f86ef1..73a4c35492 100644
--- a/src/Mvc/Mvc.ApiExplorer/src/DefaultApiDescriptionProvider.cs
+++ b/src/Mvc/Mvc.ApiExplorer/src/DefaultApiDescriptionProvider.cs
@@ -662,11 +662,11 @@ namespace Microsoft.AspNetCore.Mvc.ApiExplorer
public int GetHashCode(PropertyKey obj)
{
- var hashCodeCombiner = HashCodeCombiner.Start();
+ var hashCodeCombiner = new HashCode();
hashCodeCombiner.Add(obj.ContainerType);
hashCodeCombiner.Add(obj.PropertyName);
hashCodeCombiner.Add(obj.Source);
- return hashCodeCombiner.CombinedHash;
+ return hashCodeCombiner.ToHashCode();
}
}
}
diff --git a/src/Mvc/Mvc.Core/src/ModelBinding/ModelBinderFactory.cs b/src/Mvc/Mvc.Core/src/ModelBinding/ModelBinderFactory.cs
index 1cd59d4c72..180fb433e1 100644
--- a/src/Mvc/Mvc.Core/src/ModelBinding/ModelBinderFactory.cs
+++ b/src/Mvc/Mvc.Core/src/ModelBinding/ModelBinderFactory.cs
@@ -319,10 +319,10 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
public override int GetHashCode()
{
- var hash = new HashCodeCombiner();
+ var hash = new HashCode();
hash.Add(_metadata);
hash.Add(RuntimeHelpers.GetHashCode(_token));
- return hash;
+ return hash.ToHashCode();
}
public override string ToString()
diff --git a/src/Mvc/Mvc.Core/src/Routing/AttributeRoute.cs b/src/Mvc/Mvc.Core/src/Routing/AttributeRoute.cs
index da0fc4594e..185e77fb58 100644
--- a/src/Mvc/Mvc.Core/src/Routing/AttributeRoute.cs
+++ b/src/Mvc/Mvc.Core/src/Routing/AttributeRoute.cs
@@ -291,10 +291,10 @@ namespace Microsoft.AspNetCore.Mvc.Routing
return 0;
}
- var hash = new HashCodeCombiner();
+ var hash = new HashCode();
hash.Add(obj.Order);
hash.Add(obj.RouteTemplate.TemplateText, StringComparer.OrdinalIgnoreCase);
- return hash;
+ return hash.ToHashCode();
}
}
diff --git a/src/Mvc/Mvc.Razor/src/RazorPageActivator.cs b/src/Mvc/Mvc.Razor/src/RazorPageActivator.cs
index 9acc858e5a..49eb5c05a9 100644
--- a/src/Mvc/Mvc.Razor/src/RazorPageActivator.cs
+++ b/src/Mvc/Mvc.Razor/src/RazorPageActivator.cs
@@ -123,14 +123,14 @@ namespace Microsoft.AspNetCore.Mvc.Razor
public override int GetHashCode()
{
- var hashCodeCombiner = HashCodeCombiner.Start();
+ var hashCodeCombiner = new HashCode();
hashCodeCombiner.Add(PageType);
if (ProvidedModelType != null)
{
hashCodeCombiner.Add(ProvidedModelType);
}
- return hashCodeCombiner.CombinedHash;
+ return hashCodeCombiner.ToHashCode();
}
}
}
diff --git a/src/Mvc/Mvc.Razor/src/ViewLocationCacheKey.cs b/src/Mvc/Mvc.Razor/src/ViewLocationCacheKey.cs
index 2640110dd5..140b55ba9e 100644
--- a/src/Mvc/Mvc.Razor/src/ViewLocationCacheKey.cs
+++ b/src/Mvc/Mvc.Razor/src/ViewLocationCacheKey.cs
@@ -135,7 +135,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor
///
public override int GetHashCode()
{
- var hashCodeCombiner = HashCodeCombiner.Start();
+ var hashCodeCombiner = new HashCode();
hashCodeCombiner.Add(IsMainPage ? 1 : 0);
hashCodeCombiner.Add(ViewName, StringComparer.Ordinal);
hashCodeCombiner.Add(ControllerName, StringComparer.Ordinal);
@@ -151,7 +151,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor
}
}
- return hashCodeCombiner;
+ return hashCodeCombiner.ToHashCode();
}
}
}
diff --git a/src/Mvc/Mvc.TagHelpers/src/Cache/CacheTagKey.cs b/src/Mvc/Mvc.TagHelpers/src/Cache/CacheTagKey.cs
index bf327f30ca..f527f8f55f 100644
--- a/src/Mvc/Mvc.TagHelpers/src/Cache/CacheTagKey.cs
+++ b/src/Mvc/Mvc.TagHelpers/src/Cache/CacheTagKey.cs
@@ -247,7 +247,7 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers.Cache
return _hashcode.Value;
}
- var hashCodeCombiner = new HashCodeCombiner();
+ var hashCodeCombiner = new HashCode();
hashCodeCombiner.Add(Key, StringComparer.Ordinal);
hashCodeCombiner.Add(_expiresAfter);
@@ -258,12 +258,12 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers.Cache
hashCodeCombiner.Add(_requestCulture);
hashCodeCombiner.Add(_requestUICulture);
- CombineCollectionHashCode(hashCodeCombiner, VaryByCookieName, _cookies);
- CombineCollectionHashCode(hashCodeCombiner, VaryByHeaderName, _headers);
- CombineCollectionHashCode(hashCodeCombiner, VaryByQueryName, _queries);
- CombineCollectionHashCode(hashCodeCombiner, VaryByRouteName, _routeValues);
+ CombineCollectionHashCode(ref hashCodeCombiner, VaryByCookieName, _cookies);
+ CombineCollectionHashCode(ref hashCodeCombiner, VaryByHeaderName, _headers);
+ CombineCollectionHashCode(ref hashCodeCombiner, VaryByQueryName, _queries);
+ CombineCollectionHashCode(ref hashCodeCombiner, VaryByRouteName, _routeValues);
- _hashcode = hashCodeCombiner.CombinedHash;
+ _hashcode = hashCodeCombiner.ToHashCode();
return _hashcode.Value;
}
@@ -331,7 +331,7 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers.Cache
}
private static void CombineCollectionHashCode(
- HashCodeCombiner hashCodeCombiner,
+ ref HashCode hashCodeCombiner,
string collectionName,
IList> values)
{
diff --git a/src/Mvc/Mvc.TagHelpers/src/GlobbingUrlBuilder.cs b/src/Mvc/Mvc.TagHelpers/src/GlobbingUrlBuilder.cs
index 82c176bc8b..e0a04a5374 100644
--- a/src/Mvc/Mvc.TagHelpers/src/GlobbingUrlBuilder.cs
+++ b/src/Mvc/Mvc.TagHelpers/src/GlobbingUrlBuilder.cs
@@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
+using System.Security.Policy;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.FileProviders;
@@ -373,11 +374,11 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers
public override int GetHashCode()
{
- var hashCodeCombiner = HashCodeCombiner.Start();
+ var hashCodeCombiner = new HashCode();
hashCodeCombiner.Add(Include);
hashCodeCombiner.Add(Exclude);
- return hashCodeCombiner.CombinedHash;
+ return hashCodeCombiner.ToHashCode();
}
}
}
diff --git a/src/Mvc/Mvc.ViewFeatures/src/LambdaExpressionComparer.cs b/src/Mvc/Mvc.ViewFeatures/src/LambdaExpressionComparer.cs
index 1e0dcc7fe7..e3448c15c0 100644
--- a/src/Mvc/Mvc.ViewFeatures/src/LambdaExpressionComparer.cs
+++ b/src/Mvc/Mvc.ViewFeatures/src/LambdaExpressionComparer.cs
@@ -84,7 +84,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
public int GetHashCode(LambdaExpression lambdaExpression)
{
var expression = lambdaExpression.Body;
- var hashCodeCombiner = HashCodeCombiner.Start();
+ var hashCodeCombiner = new HashCode();
while (true)
{
@@ -107,7 +107,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
}
}
- return hashCodeCombiner.CombinedHash;
+ return hashCodeCombiner.ToHashCode();
}
}
}
diff --git a/src/Mvc/Mvc.ViewFeatures/src/MemberExpressionCacheKeyComparer.cs b/src/Mvc/Mvc.ViewFeatures/src/MemberExpressionCacheKeyComparer.cs
index 5911611c89..b1586e71ba 100644
--- a/src/Mvc/Mvc.ViewFeatures/src/MemberExpressionCacheKeyComparer.cs
+++ b/src/Mvc/Mvc.ViewFeatures/src/MemberExpressionCacheKeyComparer.cs
@@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
+using System;
using System.Collections.Generic;
using Microsoft.Extensions.Internal;
@@ -39,7 +40,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
public int GetHashCode(MemberExpressionCacheKey obj)
{
- var hashCodeCombiner = new HashCodeCombiner();
+ var hashCodeCombiner = new HashCode();
hashCodeCombiner.Add(obj.ModelType);
foreach (var member in obj)
@@ -47,7 +48,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
hashCodeCombiner.Add(member);
}
- return hashCodeCombiner.CombinedHash;
+ return hashCodeCombiner.ToHashCode();
}
}
}
diff --git a/src/Shared/ClosedGenericMatcher/ClosedGenericMatcher.cs b/src/Shared/ClosedGenericMatcher/ClosedGenericMatcher.cs
index f234c2edbc..fc41de2069 100644
--- a/src/Shared/ClosedGenericMatcher/ClosedGenericMatcher.cs
+++ b/src/Shared/ClosedGenericMatcher/ClosedGenericMatcher.cs
@@ -1,8 +1,9 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
+#nullable enable
+
using System;
-using System.Linq;
using System.Reflection;
namespace Microsoft.Extensions.Internal
@@ -28,7 +29,7 @@ namespace Microsoft.Extensions.Internal
/// typeof(KeyValuePair{,}), and is
/// typeof(KeyValuePair{string, object}).
///
- public static Type ExtractGenericInterface(Type queryType, Type interfaceType)
+ public static Type? ExtractGenericInterface(Type queryType, Type interfaceType)
{
if (queryType == null)
{
@@ -62,9 +63,9 @@ namespace Microsoft.Extensions.Internal
candidate.GetGenericTypeDefinition() == interfaceType;
}
- private static Type GetGenericInstantiation(Type queryType, Type interfaceType)
+ private static Type? GetGenericInstantiation(Type queryType, Type interfaceType)
{
- Type bestMatch = null;
+ Type? bestMatch = null;
var interfaces = queryType.GetInterfaces();
foreach (var @interface in interfaces)
{
@@ -103,4 +104,4 @@ namespace Microsoft.Extensions.Internal
}
}
}
-}
\ No newline at end of file
+}