From f37fa30683a92d83297434103a43b3d46aaa93a9 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Fri, 5 Jun 2020 06:54:07 -0700 Subject: [PATCH] Add nullable annotations to Http.Abstractions, Http.Features, Connections.Abstractions (#22337) * Add nullable annotations to Http.Abstractions, Http.Features, Connections.Abstractions Co-authored-by: James Newton-King --- .../ref/Microsoft.Net.Http.Headers.csproj | 1 + .../Microsoft.Net.Http.Headers.netcoreapp.cs | 114 +++--- src/Http/Headers/src/BaseHeaderParser.cs | 7 +- .../Headers/src/CacheControlHeaderValue.cs | 33 +- .../src/ContentDispositionHeaderValue.cs | 38 +- .../Headers/src/ContentRangeHeaderValue.cs | 15 +- src/Http/Headers/src/CookieHeaderParser.cs | 6 +- src/Http/Headers/src/CookieHeaderValue.cs | 20 +- src/Http/Headers/src/EntityTagHeaderValue.cs | 27 +- src/Http/Headers/src/GenericHeaderParser.cs | 5 +- src/Http/Headers/src/HeaderUtilities.cs | 11 +- src/Http/Headers/src/HttpHeaderParser.cs | 26 +- src/Http/Headers/src/HttpRuleParser.cs | 4 - src/Http/Headers/src/MediaTypeHeaderValue.cs | 33 +- .../src/MediaTypeHeaderValueComparer.cs | 20 +- .../src/Microsoft.Net.Http.Headers.csproj | 1 + src/Http/Headers/src/NameValueHeaderValue.cs | 42 +-- src/Http/Headers/src/ObjectCollection.cs | 4 +- .../Headers/src/RangeConditionHeaderValue.cs | 25 +- src/Http/Headers/src/RangeHeaderValue.cs | 15 +- src/Http/Headers/src/RangeItemHeaderValue.cs | 9 +- src/Http/Headers/src/SetCookieHeaderValue.cs | 27 +- .../src/StringWithQualityHeaderValue.cs | 23 +- .../StringWithQualityHeaderValueComparer.cs | 12 +- .../test/CacheControlHeaderValueTest.cs | 20 +- .../test/ContentDispositionHeaderValueTest.cs | 18 +- .../test/ContentRangeHeaderValueTest.cs | 19 +- .../Headers/test/CookieHeaderValueTest.cs | 12 +- src/Http/Headers/test/DateParserTest.cs | 4 +- .../Headers/test/EntityTagHeaderValueTest.cs | 31 +- .../Headers/test/MediaTypeHeaderValueTest.cs | 37 +- .../Microsoft.Net.Http.Headers.Tests.csproj | 1 + .../Headers/test/NameValueHeaderValueTest.cs | 32 +- .../test/RangeConditionHeaderValueTest.cs | 12 +- src/Http/Headers/test/RangeHeaderValueTest.cs | 16 +- .../Headers/test/RangeItemHeaderValueTest.cs | 2 +- .../Headers/test/SetCookieHeaderValueTest.cs | 16 +- .../test/StringWithQualityHeaderValueTest.cs | 26 +- ...rosoft.AspNetCore.Http.Abstractions.csproj | 1 + ...AspNetCore.Http.Abstractions.netcoreapp.cs | 94 ++--- .../Http.Abstractions/src/CookieBuilder.cs | 8 +- .../src/Extensions/EndpointBuilder.cs | 4 +- .../src/Extensions/MapExtensions.cs | 2 +- .../src/Extensions/MapMiddleware.cs | 7 +- .../src/Extensions/MapOptions.cs | 2 +- .../src/Extensions/MapWhenMiddleware.cs | 16 +- .../src/Extensions/MapWhenOptions.cs | 8 +- .../src/Extensions/UseMiddlewareExtensions.cs | 6 +- .../Http.Abstractions/src/FragmentString.cs | 2 +- src/Http/Http.Abstractions/src/HostString.cs | 2 +- src/Http/Http.Abstractions/src/HttpContext.cs | 4 +- src/Http/Http.Abstractions/src/HttpRequest.cs | 2 +- .../src/IMiddlewareFactory.cs | 6 +- .../src/Internal/HeaderSegment.cs | 2 +- .../src/Internal/HeaderSegmentCollection.cs | 2 +- ...rosoft.AspNetCore.Http.Abstractions.csproj | 6 +- src/Http/Http.Abstractions/src/PathString.cs | 26 +- src/Http/Http.Abstractions/src/QueryString.cs | 41 +-- .../Http.Abstractions/src/Routing/Endpoint.cs | 4 +- .../Routing/EndpointHttpContextExtensions.cs | 6 +- .../src/Routing/EndpointMetadataCollection.cs | 10 +- .../src/Routing/IEndpointFeature.cs | 4 +- .../src/Routing/RouteValueDictionary.cs | 99 ++--- .../Http.Abstractions/src/WebSocketManager.cs | 2 +- .../EndpointHttpContextExtensionsTests.cs | 2 +- .../test/MapPathMiddlewareTests.cs | 10 +- .../test/MapPredicateMiddlewareTests.cs | 15 +- ....AspNetCore.Http.Abstractions.Tests.csproj | 1 + .../test/QueryStringTests.cs | 10 +- .../test/RouteValueDictionaryTests.cs | 348 +++++++++--------- .../test/UseMiddlewareTest.cs | 14 +- .../test/UsePathBaseExtensionsTests.cs | 5 +- .../test/UseWhenExtensionsTests.cs | 6 +- .../Microsoft.AspNetCore.Http.Features.csproj | 1 + ...oft.AspNetCore.Http.Features.netcoreapp.cs | 18 +- ...AspNetCore.Http.Features.netstandard2.0.cs | 10 +- src/Http/Http.Features/src/CookieOptions.cs | 4 +- .../Http.Features/src/FeatureCollection.cs | 12 +- .../Http.Features/src/FeatureReference.cs | 9 +- .../Http.Features/src/FeatureReferences.cs | 12 +- .../Http.Features/src/IFeatureCollection.cs | 2 +- .../Microsoft.AspNetCore.Http.Features.csproj | 4 +- .../src/WebSocketAcceptContext.cs | 4 +- .../test/FeatureCollectionTests.cs | 4 +- ...soft.AspNetCore.Http.Features.Tests.csproj | 1 + .../Microsoft.AspNetCore.Http.netcoreapp.cs | 8 +- src/Http/HttpAbstractions.sln | 17 + .../ref/Microsoft.AspNetCore.Metadata.csproj | 1 + ...icrosoft.AspNetCore.Metadata.netcoreapp.cs | 6 +- ...soft.AspNetCore.Metadata.netstandard2.0.cs | 6 +- src/Http/Metadata/src/IAuthorizeData.cs | 6 +- .../src/Microsoft.AspNetCore.Metadata.csproj | 1 + ...oft.AspNetCore.Routing.Abstractions.csproj | 1 + ...NetCore.Routing.Abstractions.netcoreapp.cs | 16 +- .../Routing.Abstractions/src/LinkGenerator.cs | 16 +- ...oft.AspNetCore.Routing.Abstractions.csproj | 3 +- .../Routing.Abstractions/src/RouteContext.cs | 4 +- .../src/RoutingHttpContextExtensions.cs | 2 +- .../src/VirtualPathContext.cs | 4 +- .../ref/Microsoft.AspNetCore.Routing.csproj | 1 + .../src/Microsoft.AspNetCore.Routing.csproj | 1 + ...AspNetCore.Connections.Abstractions.csproj | 1 + ...ore.Connections.Abstractions.netcoreapp.cs | 80 ++-- ...Connections.Abstractions.netstandard2.0.cs | 80 ++-- ...Connections.Abstractions.netstandard2.1.cs | 80 ++-- .../src/BaseConnectionContext.cs | 8 +- .../src/ConnectionContext.cs | 2 +- .../src/ConnectionItems.cs | 38 +- .../src/DefaultConnectionContext.cs | 16 +- .../Features/IConnectionEndpointFeature.cs | 4 +- .../src/Features/IConnectionIdFeature.cs | 4 +- .../src/Features/IConnectionItemsFeature.cs | 4 +- .../Features/IConnectionTransportFeature.cs | 4 +- .../src/Features/IConnectionUserFeature.cs | 2 +- .../src/IMulitplexedConnectionListener.cs | 2 +- .../src/IMultiplexedConnectionFactory.cs | 2 +- .../IMultiplexedConnectionListenerFactory.cs | 2 +- ...AspNetCore.Connections.Abstractions.csproj | 3 +- .../src/MultiplexedConnectionContext.cs | 2 +- .../ActivatorUtilities/ActivatorUtilities.cs | 12 +- .../ParameterDefaultValue.cs | 4 +- src/Shared/PropertyHelper/PropertyHelper.cs | 44 +-- .../Microsoft.AspNetCore.Shared.Tests.csproj | 1 + 123 files changed, 1060 insertions(+), 1050 deletions(-) diff --git a/src/Http/Headers/ref/Microsoft.Net.Http.Headers.csproj b/src/Http/Headers/ref/Microsoft.Net.Http.Headers.csproj index 5d53f31973..ab3ef8ff50 100644 --- a/src/Http/Headers/ref/Microsoft.Net.Http.Headers.csproj +++ b/src/Http/Headers/ref/Microsoft.Net.Http.Headers.csproj @@ -2,6 +2,7 @@ $(DefaultNetCoreTargetFramework) + annotations diff --git a/src/Http/Headers/ref/Microsoft.Net.Http.Headers.netcoreapp.cs b/src/Http/Headers/ref/Microsoft.Net.Http.Headers.netcoreapp.cs index 74bfe68f38..ff176b7f4e 100644 --- a/src/Http/Headers/ref/Microsoft.Net.Http.Headers.netcoreapp.cs +++ b/src/Http/Headers/ref/Microsoft.Net.Http.Headers.netcoreapp.cs @@ -34,11 +34,11 @@ namespace Microsoft.Net.Http.Headers public bool ProxyRevalidate { get { throw null; } set { } } public bool Public { get { throw null; } set { } } public System.TimeSpan? SharedMaxAge { get { throw null; } set { } } - public override bool Equals(object obj) { throw null; } + public override bool Equals(object? obj) { throw null; } public override int GetHashCode() { throw null; } public static Microsoft.Net.Http.Headers.CacheControlHeaderValue Parse(Microsoft.Extensions.Primitives.StringSegment input) { throw null; } public override string ToString() { throw null; } - public static bool TryParse(Microsoft.Extensions.Primitives.StringSegment input, out Microsoft.Net.Http.Headers.CacheControlHeaderValue parsedValue) { throw null; } + public static bool TryParse(Microsoft.Extensions.Primitives.StringSegment input, [System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] out Microsoft.Net.Http.Headers.CacheControlHeaderValue? parsedValue) { throw null; } } public partial class ContentDispositionHeaderValue { @@ -52,13 +52,13 @@ namespace Microsoft.Net.Http.Headers public System.Collections.Generic.IList Parameters { get { throw null; } } public System.DateTimeOffset? ReadDate { get { throw null; } set { } } public long? Size { get { throw null; } set { } } - public override bool Equals(object obj) { throw null; } + public override bool Equals(object? obj) { throw null; } public override int GetHashCode() { throw null; } public static Microsoft.Net.Http.Headers.ContentDispositionHeaderValue Parse(Microsoft.Extensions.Primitives.StringSegment input) { throw null; } public void SetHttpFileName(Microsoft.Extensions.Primitives.StringSegment fileName) { } public void SetMimeFileName(Microsoft.Extensions.Primitives.StringSegment fileName) { } public override string ToString() { throw null; } - public static bool TryParse(Microsoft.Extensions.Primitives.StringSegment input, out Microsoft.Net.Http.Headers.ContentDispositionHeaderValue parsedValue) { throw null; } + public static bool TryParse(Microsoft.Extensions.Primitives.StringSegment input, [System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] out Microsoft.Net.Http.Headers.ContentDispositionHeaderValue? parsedValue) { throw null; } } public static partial class ContentDispositionHeaderValueIdentityExtensions { @@ -76,11 +76,11 @@ namespace Microsoft.Net.Http.Headers public long? Length { get { throw null; } } public long? To { get { throw null; } } public Microsoft.Extensions.Primitives.StringSegment Unit { get { throw null; } set { } } - public override bool Equals(object obj) { throw null; } + public override bool Equals(object? obj) { throw null; } public override int GetHashCode() { throw null; } public static Microsoft.Net.Http.Headers.ContentRangeHeaderValue Parse(Microsoft.Extensions.Primitives.StringSegment input) { throw null; } public override string ToString() { throw null; } - public static bool TryParse(Microsoft.Extensions.Primitives.StringSegment input, out Microsoft.Net.Http.Headers.ContentRangeHeaderValue parsedValue) { throw null; } + public static bool TryParse(Microsoft.Extensions.Primitives.StringSegment input, [System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] out Microsoft.Net.Http.Headers.ContentRangeHeaderValue parsedValue) { throw null; } } public partial class CookieHeaderValue { @@ -88,15 +88,15 @@ namespace Microsoft.Net.Http.Headers public CookieHeaderValue(Microsoft.Extensions.Primitives.StringSegment name, Microsoft.Extensions.Primitives.StringSegment value) { } public Microsoft.Extensions.Primitives.StringSegment Name { get { throw null; } set { } } public Microsoft.Extensions.Primitives.StringSegment Value { get { throw null; } set { } } - public override bool Equals(object obj) { throw null; } + public override bool Equals(object? obj) { throw null; } public override int GetHashCode() { throw null; } public static Microsoft.Net.Http.Headers.CookieHeaderValue Parse(Microsoft.Extensions.Primitives.StringSegment input) { throw null; } - public static System.Collections.Generic.IList ParseList(System.Collections.Generic.IList inputs) { throw null; } - public static System.Collections.Generic.IList ParseStrictList(System.Collections.Generic.IList inputs) { throw null; } + public static System.Collections.Generic.IList ParseList(System.Collections.Generic.IList? inputs) { throw null; } + public static System.Collections.Generic.IList ParseStrictList(System.Collections.Generic.IList? inputs) { throw null; } public override string ToString() { throw null; } - public static bool TryParse(Microsoft.Extensions.Primitives.StringSegment input, out Microsoft.Net.Http.Headers.CookieHeaderValue parsedValue) { throw null; } - public static bool TryParseList(System.Collections.Generic.IList inputs, out System.Collections.Generic.IList parsedValues) { throw null; } - public static bool TryParseStrictList(System.Collections.Generic.IList inputs, out System.Collections.Generic.IList parsedValues) { throw null; } + public static bool TryParse(Microsoft.Extensions.Primitives.StringSegment input, [System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] out Microsoft.Net.Http.Headers.CookieHeaderValue? parsedValue) { throw null; } + public static bool TryParseList(System.Collections.Generic.IList? inputs, [System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] out System.Collections.Generic.IList? parsedValues) { throw null; } + public static bool TryParseStrictList(System.Collections.Generic.IList? inputs, [System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] out System.Collections.Generic.IList? parsedValues) { throw null; } } public partial class EntityTagHeaderValue { @@ -105,16 +105,16 @@ namespace Microsoft.Net.Http.Headers public static Microsoft.Net.Http.Headers.EntityTagHeaderValue Any { get { throw null; } } public bool IsWeak { get { throw null; } } public Microsoft.Extensions.Primitives.StringSegment Tag { get { throw null; } } - public bool Compare(Microsoft.Net.Http.Headers.EntityTagHeaderValue other, bool useStrongComparison) { throw null; } - public override bool Equals(object obj) { throw null; } + public bool Compare(Microsoft.Net.Http.Headers.EntityTagHeaderValue? other, bool useStrongComparison) { throw null; } + public override bool Equals(object? obj) { throw null; } public override int GetHashCode() { throw null; } public static Microsoft.Net.Http.Headers.EntityTagHeaderValue Parse(Microsoft.Extensions.Primitives.StringSegment input) { throw null; } - public static System.Collections.Generic.IList ParseList(System.Collections.Generic.IList inputs) { throw null; } - public static System.Collections.Generic.IList ParseStrictList(System.Collections.Generic.IList inputs) { throw null; } + public static System.Collections.Generic.IList ParseList(System.Collections.Generic.IList? inputs) { throw null; } + public static System.Collections.Generic.IList ParseStrictList(System.Collections.Generic.IList? inputs) { throw null; } public override string ToString() { throw null; } - public static bool TryParse(Microsoft.Extensions.Primitives.StringSegment input, out Microsoft.Net.Http.Headers.EntityTagHeaderValue parsedValue) { throw null; } - public static bool TryParseList(System.Collections.Generic.IList inputs, out System.Collections.Generic.IList parsedValues) { throw null; } - public static bool TryParseStrictList(System.Collections.Generic.IList inputs, out System.Collections.Generic.IList parsedValues) { throw null; } + public static bool TryParse(Microsoft.Extensions.Primitives.StringSegment input, [System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] out Microsoft.Net.Http.Headers.EntityTagHeaderValue parsedValue) { throw null; } + public static bool TryParseList(System.Collections.Generic.IList? inputs, [System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] out System.Collections.Generic.IList? parsedValues) { throw null; } + public static bool TryParseStrictList(System.Collections.Generic.IList? inputs, [System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] out System.Collections.Generic.IList? parsedValues) { throw null; } } public static partial class HeaderNames { @@ -228,7 +228,7 @@ namespace Microsoft.Net.Http.Headers public MediaTypeHeaderValue(Microsoft.Extensions.Primitives.StringSegment mediaType, double quality) { } public Microsoft.Extensions.Primitives.StringSegment Boundary { get { throw null; } set { } } public Microsoft.Extensions.Primitives.StringSegment Charset { get { throw null; } set { } } - public System.Text.Encoding Encoding { get { throw null; } set { } } + public System.Text.Encoding? Encoding { get { throw null; } set { } } public System.Collections.Generic.IEnumerable Facets { get { throw null; } } public bool IsReadOnly { get { throw null; } } public bool MatchesAllSubTypes { get { throw null; } } @@ -243,22 +243,22 @@ namespace Microsoft.Net.Http.Headers public Microsoft.Extensions.Primitives.StringSegment Type { get { throw null; } } public Microsoft.Net.Http.Headers.MediaTypeHeaderValue Copy() { throw null; } public Microsoft.Net.Http.Headers.MediaTypeHeaderValue CopyAsReadOnly() { throw null; } - public override bool Equals(object obj) { throw null; } + public override bool Equals(object? obj) { throw null; } public override int GetHashCode() { throw null; } public bool IsSubsetOf(Microsoft.Net.Http.Headers.MediaTypeHeaderValue otherMediaType) { throw null; } public static Microsoft.Net.Http.Headers.MediaTypeHeaderValue Parse(Microsoft.Extensions.Primitives.StringSegment input) { throw null; } - public static System.Collections.Generic.IList ParseList(System.Collections.Generic.IList inputs) { throw null; } - public static System.Collections.Generic.IList ParseStrictList(System.Collections.Generic.IList inputs) { throw null; } + public static System.Collections.Generic.IList ParseList(System.Collections.Generic.IList? inputs) { throw null; } + public static System.Collections.Generic.IList ParseStrictList(System.Collections.Generic.IList? inputs) { throw null; } public override string ToString() { throw null; } - public static bool TryParse(Microsoft.Extensions.Primitives.StringSegment input, out Microsoft.Net.Http.Headers.MediaTypeHeaderValue parsedValue) { throw null; } - public static bool TryParseList(System.Collections.Generic.IList inputs, out System.Collections.Generic.IList parsedValues) { throw null; } - public static bool TryParseStrictList(System.Collections.Generic.IList inputs, out System.Collections.Generic.IList parsedValues) { throw null; } + public static bool TryParse(Microsoft.Extensions.Primitives.StringSegment input, [System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] out Microsoft.Net.Http.Headers.MediaTypeHeaderValue? parsedValue) { throw null; } + public static bool TryParseList(System.Collections.Generic.IList? inputs, [System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] out System.Collections.Generic.IList? parsedValues) { throw null; } + public static bool TryParseStrictList(System.Collections.Generic.IList? inputs, [System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] out System.Collections.Generic.IList? parsedValues) { throw null; } } public partial class MediaTypeHeaderValueComparer : System.Collections.Generic.IComparer { internal MediaTypeHeaderValueComparer() { } - public static Microsoft.Net.Http.Headers.MediaTypeHeaderValueComparer QualityComparer { get { throw null; } } - public int Compare(Microsoft.Net.Http.Headers.MediaTypeHeaderValue mediaType1, Microsoft.Net.Http.Headers.MediaTypeHeaderValue mediaType2) { throw null; } + public static Microsoft.Net.Http.Headers.MediaTypeHeaderValueComparer QualityComparer { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } + public int Compare(Microsoft.Net.Http.Headers.MediaTypeHeaderValue? mediaType1, Microsoft.Net.Http.Headers.MediaTypeHeaderValue? mediaType2) { throw null; } } public partial class NameValueHeaderValue { @@ -269,31 +269,31 @@ namespace Microsoft.Net.Http.Headers public Microsoft.Extensions.Primitives.StringSegment Value { get { throw null; } set { } } public Microsoft.Net.Http.Headers.NameValueHeaderValue Copy() { throw null; } public Microsoft.Net.Http.Headers.NameValueHeaderValue CopyAsReadOnly() { throw null; } - public override bool Equals(object obj) { throw null; } - public static Microsoft.Net.Http.Headers.NameValueHeaderValue Find(System.Collections.Generic.IList values, Microsoft.Extensions.Primitives.StringSegment name) { throw null; } + public override bool Equals(object? obj) { throw null; } + public static Microsoft.Net.Http.Headers.NameValueHeaderValue? Find(System.Collections.Generic.IList? values, Microsoft.Extensions.Primitives.StringSegment name) { throw null; } public override int GetHashCode() { throw null; } public Microsoft.Extensions.Primitives.StringSegment GetUnescapedValue() { throw null; } public static Microsoft.Net.Http.Headers.NameValueHeaderValue Parse(Microsoft.Extensions.Primitives.StringSegment input) { throw null; } - public static System.Collections.Generic.IList ParseList(System.Collections.Generic.IList input) { throw null; } - public static System.Collections.Generic.IList ParseStrictList(System.Collections.Generic.IList input) { throw null; } + public static System.Collections.Generic.IList ParseList(System.Collections.Generic.IList? input) { throw null; } + public static System.Collections.Generic.IList ParseStrictList(System.Collections.Generic.IList? input) { throw null; } public void SetAndEscapeValue(Microsoft.Extensions.Primitives.StringSegment value) { } public override string ToString() { throw null; } - public static bool TryParse(Microsoft.Extensions.Primitives.StringSegment input, out Microsoft.Net.Http.Headers.NameValueHeaderValue parsedValue) { throw null; } - public static bool TryParseList(System.Collections.Generic.IList input, out System.Collections.Generic.IList parsedValues) { throw null; } - public static bool TryParseStrictList(System.Collections.Generic.IList input, out System.Collections.Generic.IList parsedValues) { throw null; } + public static bool TryParse(Microsoft.Extensions.Primitives.StringSegment input, [System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] out Microsoft.Net.Http.Headers.NameValueHeaderValue? parsedValue) { throw null; } + public static bool TryParseList(System.Collections.Generic.IList? input, [System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] out System.Collections.Generic.IList? parsedValues) { throw null; } + public static bool TryParseStrictList(System.Collections.Generic.IList? input, [System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] out System.Collections.Generic.IList? parsedValues) { throw null; } } public partial class RangeConditionHeaderValue { - public RangeConditionHeaderValue(Microsoft.Net.Http.Headers.EntityTagHeaderValue entityTag) { } + public RangeConditionHeaderValue(Microsoft.Net.Http.Headers.EntityTagHeaderValue? entityTag) { } public RangeConditionHeaderValue(System.DateTimeOffset lastModified) { } - public RangeConditionHeaderValue(string entityTag) { } - public Microsoft.Net.Http.Headers.EntityTagHeaderValue EntityTag { get { throw null; } } + public RangeConditionHeaderValue(string? entityTag) { } + public Microsoft.Net.Http.Headers.EntityTagHeaderValue? EntityTag { get { throw null; } } public System.DateTimeOffset? LastModified { get { throw null; } } - public override bool Equals(object obj) { throw null; } + public override bool Equals(object? obj) { throw null; } public override int GetHashCode() { throw null; } public static Microsoft.Net.Http.Headers.RangeConditionHeaderValue Parse(Microsoft.Extensions.Primitives.StringSegment input) { throw null; } public override string ToString() { throw null; } - public static bool TryParse(Microsoft.Extensions.Primitives.StringSegment input, out Microsoft.Net.Http.Headers.RangeConditionHeaderValue parsedValue) { throw null; } + public static bool TryParse(Microsoft.Extensions.Primitives.StringSegment input, [System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] out Microsoft.Net.Http.Headers.RangeConditionHeaderValue? parsedValue) { throw null; } } public partial class RangeHeaderValue { @@ -301,18 +301,18 @@ namespace Microsoft.Net.Http.Headers public RangeHeaderValue(long? from, long? to) { } public System.Collections.Generic.ICollection Ranges { get { throw null; } } public Microsoft.Extensions.Primitives.StringSegment Unit { get { throw null; } set { } } - public override bool Equals(object obj) { throw null; } + public override bool Equals(object? obj) { throw null; } public override int GetHashCode() { throw null; } public static Microsoft.Net.Http.Headers.RangeHeaderValue Parse(Microsoft.Extensions.Primitives.StringSegment input) { throw null; } public override string ToString() { throw null; } - public static bool TryParse(Microsoft.Extensions.Primitives.StringSegment input, out Microsoft.Net.Http.Headers.RangeHeaderValue parsedValue) { throw null; } + public static bool TryParse(Microsoft.Extensions.Primitives.StringSegment input, [System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] out Microsoft.Net.Http.Headers.RangeHeaderValue parsedValue) { throw null; } } public partial class RangeItemHeaderValue { public RangeItemHeaderValue(long? from, long? to) { } public long? From { get { throw null; } } public long? To { get { throw null; } } - public override bool Equals(object obj) { throw null; } + public override bool Equals(object? obj) { throw null; } public override int GetHashCode() { throw null; } public override string ToString() { throw null; } } @@ -337,15 +337,15 @@ namespace Microsoft.Net.Http.Headers public bool Secure { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } public Microsoft.Extensions.Primitives.StringSegment Value { get { throw null; } set { } } public void AppendToStringBuilder(System.Text.StringBuilder builder) { } - public override bool Equals(object obj) { throw null; } + public override bool Equals(object? obj) { throw null; } public override int GetHashCode() { throw null; } public static Microsoft.Net.Http.Headers.SetCookieHeaderValue Parse(Microsoft.Extensions.Primitives.StringSegment input) { throw null; } - public static System.Collections.Generic.IList ParseList(System.Collections.Generic.IList inputs) { throw null; } - public static System.Collections.Generic.IList ParseStrictList(System.Collections.Generic.IList inputs) { throw null; } + public static System.Collections.Generic.IList ParseList(System.Collections.Generic.IList? inputs) { throw null; } + public static System.Collections.Generic.IList ParseStrictList(System.Collections.Generic.IList? inputs) { throw null; } public override string ToString() { throw null; } - public static bool TryParse(Microsoft.Extensions.Primitives.StringSegment input, out Microsoft.Net.Http.Headers.SetCookieHeaderValue parsedValue) { throw null; } - public static bool TryParseList(System.Collections.Generic.IList inputs, out System.Collections.Generic.IList parsedValues) { throw null; } - public static bool TryParseStrictList(System.Collections.Generic.IList inputs, out System.Collections.Generic.IList parsedValues) { throw null; } + public static bool TryParse(Microsoft.Extensions.Primitives.StringSegment input, [System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] out Microsoft.Net.Http.Headers.SetCookieHeaderValue? parsedValue) { throw null; } + public static bool TryParseList(System.Collections.Generic.IList? inputs, [System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] out System.Collections.Generic.IList? parsedValues) { throw null; } + public static bool TryParseStrictList(System.Collections.Generic.IList? inputs, [System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] out System.Collections.Generic.IList? parsedValues) { throw null; } } public partial class StringWithQualityHeaderValue { @@ -353,20 +353,20 @@ namespace Microsoft.Net.Http.Headers public StringWithQualityHeaderValue(Microsoft.Extensions.Primitives.StringSegment value, double quality) { } public double? Quality { get { throw null; } } public Microsoft.Extensions.Primitives.StringSegment Value { get { throw null; } } - public override bool Equals(object obj) { throw null; } + public override bool Equals(object? obj) { throw null; } public override int GetHashCode() { throw null; } public static Microsoft.Net.Http.Headers.StringWithQualityHeaderValue Parse(Microsoft.Extensions.Primitives.StringSegment input) { throw null; } - public static System.Collections.Generic.IList ParseList(System.Collections.Generic.IList input) { throw null; } - public static System.Collections.Generic.IList ParseStrictList(System.Collections.Generic.IList input) { throw null; } + public static System.Collections.Generic.IList ParseList(System.Collections.Generic.IList? input) { throw null; } + public static System.Collections.Generic.IList ParseStrictList(System.Collections.Generic.IList? input) { throw null; } public override string ToString() { throw null; } - public static bool TryParse(Microsoft.Extensions.Primitives.StringSegment input, out Microsoft.Net.Http.Headers.StringWithQualityHeaderValue parsedValue) { throw null; } - public static bool TryParseList(System.Collections.Generic.IList input, out System.Collections.Generic.IList parsedValues) { throw null; } - public static bool TryParseStrictList(System.Collections.Generic.IList input, out System.Collections.Generic.IList parsedValues) { throw null; } + public static bool TryParse(Microsoft.Extensions.Primitives.StringSegment input, [System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] out Microsoft.Net.Http.Headers.StringWithQualityHeaderValue parsedValue) { throw null; } + public static bool TryParseList(System.Collections.Generic.IList? input, [System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] out System.Collections.Generic.IList? parsedValues) { throw null; } + public static bool TryParseStrictList(System.Collections.Generic.IList? input, [System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] out System.Collections.Generic.IList? parsedValues) { throw null; } } public partial class StringWithQualityHeaderValueComparer : System.Collections.Generic.IComparer { internal StringWithQualityHeaderValueComparer() { } - public static Microsoft.Net.Http.Headers.StringWithQualityHeaderValueComparer QualityComparer { get { throw null; } } - public int Compare(Microsoft.Net.Http.Headers.StringWithQualityHeaderValue stringWithQuality1, Microsoft.Net.Http.Headers.StringWithQualityHeaderValue stringWithQuality2) { throw null; } + public static Microsoft.Net.Http.Headers.StringWithQualityHeaderValueComparer QualityComparer { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } + public int Compare(Microsoft.Net.Http.Headers.StringWithQualityHeaderValue? stringWithQuality1, Microsoft.Net.Http.Headers.StringWithQualityHeaderValue? stringWithQuality2) { throw null; } } } diff --git a/src/Http/Headers/src/BaseHeaderParser.cs b/src/Http/Headers/src/BaseHeaderParser.cs index f3caaafb70..4e80787878 100644 --- a/src/Http/Headers/src/BaseHeaderParser.cs +++ b/src/Http/Headers/src/BaseHeaderParser.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.Diagnostics.CodeAnalysis; using Microsoft.Extensions.Primitives; namespace Microsoft.Net.Http.Headers @@ -12,11 +13,11 @@ namespace Microsoft.Net.Http.Headers { } - protected abstract int GetParsedValueLength(StringSegment value, int startIndex, out T parsedValue); + protected abstract int GetParsedValueLength(StringSegment value, int startIndex, [MaybeNull] out T parsedValue); - public sealed override bool TryParseValue(StringSegment value, ref int index, out T parsedValue) + public sealed override bool TryParseValue(StringSegment value, ref int index, [MaybeNull] out T parsedValue) { - parsedValue = default(T); + parsedValue = default; // If multiple values are supported (i.e. list of values), then accept an empty string: The header may // be added multiple times to the request/response message. E.g. diff --git a/src/Http/Headers/src/CacheControlHeaderValue.cs b/src/Http/Headers/src/CacheControlHeaderValue.cs index cee7f8b8c1..14a59b2422 100644 --- a/src/Http/Headers/src/CacheControlHeaderValue.cs +++ b/src/Http/Headers/src/CacheControlHeaderValue.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Diagnostics.Contracts; using System.Globalization; using System.Text; @@ -31,12 +32,12 @@ namespace Microsoft.Net.Http.Headers // Cache-Control headers, only one instance of CacheControlHeaderValue is created (if all headers contain valid // values, otherwise we may have multiple strings containing the invalid values). private static readonly HttpHeaderParser Parser - = new GenericHeaderParser(true, GetCacheControlLength); + = new GenericHeaderParser(true, GetCacheControlLength!); private static readonly Action CheckIsValidTokenAction = CheckIsValidToken; private bool _noCache; - private ICollection _noCacheHeaders; + private ICollection? _noCacheHeaders; private bool _noStore; private TimeSpan? _maxAge; private TimeSpan? _sharedMaxAge; @@ -47,10 +48,10 @@ namespace Microsoft.Net.Http.Headers private bool _onlyIfCached; private bool _public; private bool _private; - private ICollection _privateHeaders; + private ICollection? _privateHeaders; private bool _mustRevalidate; private bool _proxyRevalidate; - private IList _extensions; + private IList? _extensions; public CacheControlHeaderValue() { @@ -240,7 +241,7 @@ namespace Microsoft.Net.Http.Headers return sb.ToString(); } - public override bool Equals(object obj) + public override bool Equals(object? obj) { var other = obj as CacheControlHeaderValue; @@ -325,7 +326,7 @@ namespace Microsoft.Net.Http.Headers public static CacheControlHeaderValue Parse(StringSegment input) { - int index = 0; + var index = 0; // Cache-Control is unusual because there are no required values so the parser will succeed for an empty string, but still return null. var result = Parser.ParseValue(input, ref index); if (result == null) @@ -335,9 +336,9 @@ namespace Microsoft.Net.Http.Headers return result; } - public static bool TryParse(StringSegment input, out CacheControlHeaderValue parsedValue) + public static bool TryParse(StringSegment input, [NotNullWhen(true)] out CacheControlHeaderValue? parsedValue) { - int index = 0; + var index = 0; // Cache-Control is unusual because there are no required values so the parser will succeed for an empty string, but still return null. if (Parser.TryParseValue(input, ref index, out parsedValue) && parsedValue != null) { @@ -347,7 +348,7 @@ namespace Microsoft.Net.Http.Headers return false; } - private static int GetCacheControlLength(StringSegment input, int startIndex, out CacheControlHeaderValue parsedValue) + private static int GetCacheControlLength(StringSegment input, int startIndex, out CacheControlHeaderValue? parsedValue) { Contract.Requires(startIndex >= 0); @@ -361,16 +362,18 @@ namespace Microsoft.Net.Http.Headers // Cache-Control header consists of a list of name/value pairs, where the value is optional. So use an // instance of NameValueHeaderParser to parse the string. var current = startIndex; - NameValueHeaderValue nameValue = null; var nameValueList = new List(); while (current < input.Length) { - if (!NameValueHeaderValue.MultipleValueParser.TryParseValue(input, ref current, out nameValue)) + if (!NameValueHeaderValue.MultipleValueParser.TryParseValue(input, ref current, out var nameValue)) { return 0; } - nameValueList.Add(nameValue); + if (nameValue != null) + { + nameValueList.Add(nameValue); + } } // If we get here, we were able to successfully parse the string as list of name/value pairs. Now analyze @@ -539,10 +542,8 @@ namespace Microsoft.Net.Http.Headers private static bool TrySetOptionalTokenList( NameValueHeaderValue nameValue, ref bool boolField, - ref ICollection destination) + ref ICollection? destination) { - Contract.Requires(nameValue != null); - if (nameValue.Value == null) { boolField = true; @@ -603,8 +604,6 @@ namespace Microsoft.Net.Http.Headers private static bool TrySetTimeSpan(NameValueHeaderValue nameValue, ref TimeSpan? timeSpan) { - Contract.Requires(nameValue != null); - if (nameValue.Value == null) { return false; diff --git a/src/Http/Headers/src/ContentDispositionHeaderValue.cs b/src/Http/Headers/src/ContentDispositionHeaderValue.cs index cb868ce897..3e629d10cb 100644 --- a/src/Http/Headers/src/ContentDispositionHeaderValue.cs +++ b/src/Http/Headers/src/ContentDispositionHeaderValue.cs @@ -4,6 +4,7 @@ using System; using System.Buffers; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Diagnostics.Contracts; using System.Globalization; using System.Linq; @@ -26,10 +27,10 @@ namespace Microsoft.Net.Http.Headers private static readonly char[] SingleQuote = new char[] { '\'' }; private static readonly HttpHeaderParser Parser - = new GenericHeaderParser(false, GetDispositionTypeLength); + = new GenericHeaderParser(false, GetDispositionTypeLength!); // Use list instead of dictionary since we may have multiple parameters with the same name. - private ObjectCollection _parameters; + private ObjectCollection? _parameters; private StringSegment _dispositionType; private ContentDispositionHeaderValue() @@ -109,11 +110,10 @@ namespace Microsoft.Net.Http.Headers get { var sizeParameter = NameValueHeaderValue.Find(_parameters, SizeString); - long value; if (sizeParameter != null) { var sizeString = sizeParameter.Value; - if (HeaderUtilities.TryParseNonNegativeInt64(sizeString, out value)) + if (HeaderUtilities.TryParseNonNegativeInt64(sizeString, out var value)) { return value; } @@ -128,7 +128,7 @@ namespace Microsoft.Net.Http.Headers // Remove parameter if (sizeParameter != null) { - _parameters.Remove(sizeParameter); + _parameters!.Remove(sizeParameter); } } else if (value < 0) @@ -141,8 +141,8 @@ namespace Microsoft.Net.Http.Headers } else { - string sizeString = value.GetValueOrDefault().ToString(CultureInfo.InvariantCulture); - _parameters.Add(new NameValueHeaderValue(SizeString, sizeString)); + var sizeString = value.GetValueOrDefault().ToString(CultureInfo.InvariantCulture); + Parameters.Add(new NameValueHeaderValue(SizeString, sizeString)); } } } @@ -180,7 +180,7 @@ namespace Microsoft.Net.Http.Headers return _dispositionType + NameValueHeaderValue.ToString(_parameters, ';', true); } - public override bool Equals(object obj) + public override bool Equals(object? obj) { var other = obj as ContentDispositionHeaderValue; @@ -202,16 +202,16 @@ namespace Microsoft.Net.Http.Headers public static ContentDispositionHeaderValue Parse(StringSegment input) { var index = 0; - return Parser.ParseValue(input, ref index); + return Parser.ParseValue(input, ref index)!; } - public static bool TryParse(StringSegment input, out ContentDispositionHeaderValue parsedValue) + public static bool TryParse(StringSegment input, [NotNullWhen(true)] out ContentDispositionHeaderValue? parsedValue) { var index = 0; - return Parser.TryParseValue(input, ref index, out parsedValue); + return Parser.TryParseValue(input, ref index, out parsedValue!); } - private static int GetDispositionTypeLength(StringSegment input, int startIndex, out ContentDispositionHeaderValue parsedValue) + private static int GetDispositionTypeLength(StringSegment input, int startIndex, out ContentDispositionHeaderValue? parsedValue) { Contract.Requires(startIndex >= 0); @@ -253,7 +253,7 @@ namespace Microsoft.Net.Http.Headers private static int GetDispositionTypeExpressionLength(StringSegment input, int startIndex, out StringSegment dispositionType) { - Contract.Requires((input != null) && (input.Length > 0) && (startIndex < input.Length)); + Contract.Requires((input.Length > 0) && (startIndex < input.Length)); // This method just parses the disposition type string, it does not parse parameters. dispositionType = null; @@ -318,7 +318,7 @@ namespace Microsoft.Net.Http.Headers // Remove parameter if (dateParameter != null) { - _parameters.Remove(dateParameter); + _parameters!.Remove(dateParameter); } } else @@ -343,7 +343,7 @@ namespace Microsoft.Net.Http.Headers var nameParameter = NameValueHeaderValue.Find(_parameters, parameter); if (nameParameter != null) { - string result; + string? result; // filename*=utf-8'lang'%7FMyString if (parameter.EndsWith("*", StringComparison.Ordinal)) { @@ -375,7 +375,7 @@ namespace Microsoft.Net.Http.Headers // Remove parameter if (nameParameter != null) { - _parameters.Remove(nameParameter); + _parameters!.Remove(nameParameter); } } else @@ -497,7 +497,7 @@ namespace Microsoft.Net.Http.Headers } // Attempt to decode MIME encoded strings - private bool TryDecodeMime(StringSegment input, out string output) + private bool TryDecodeMime(StringSegment input, [NotNullWhen(true)] out string? output) { Contract.Assert(input != null); @@ -582,7 +582,7 @@ namespace Microsoft.Net.Http.Headers // Attempt to decode using RFC 5987 encoding. // encoding'language'my%20string - private bool TryDecode5987(StringSegment input, out string output) + private bool TryDecode5987(StringSegment input, [NotNullWhen(true)] out string? output) { output = null; @@ -593,7 +593,7 @@ namespace Microsoft.Net.Http.Headers } var decoded = new StringBuilder(); - byte[] unescapedBytes = null; + byte[]? unescapedBytes = null; try { var encoding = Encoding.GetEncoding(parts[0].ToString()); diff --git a/src/Http/Headers/src/ContentRangeHeaderValue.cs b/src/Http/Headers/src/ContentRangeHeaderValue.cs index 99723864f3..1c9a7a55b7 100644 --- a/src/Http/Headers/src/ContentRangeHeaderValue.cs +++ b/src/Http/Headers/src/ContentRangeHeaderValue.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Diagnostics.CodeAnalysis; using System.Diagnostics.Contracts; using System.Globalization; using System.Text; @@ -12,7 +13,7 @@ namespace Microsoft.Net.Http.Headers public class ContentRangeHeaderValue { private static readonly HttpHeaderParser Parser - = new GenericHeaderParser(false, GetContentRangeLength); + = new GenericHeaderParser(false, GetContentRangeLength!); private StringSegment _unit; private long? _from; @@ -113,7 +114,7 @@ namespace Microsoft.Net.Http.Headers get { return _from != null; } } - public override bool Equals(object obj) + public override bool Equals(object? obj) { var other = obj as ContentRangeHeaderValue; @@ -176,16 +177,16 @@ namespace Microsoft.Net.Http.Headers public static ContentRangeHeaderValue Parse(StringSegment input) { var index = 0; - return Parser.ParseValue(input, ref index); + return Parser.ParseValue(input, ref index)!; } - public static bool TryParse(StringSegment input, out ContentRangeHeaderValue parsedValue) + public static bool TryParse(StringSegment input, [NotNullWhen(true)] out ContentRangeHeaderValue parsedValue) { var index = 0; - return Parser.TryParseValue(input, ref index, out parsedValue); + return Parser.TryParseValue(input, ref index, out parsedValue!); } - private static int GetContentRangeLength(StringSegment input, int startIndex, out ContentRangeHeaderValue parsedValue) + private static int GetContentRangeLength(StringSegment input, int startIndex, out ContentRangeHeaderValue? parsedValue) { Contract.Requires(startIndex >= 0); @@ -351,7 +352,7 @@ namespace Microsoft.Net.Http.Headers int toLength, int lengthStartIndex, int lengthLength, - out ContentRangeHeaderValue parsedValue) + [NotNullWhen(true)]out ContentRangeHeaderValue? parsedValue) { parsedValue = null; diff --git a/src/Http/Headers/src/CookieHeaderParser.cs b/src/Http/Headers/src/CookieHeaderParser.cs index 7201ae21a1..b77263bc18 100644 --- a/src/Http/Headers/src/CookieHeaderParser.cs +++ b/src/Http/Headers/src/CookieHeaderParser.cs @@ -13,7 +13,7 @@ namespace Microsoft.Net.Http.Headers { } - public override bool TryParseValue(StringSegment value, ref int index, out CookieHeaderValue parsedValue) + public override bool TryParseValue(StringSegment value, ref int index, out CookieHeaderValue? parsedValue) { parsedValue = null; @@ -43,8 +43,7 @@ namespace Microsoft.Net.Http.Headers return SupportsMultipleValues; } - CookieHeaderValue result = null; - if (!CookieHeaderValue.TryGetCookieLength(value, ref current, out result)) + if (!CookieHeaderValue.TryGetCookieLength(value, ref current, out var result)) { return false; } @@ -64,7 +63,6 @@ namespace Microsoft.Net.Http.Headers private static int GetNextNonEmptyOrWhitespaceIndex(StringSegment input, int startIndex, bool skipEmptyValues, out bool separatorFound) { - Contract.Requires(input != null); Contract.Requires(startIndex <= input.Length); // it's OK if index == value.Length. separatorFound = false; diff --git a/src/Http/Headers/src/CookieHeaderValue.cs b/src/Http/Headers/src/CookieHeaderValue.cs index 54753d2830..d92fcc6f83 100644 --- a/src/Http/Headers/src/CookieHeaderValue.cs +++ b/src/Http/Headers/src/CookieHeaderValue.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Diagnostics.Contracts; using System.Text; using Microsoft.Extensions.Primitives; @@ -83,37 +84,37 @@ namespace Microsoft.Net.Http.Headers public static CookieHeaderValue Parse(StringSegment input) { var index = 0; - return SingleValueParser.ParseValue(input, ref index); + return SingleValueParser.ParseValue(input, ref index)!; } - public static bool TryParse(StringSegment input, out CookieHeaderValue parsedValue) + public static bool TryParse(StringSegment input, [NotNullWhen(true)] out CookieHeaderValue? parsedValue) { var index = 0; - return SingleValueParser.TryParseValue(input, ref index, out parsedValue); + return SingleValueParser.TryParseValue(input, ref index, out parsedValue!); } - public static IList ParseList(IList inputs) + public static IList ParseList(IList? inputs) { return MultipleValueParser.ParseValues(inputs); } - public static IList ParseStrictList(IList inputs) + public static IList ParseStrictList(IList? inputs) { return MultipleValueParser.ParseStrictValues(inputs); } - public static bool TryParseList(IList inputs, out IList parsedValues) + public static bool TryParseList(IList? inputs, [NotNullWhen(true)] out IList? parsedValues) { return MultipleValueParser.TryParseValues(inputs, out parsedValues); } - public static bool TryParseStrictList(IList inputs, out IList parsedValues) + public static bool TryParseStrictList(IList? inputs, [NotNullWhen(true)] out IList? parsedValues) { return MultipleValueParser.TryParseStrictValues(inputs, out parsedValues); } // name=value; name="value" - internal static bool TryGetCookieLength(StringSegment input, ref int offset, out CookieHeaderValue parsedValue) + internal static bool TryGetCookieLength(StringSegment input, ref int offset, [NotNullWhen(true)] out CookieHeaderValue? parsedValue) { Contract.Requires(offset >= 0); @@ -158,7 +159,6 @@ namespace Microsoft.Net.Http.Headers // ; US-ASCII characters excluding CTLs, whitespace DQUOTE, comma, semicolon, and backslash internal static StringSegment GetCookieValue(StringSegment input, ref int offset) { - Contract.Requires(input != null); Contract.Requires(offset >= 0); Contract.Ensures((Contract.Result() >= 0) && (Contract.Result() <= (input.Length - offset))); @@ -256,7 +256,7 @@ namespace Microsoft.Net.Http.Headers } } - public override bool Equals(object obj) + public override bool Equals(object? obj) { var other = obj as CookieHeaderValue; diff --git a/src/Http/Headers/src/EntityTagHeaderValue.cs b/src/Http/Headers/src/EntityTagHeaderValue.cs index 9b3a37136b..a468eeb5dc 100644 --- a/src/Http/Headers/src/EntityTagHeaderValue.cs +++ b/src/Http/Headers/src/EntityTagHeaderValue.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Diagnostics.Contracts; using Microsoft.Extensions.Primitives; @@ -13,15 +14,15 @@ namespace Microsoft.Net.Http.Headers // Note that the ETag header does not allow a * but we're not that strict: We allow both '*' and ETag values in a single value. // We can't guarantee that a single parsed value will be used directly in an ETag header. private static readonly HttpHeaderParser SingleValueParser - = new GenericHeaderParser(false, GetEntityTagLength); + = new GenericHeaderParser(false, GetEntityTagLength!); // Note that if multiple ETag values are allowed (e.g. 'If-Match', 'If-None-Match'), according to the RFC // the value must either be '*' or a list of ETag values. It's not allowed to have both '*' and a list of // ETag values. We're not that strict: We allow both '*' and ETag values in a list. If the server sends such // an invalid list, we want to be able to represent it using the corresponding header property. private static readonly HttpHeaderParser MultipleValueParser - = new GenericHeaderParser(true, GetEntityTagLength); + = new GenericHeaderParser(true, GetEntityTagLength!); - private static EntityTagHeaderValue AnyType; + private static EntityTagHeaderValue? AnyType; private StringSegment _tag; private bool _isWeak; @@ -103,7 +104,7 @@ namespace Microsoft.Net.Http.Headers /// true if the strength and tag of the two values match, /// false if the other value is null, is not an , or if there is a mismatch of strength or tag between the two values. /// - public override bool Equals(object obj) + public override bool Equals(object? obj) { var other = obj as EntityTagHeaderValue; @@ -131,7 +132,7 @@ namespace Microsoft.Net.Http.Headers /// true if the match for the given comparison type, /// false if the other value is null or the comparison failed. /// - public bool Compare(EntityTagHeaderValue other, bool useStrongComparison) + public bool Compare(EntityTagHeaderValue? other, bool useStrongComparison) { if (other == null) { @@ -151,36 +152,36 @@ namespace Microsoft.Net.Http.Headers public static EntityTagHeaderValue Parse(StringSegment input) { var index = 0; - return SingleValueParser.ParseValue(input, ref index); + return SingleValueParser.ParseValue(input, ref index)!; } - public static bool TryParse(StringSegment input, out EntityTagHeaderValue parsedValue) + public static bool TryParse(StringSegment input, [NotNullWhen(true)] out EntityTagHeaderValue parsedValue) { var index = 0; - return SingleValueParser.TryParseValue(input, ref index, out parsedValue); + return SingleValueParser.TryParseValue(input, ref index, out parsedValue!); } - public static IList ParseList(IList inputs) + public static IList ParseList(IList? inputs) { return MultipleValueParser.ParseValues(inputs); } - public static IList ParseStrictList(IList inputs) + public static IList ParseStrictList(IList? inputs) { return MultipleValueParser.ParseStrictValues(inputs); } - public static bool TryParseList(IList inputs, out IList parsedValues) + public static bool TryParseList(IList? inputs, [NotNullWhen(true)] out IList? parsedValues) { return MultipleValueParser.TryParseValues(inputs, out parsedValues); } - public static bool TryParseStrictList(IList inputs, out IList parsedValues) + public static bool TryParseStrictList(IList? inputs, [NotNullWhen(true)] out IList? parsedValues) { return MultipleValueParser.TryParseStrictValues(inputs, out parsedValues); } - internal static int GetEntityTagLength(StringSegment input, int startIndex, out EntityTagHeaderValue parsedValue) + internal static int GetEntityTagLength(StringSegment input, int startIndex, out EntityTagHeaderValue? parsedValue) { Contract.Requires(startIndex >= 0); diff --git a/src/Http/Headers/src/GenericHeaderParser.cs b/src/Http/Headers/src/GenericHeaderParser.cs index a2fbf720f9..53a5777448 100644 --- a/src/Http/Headers/src/GenericHeaderParser.cs +++ b/src/Http/Headers/src/GenericHeaderParser.cs @@ -2,13 +2,14 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Diagnostics.CodeAnalysis; using Microsoft.Extensions.Primitives; namespace Microsoft.Net.Http.Headers { internal sealed class GenericHeaderParser : BaseHeaderParser { - internal delegate int GetParsedValueLengthDelegate(StringSegment value, int startIndex, out T parsedValue); + internal delegate int GetParsedValueLengthDelegate(StringSegment value, int startIndex, [MaybeNull] out T parsedValue); private GetParsedValueLengthDelegate _getParsedValueLength; @@ -23,7 +24,7 @@ namespace Microsoft.Net.Http.Headers _getParsedValueLength = getParsedValueLength; } - protected override int GetParsedValueLength(StringSegment value, int startIndex, out T parsedValue) + protected override int GetParsedValueLength(StringSegment value, int startIndex, [MaybeNull] out T parsedValue) { return _getParsedValueLength(value, startIndex, out parsedValue); } diff --git a/src/Http/Headers/src/HeaderUtilities.cs b/src/Http/Headers/src/HeaderUtilities.cs index ac193c0c38..75be781c16 100644 --- a/src/Http/Headers/src/HeaderUtilities.cs +++ b/src/Http/Headers/src/HeaderUtilities.cs @@ -19,8 +19,6 @@ namespace Microsoft.Net.Http.Headers internal static void SetQuality(IList parameters, double? value) { - Contract.Requires(parameters != null); - var qualityParameter = NameValueHeaderValue.Find(parameters, QualityName); if (value.HasValue) { @@ -41,7 +39,7 @@ namespace Microsoft.Net.Http.Headers } else { - parameters.Add(new NameValueHeaderValue(QualityName, qualityString)); + parameters!.Add(new NameValueHeaderValue(QualityName, qualityString)); } } else @@ -56,8 +54,6 @@ namespace Microsoft.Net.Http.Headers internal static double? GetQuality(IList parameters) { - Contract.Requires(parameters != null); - var qualityParameter = NameValueHeaderValue.Find(parameters, QualityName); if (qualityParameter != null) { @@ -85,12 +81,12 @@ namespace Microsoft.Net.Http.Headers } } - internal static bool AreEqualCollections(ICollection x, ICollection y) + internal static bool AreEqualCollections(ICollection? x, ICollection? y) { return AreEqualCollections(x, y, null); } - internal static bool AreEqualCollections(ICollection x, ICollection y, IEqualityComparer comparer) + internal static bool AreEqualCollections(ICollection? x, ICollection? y, IEqualityComparer? comparer) { if (x == null) { @@ -157,7 +153,6 @@ namespace Microsoft.Net.Http.Headers bool skipEmptyValues, out bool separatorFound) { - Contract.Requires(input != null); Contract.Requires(startIndex <= input.Length); // it's OK if index == value.Length. separatorFound = false; diff --git a/src/Http/Headers/src/HttpHeaderParser.cs b/src/Http/Headers/src/HttpHeaderParser.cs index 027a9de438..addb5479f8 100644 --- a/src/Http/Headers/src/HttpHeaderParser.cs +++ b/src/Http/Headers/src/HttpHeaderParser.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Diagnostics.Contracts; using System.Globalization; using Microsoft.Extensions.Primitives; @@ -11,7 +12,7 @@ namespace Microsoft.Net.Http.Headers { internal abstract class HttpHeaderParser { - private bool _supportsMultipleValues; + private readonly bool _supportsMultipleValues; protected HttpHeaderParser(bool supportsMultipleValues) { @@ -27,8 +28,9 @@ namespace Microsoft.Net.Http.Headers // pointing to the next non-whitespace character after a delimiter. E.g. if called with a start index of 0 // for string "value , second_value", then after the call completes, 'index' must point to 's', i.e. the first // non-whitespace after the separator ','. - public abstract bool TryParseValue(StringSegment value, ref int index, out T parsedValue); + public abstract bool TryParseValue(StringSegment value, ref int index, [MaybeNull] out T parsedValue); + [return: MaybeNull] public T ParseValue(StringSegment value, ref int index) { // Index may be value.Length (e.g. both 0). This may be allowed for some headers (e.g. Accept but not @@ -46,23 +48,23 @@ namespace Microsoft.Net.Http.Headers return result; } - public virtual bool TryParseValues(IList values, out IList parsedValues) + public virtual bool TryParseValues(IList? values, [NotNullWhen(true)] out IList? parsedValues) { return TryParseValues(values, strict: false, parsedValues: out parsedValues); } - public virtual bool TryParseStrictValues(IList values, out IList parsedValues) + public virtual bool TryParseStrictValues(IList? values, [NotNullWhen(true)] out IList? parsedValues) { return TryParseValues(values, strict: true, parsedValues: out parsedValues); } - protected virtual bool TryParseValues(IList values, bool strict, out IList parsedValues) + protected virtual bool TryParseValues(IList? values, bool strict, [NotNullWhen(true)] out IList? parsedValues) { Contract.Assert(_supportsMultipleValues); // If a parser returns an empty list, it means there was no value, but that's valid (e.g. "Accept: "). The caller // can ignore the value. parsedValues = null; - List results = null; + List? results = null; if (values == null) { return false; @@ -70,7 +72,7 @@ namespace Microsoft.Net.Http.Headers for (var i = 0; i < values.Count; i++) { var value = values[i]; - int index = 0; + var index = 0; while (!string.IsNullOrEmpty(value) && index < value.Length) { @@ -106,17 +108,17 @@ namespace Microsoft.Net.Http.Headers return false; } - public virtual IList ParseValues(IList values) + public virtual IList ParseValues(IList? values) { return ParseValues(values, strict: false); } - public virtual IList ParseStrictValues(IList values) + public virtual IList ParseStrictValues(IList? values) { return ParseValues(values, strict: true); } - protected virtual IList ParseValues(IList values, bool strict) + protected virtual IList ParseValues(IList? values, bool strict) { Contract.Assert(_supportsMultipleValues); // If a parser returns an empty list, it means there was no value, but that's valid (e.g. "Accept: "). The caller @@ -164,9 +166,7 @@ namespace Microsoft.Net.Http.Headers // for most headers (custom types, string, etc.). public virtual string ToString(object value) { - Contract.Requires(value != null); - - return value.ToString(); + return value.ToString()!; } } } diff --git a/src/Http/Headers/src/HttpRuleParser.cs b/src/Http/Headers/src/HttpRuleParser.cs index 05f4a4576f..a3563e3fe6 100644 --- a/src/Http/Headers/src/HttpRuleParser.cs +++ b/src/Http/Headers/src/HttpRuleParser.cs @@ -93,7 +93,6 @@ namespace Microsoft.Net.Http.Headers [Pure] internal static int GetTokenLength(StringSegment input, int startIndex) { - Contract.Requires(input != null); Contract.Ensures((Contract.Result() >= 0) && (Contract.Result() <= (input.Length - startIndex))); if (startIndex >= input.Length) @@ -116,7 +115,6 @@ namespace Microsoft.Net.Http.Headers internal static int GetWhitespaceLength(StringSegment input, int startIndex) { - Contract.Requires(input != null); Contract.Ensures((Contract.Result() >= 0) && (Contract.Result() <= (input.Length - startIndex))); if (startIndex >= input.Length) @@ -160,7 +158,6 @@ namespace Microsoft.Net.Http.Headers internal static int GetNumberLength(StringSegment input, int startIndex, bool allowDecimal) { - Contract.Requires(input != null); Contract.Requires((startIndex >= 0) && (startIndex < input.Length)); Contract.Ensures((Contract.Result() >= 0) && (Contract.Result() <= (input.Length - startIndex))); @@ -213,7 +210,6 @@ namespace Microsoft.Net.Http.Headers // CHAR = internal static HttpParseResult GetQuotedPairLength(StringSegment input, int startIndex, out int length) { - Contract.Requires(input != null); Contract.Requires((startIndex >= 0) && (startIndex < input.Length)); Contract.Ensures((Contract.ValueAtReturn(out length) >= 0) && (Contract.ValueAtReturn(out length) <= (input.Length - startIndex))); diff --git a/src/Http/Headers/src/MediaTypeHeaderValue.cs b/src/Http/Headers/src/MediaTypeHeaderValue.cs index a7a39c904e..df3d96c0cf 100644 --- a/src/Http/Headers/src/MediaTypeHeaderValue.cs +++ b/src/Http/Headers/src/MediaTypeHeaderValue.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Diagnostics.Contracts; using System.Globalization; using System.Linq; @@ -29,12 +30,12 @@ namespace Microsoft.Net.Http.Headers private static readonly char[] PeriodCharacterArray = new char[] { PeriodCharacter }; private static readonly HttpHeaderParser SingleValueParser - = new GenericHeaderParser(false, GetMediaTypeLength); + = new GenericHeaderParser(false, GetMediaTypeLength!); private static readonly HttpHeaderParser MultipleValueParser - = new GenericHeaderParser(true, GetMediaTypeLength); + = new GenericHeaderParser(true, GetMediaTypeLength!); // Use a collection instead of a dictionary since we may have multiple parameters with the same name. - private ObjectCollection _parameters; + private ObjectCollection? _parameters; private StringSegment _mediaType; private bool _isReadOnly; @@ -108,7 +109,7 @@ namespace Microsoft.Net.Http.Headers /// Gets or sets the value of the Encoding parameter. Setting the Encoding will set /// the to . /// - public Encoding Encoding + public Encoding? Encoding { get { @@ -205,7 +206,7 @@ namespace Microsoft.Net.Http.Headers /// public double? Quality { - get { return HeaderUtilities.GetQuality(_parameters); } + get { return HeaderUtilities.GetQuality(Parameters); } set { HeaderUtilities.ThrowIfReadOnly(IsReadOnly); @@ -444,7 +445,7 @@ namespace Microsoft.Net.Http.Headers return builder.ToString(); } - public override bool Equals(object obj) + public override bool Equals(object? obj) { var other = obj as MediaTypeHeaderValue; @@ -471,7 +472,7 @@ namespace Microsoft.Net.Http.Headers public static MediaTypeHeaderValue Parse(StringSegment input) { var index = 0; - return SingleValueParser.ParseValue(input, ref index); + return SingleValueParser.ParseValue(input, ref index)!; } /// @@ -480,10 +481,10 @@ namespace Microsoft.Net.Http.Headers /// The with the media type. The media type constructed here must not have an y /// The parsed /// True if the value was successfully parsed. - public static bool TryParse(StringSegment input, out MediaTypeHeaderValue parsedValue) + public static bool TryParse(StringSegment input, [NotNullWhen(true)] out MediaTypeHeaderValue? parsedValue) { var index = 0; - return SingleValueParser.TryParseValue(input, ref index, out parsedValue); + return SingleValueParser.TryParseValue(input, ref index, out parsedValue!); } /// @@ -491,7 +492,7 @@ namespace Microsoft.Net.Http.Headers /// /// A list of media types /// The parsed . - public static IList ParseList(IList inputs) + public static IList ParseList(IList? inputs) { return MultipleValueParser.ParseValues(inputs); } @@ -502,7 +503,7 @@ namespace Microsoft.Net.Http.Headers /// /// A list of media types /// The parsed . - public static IList ParseStrictList(IList inputs) + public static IList ParseStrictList(IList? inputs) { return MultipleValueParser.ParseStrictValues(inputs); } @@ -513,7 +514,7 @@ namespace Microsoft.Net.Http.Headers /// A list of media types /// The parsed . /// True if the value was successfully parsed. - public static bool TryParseList(IList inputs, out IList parsedValues) + public static bool TryParseList(IList? inputs, [NotNullWhen(true)] out IList? parsedValues) { return MultipleValueParser.TryParseValues(inputs, out parsedValues); } @@ -524,12 +525,12 @@ namespace Microsoft.Net.Http.Headers /// A list of media types /// The parsed . /// True if the value was successfully parsed. - public static bool TryParseStrictList(IList inputs, out IList parsedValues) + public static bool TryParseStrictList(IList? inputs, [NotNullWhen(true)] out IList? parsedValues) { return MultipleValueParser.TryParseStrictValues(inputs, out parsedValues); } - private static int GetMediaTypeLength(StringSegment input, int startIndex, out MediaTypeHeaderValue parsedValue) + private static int GetMediaTypeLength(StringSegment input, int startIndex, out MediaTypeHeaderValue? parsedValue) { Contract.Requires(startIndex >= 0); @@ -550,7 +551,7 @@ namespace Microsoft.Net.Http.Headers var current = startIndex + mediaTypeLength; current = current + HttpRuleParser.GetWhitespaceLength(input, current); - MediaTypeHeaderValue mediaTypeHeader = null; + MediaTypeHeaderValue? mediaTypeHeader = null; // If we're not done and we have a parameter delimiter, then we have a list of parameters. if ((current < input.Length) && (input[current] == ';')) @@ -575,7 +576,7 @@ namespace Microsoft.Net.Http.Headers private static int GetMediaTypeExpressionLength(StringSegment input, int startIndex, out StringSegment mediaType) { - Contract.Requires((input != null) && (input.Length > 0) && (startIndex < input.Length)); + Contract.Requires((input.Length > 0) && (startIndex < input.Length)); // This method just parses the "type/subtype" string, it does not parse parameters. mediaType = null; diff --git a/src/Http/Headers/src/MediaTypeHeaderValueComparer.cs b/src/Http/Headers/src/MediaTypeHeaderValueComparer.cs index cc34640988..f442f6441f 100644 --- a/src/Http/Headers/src/MediaTypeHeaderValueComparer.cs +++ b/src/Http/Headers/src/MediaTypeHeaderValueComparer.cs @@ -12,17 +12,11 @@ namespace Microsoft.Net.Http.Headers /// public class MediaTypeHeaderValueComparer : IComparer { - private static readonly MediaTypeHeaderValueComparer _mediaTypeComparer = - new MediaTypeHeaderValueComparer(); - private MediaTypeHeaderValueComparer() { } - public static MediaTypeHeaderValueComparer QualityComparer - { - get { return _mediaTypeComparer; } - } + public static MediaTypeHeaderValueComparer QualityComparer { get; } = new MediaTypeHeaderValueComparer(); /// /// @@ -37,13 +31,23 @@ namespace Microsoft.Net.Http.Headers /// If we had a list of media types (comma separated): { text/*;q=0.8, text/*+json;q=0.8, */*;q=1, */*;q=0.8, text/plain;q=0.8 } /// Sorting them using Compare would return: { */*;q=0.8, text/*;q=0.8, text/*+json;q=0.8, text/plain;q=0.8, */*;q=1 } /// - public int Compare(MediaTypeHeaderValue mediaType1, MediaTypeHeaderValue mediaType2) + public int Compare(MediaTypeHeaderValue? mediaType1, MediaTypeHeaderValue? mediaType2) { if (object.ReferenceEquals(mediaType1, mediaType2)) { return 0; } + if (mediaType1 is null) + { + return -1; + } + + if (mediaType2 is null) + { + return 1; + } + var returnValue = CompareBasedOnQualityFactor(mediaType1, mediaType2); if (returnValue == 0) diff --git a/src/Http/Headers/src/Microsoft.Net.Http.Headers.csproj b/src/Http/Headers/src/Microsoft.Net.Http.Headers.csproj index d0c27e7ed7..afde882724 100644 --- a/src/Http/Headers/src/Microsoft.Net.Http.Headers.csproj +++ b/src/Http/Headers/src/Microsoft.Net.Http.Headers.csproj @@ -9,6 +9,7 @@ true http false + enable diff --git a/src/Http/Headers/src/NameValueHeaderValue.cs b/src/Http/Headers/src/NameValueHeaderValue.cs index 58d337d55a..9ef6283cd9 100644 --- a/src/Http/Headers/src/NameValueHeaderValue.cs +++ b/src/Http/Headers/src/NameValueHeaderValue.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Diagnostics.Contracts; using System.Globalization; using System.Text; @@ -16,9 +17,9 @@ namespace Microsoft.Net.Http.Headers public class NameValueHeaderValue { private static readonly HttpHeaderParser SingleValueParser - = new GenericHeaderParser(false, GetNameValueLength); + = new GenericHeaderParser(false, GetNameValueLength!); internal static readonly HttpHeaderParser MultipleValueParser - = new GenericHeaderParser(true, GetNameValueLength); + = new GenericHeaderParser(true, GetNameValueLength!); private StringSegment _name; private StringSegment _value; @@ -109,7 +110,7 @@ namespace Microsoft.Net.Http.Headers return nameHashCode; } - public override bool Equals(object obj) + public override bool Equals(object? obj) { var other = obj as NameValueHeaderValue; @@ -168,31 +169,31 @@ namespace Microsoft.Net.Http.Headers public static NameValueHeaderValue Parse(StringSegment input) { var index = 0; - return SingleValueParser.ParseValue(input, ref index); + return SingleValueParser.ParseValue(input, ref index)!; } - public static bool TryParse(StringSegment input, out NameValueHeaderValue parsedValue) + public static bool TryParse(StringSegment input, [NotNullWhen(true)] out NameValueHeaderValue? parsedValue) { var index = 0; - return SingleValueParser.TryParseValue(input, ref index, out parsedValue); + return SingleValueParser.TryParseValue(input, ref index, out parsedValue!); } - public static IList ParseList(IList input) + public static IList ParseList(IList? input) { return MultipleValueParser.ParseValues(input); } - public static IList ParseStrictList(IList input) + public static IList ParseStrictList(IList? input) { return MultipleValueParser.ParseStrictValues(input); } - public static bool TryParseList(IList input, out IList parsedValues) + public static bool TryParseList(IList? input, [NotNullWhen(true)] out IList? parsedValues) { return MultipleValueParser.TryParseValues(input, out parsedValues); } - public static bool TryParseStrictList(IList input, out IList parsedValues) + public static bool TryParseStrictList(IList? input, [NotNullWhen(true)] out IList? parsedValues) { return MultipleValueParser.TryParseStrictValues(input, out parsedValues); } @@ -207,7 +208,7 @@ namespace Microsoft.Net.Http.Headers } internal static void ToString( - IList values, + IList? values, char separator, bool leadingSeparator, StringBuilder destination) @@ -235,7 +236,7 @@ namespace Microsoft.Net.Http.Headers } } - internal static string ToString(IList values, char separator, bool leadingSeparator) + internal static string? ToString(IList? values, char separator, bool leadingSeparator) { if ((values == null) || (values.Count == 0)) { @@ -249,7 +250,7 @@ namespace Microsoft.Net.Http.Headers return sb.ToString(); } - internal static int GetHashCode(IList values) + internal static int GetHashCode(IList? values) { if ((values == null) || (values.Count == 0)) { @@ -264,9 +265,8 @@ namespace Microsoft.Net.Http.Headers return result; } - private static int GetNameValueLength(StringSegment input, int startIndex, out NameValueHeaderValue parsedValue) + private static int GetNameValueLength(StringSegment input, int startIndex, out NameValueHeaderValue? parsedValue) { - Contract.Requires(input != null); Contract.Requires(startIndex >= 0); parsedValue = null; @@ -323,7 +323,6 @@ namespace Microsoft.Net.Http.Headers char delimiter, IList nameValueCollection) { - Contract.Requires(nameValueCollection != null); Contract.Requires(startIndex >= 0); if ((StringSegment.IsNullOrEmpty(input)) || (startIndex >= input.Length)) @@ -334,8 +333,7 @@ namespace Microsoft.Net.Http.Headers var current = startIndex + HttpRuleParser.GetWhitespaceLength(input, startIndex); while (true) { - NameValueHeaderValue parameter = null; - var nameValueLength = GetNameValueLength(input, current, out parameter); + var nameValueLength = GetNameValueLength(input, current, out var parameter); if (nameValueLength == 0) { @@ -343,7 +341,7 @@ namespace Microsoft.Net.Http.Headers return current - startIndex; } - nameValueCollection.Add(parameter); + nameValueCollection!.Add(parameter!); current = current + nameValueLength; current = current + HttpRuleParser.GetWhitespaceLength(input, current); @@ -359,9 +357,9 @@ namespace Microsoft.Net.Http.Headers } } - public static NameValueHeaderValue Find(IList values, StringSegment name) + public static NameValueHeaderValue? Find(IList? values, StringSegment name) { - Contract.Requires((name != null) && (name.Length > 0)); + Contract.Requires(name.Length > 0); if ((values == null) || (values.Count == 0)) { @@ -381,8 +379,6 @@ namespace Microsoft.Net.Http.Headers internal static int GetValueLength(StringSegment input, int startIndex) { - Contract.Requires(input != null); - if (startIndex >= input.Length) { return 0; diff --git a/src/Http/Headers/src/ObjectCollection.cs b/src/Http/Headers/src/ObjectCollection.cs index f46b2dd743..c322802440 100644 --- a/src/Http/Headers/src/ObjectCollection.cs +++ b/src/Http/Headers/src/ObjectCollection.cs @@ -21,7 +21,7 @@ namespace Microsoft.Net.Http.Headers // We need to create a 'read-only' inner list for Collection to do the right // thing. - private static IList CreateInnerList(bool isReadOnly, IEnumerable other = null) + private static IList CreateInnerList(bool isReadOnly, IEnumerable? other = null) { var list = other == null ? new List() : new List(other); if (isReadOnly) @@ -78,4 +78,4 @@ namespace Microsoft.Net.Http.Headers } } } -} \ No newline at end of file +} diff --git a/src/Http/Headers/src/RangeConditionHeaderValue.cs b/src/Http/Headers/src/RangeConditionHeaderValue.cs index b1d6513e2e..ebe21f59b8 100644 --- a/src/Http/Headers/src/RangeConditionHeaderValue.cs +++ b/src/Http/Headers/src/RangeConditionHeaderValue.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Diagnostics.CodeAnalysis; using System.Diagnostics.Contracts; using Microsoft.Extensions.Primitives; @@ -10,10 +11,10 @@ namespace Microsoft.Net.Http.Headers public class RangeConditionHeaderValue { private static readonly HttpHeaderParser Parser - = new GenericHeaderParser(false, GetRangeConditionLength); + = new GenericHeaderParser(false, GetRangeConditionLength!); private DateTimeOffset? _lastModified; - private EntityTagHeaderValue _entityTag; + private EntityTagHeaderValue? _entityTag; private RangeConditionHeaderValue() { @@ -25,7 +26,7 @@ namespace Microsoft.Net.Http.Headers _lastModified = lastModified; } - public RangeConditionHeaderValue(EntityTagHeaderValue entityTag) + public RangeConditionHeaderValue(EntityTagHeaderValue? entityTag) { if (entityTag == null) { @@ -35,7 +36,7 @@ namespace Microsoft.Net.Http.Headers _entityTag = entityTag; } - public RangeConditionHeaderValue(string entityTag) + public RangeConditionHeaderValue(string? entityTag) : this(new EntityTagHeaderValue(entityTag)) { } @@ -45,7 +46,7 @@ namespace Microsoft.Net.Http.Headers get { return _lastModified; } } - public EntityTagHeaderValue EntityTag + public EntityTagHeaderValue? EntityTag { get { return _entityTag; } } @@ -59,7 +60,7 @@ namespace Microsoft.Net.Http.Headers return _entityTag.ToString(); } - public override bool Equals(object obj) + public override bool Equals(object? obj) { var other = obj as RangeConditionHeaderValue; @@ -89,16 +90,16 @@ namespace Microsoft.Net.Http.Headers public static RangeConditionHeaderValue Parse(StringSegment input) { var index = 0; - return Parser.ParseValue(input, ref index); + return Parser.ParseValue(input, ref index)!; } - public static bool TryParse(StringSegment input, out RangeConditionHeaderValue parsedValue) + public static bool TryParse(StringSegment input, [NotNullWhen(true)] out RangeConditionHeaderValue? parsedValue) { var index = 0; - return Parser.TryParseValue(input, ref index, out parsedValue); + return Parser.TryParseValue(input, ref index, out parsedValue!); } - private static int GetRangeConditionLength(StringSegment input, int startIndex, out RangeConditionHeaderValue parsedValue) + private static int GetRangeConditionLength(StringSegment input, int startIndex, out RangeConditionHeaderValue? parsedValue) { Contract.Requires(startIndex >= 0); @@ -114,7 +115,7 @@ namespace Microsoft.Net.Http.Headers // Caller must remove leading whitespaces. DateTimeOffset date = DateTimeOffset.MinValue; - EntityTagHeaderValue entityTag = null; + EntityTagHeaderValue? entityTag = null; // Entity tags are quoted strings optionally preceded by "W/". By looking at the first two character we // can determine whether the string is en entity tag or a date. @@ -164,4 +165,4 @@ namespace Microsoft.Net.Http.Headers return current - startIndex; } } -} \ No newline at end of file +} diff --git a/src/Http/Headers/src/RangeHeaderValue.cs b/src/Http/Headers/src/RangeHeaderValue.cs index 67d671267b..8247c3ff60 100644 --- a/src/Http/Headers/src/RangeHeaderValue.cs +++ b/src/Http/Headers/src/RangeHeaderValue.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Diagnostics.Contracts; using System.Text; using Microsoft.Extensions.Primitives; @@ -12,10 +13,10 @@ namespace Microsoft.Net.Http.Headers public class RangeHeaderValue { private static readonly HttpHeaderParser Parser - = new GenericHeaderParser(false, GetRangeLength); + = new GenericHeaderParser(false, GetRangeLength!); private StringSegment _unit; - private ICollection _ranges; + private ICollection? _ranges; public RangeHeaderValue() { @@ -77,7 +78,7 @@ namespace Microsoft.Net.Http.Headers return sb.ToString(); } - public override bool Equals(object obj) + public override bool Equals(object? obj) { var other = obj as RangeHeaderValue; @@ -105,16 +106,16 @@ namespace Microsoft.Net.Http.Headers public static RangeHeaderValue Parse(StringSegment input) { var index = 0; - return Parser.ParseValue(input, ref index); + return Parser.ParseValue(input, ref index)!; } - public static bool TryParse(StringSegment input, out RangeHeaderValue parsedValue) + public static bool TryParse(StringSegment input, [NotNullWhen(true)] out RangeHeaderValue parsedValue) { var index = 0; - return Parser.TryParseValue(input, ref index, out parsedValue); + return Parser.TryParseValue(input, ref index, out parsedValue!); } - private static int GetRangeLength(StringSegment input, int startIndex, out RangeHeaderValue parsedValue) + private static int GetRangeLength(StringSegment input, int startIndex, out RangeHeaderValue? parsedValue) { Contract.Requires(startIndex >= 0); diff --git a/src/Http/Headers/src/RangeItemHeaderValue.cs b/src/Http/Headers/src/RangeItemHeaderValue.cs index 010f2da1e0..edc4d4b2e0 100644 --- a/src/Http/Headers/src/RangeItemHeaderValue.cs +++ b/src/Http/Headers/src/RangeItemHeaderValue.cs @@ -61,7 +61,7 @@ namespace Microsoft.Net.Http.Headers _to.GetValueOrDefault().ToString(NumberFormatInfo.InvariantInfo); } - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (obj is RangeItemHeaderValue other) { @@ -91,7 +91,6 @@ namespace Microsoft.Net.Http.Headers int startIndex, ICollection rangeCollection) { - Contract.Requires(rangeCollection != null); Contract.Requires(startIndex >= 0); Contract.Ensures((Contract.Result() == 0) || (rangeCollection.Count > 0), "If we can parse the string, then we expect to have at least one range item."); @@ -111,7 +110,7 @@ namespace Microsoft.Net.Http.Headers return 0; } - RangeItemHeaderValue range = null; + RangeItemHeaderValue? range = null; while (true) { var rangeLength = GetRangeItemLength(input, current, out range); @@ -121,7 +120,7 @@ namespace Microsoft.Net.Http.Headers return 0; } - rangeCollection.Add(range); + rangeCollection!.Add(range!); current = current + rangeLength; current = HeaderUtilities.GetNextNonEmptyOrWhitespaceIndex(input, current, true, out separatorFound); @@ -140,7 +139,7 @@ namespace Microsoft.Net.Http.Headers } } - internal static int GetRangeItemLength(StringSegment input, int startIndex, out RangeItemHeaderValue parsedValue) + internal static int GetRangeItemLength(StringSegment input, int startIndex, out RangeItemHeaderValue? parsedValue) { Contract.Requires(startIndex >= 0); diff --git a/src/Http/Headers/src/SetCookieHeaderValue.cs b/src/Http/Headers/src/SetCookieHeaderValue.cs index cdf12381aa..5e7c28564e 100644 --- a/src/Http/Headers/src/SetCookieHeaderValue.cs +++ b/src/Http/Headers/src/SetCookieHeaderValue.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Diagnostics.Contracts; using System.Text; using Microsoft.Extensions.Primitives; @@ -31,9 +32,9 @@ namespace Microsoft.Net.Http.Headers private const string ExpiresDateFormat = "r"; private static readonly HttpHeaderParser SingleValueParser - = new GenericHeaderParser(false, GetSetCookieLength); + = new GenericHeaderParser(false, GetSetCookieLength!); private static readonly HttpHeaderParser MultipleValueParser - = new GenericHeaderParser(true, GetSetCookieLength); + = new GenericHeaderParser(true, GetSetCookieLength!); private StringSegment _name; private StringSegment _value; @@ -103,8 +104,8 @@ namespace Microsoft.Net.Http.Headers { var length = _name.Length + EqualsToken.Length + _value.Length; - string maxAge = null; - string sameSite = null; + string? maxAge = null; + string? sameSite = null; if (Expires.HasValue) { @@ -296,37 +297,37 @@ namespace Microsoft.Net.Http.Headers public static SetCookieHeaderValue Parse(StringSegment input) { var index = 0; - return SingleValueParser.ParseValue(input, ref index); + return SingleValueParser.ParseValue(input, ref index)!; } - public static bool TryParse(StringSegment input, out SetCookieHeaderValue parsedValue) + public static bool TryParse(StringSegment input, [NotNullWhen(true)] out SetCookieHeaderValue? parsedValue) { var index = 0; - return SingleValueParser.TryParseValue(input, ref index, out parsedValue); + return SingleValueParser.TryParseValue(input, ref index, out parsedValue!); } - public static IList ParseList(IList inputs) + public static IList ParseList(IList? inputs) { return MultipleValueParser.ParseValues(inputs); } - public static IList ParseStrictList(IList inputs) + public static IList ParseStrictList(IList? inputs) { return MultipleValueParser.ParseStrictValues(inputs); } - public static bool TryParseList(IList inputs, out IList parsedValues) + public static bool TryParseList(IList? inputs, [NotNullWhen(true)] out IList? parsedValues) { return MultipleValueParser.TryParseValues(inputs, out parsedValues); } - public static bool TryParseStrictList(IList inputs, out IList parsedValues) + public static bool TryParseStrictList(IList? inputs, [NotNullWhen(true)] out IList? parsedValues) { return MultipleValueParser.TryParseStrictValues(inputs, out parsedValues); } // name=value; expires=Sun, 06 Nov 1994 08:49:37 GMT; max-age=86400; domain=domain1; path=path1; secure; samesite={Strict|Lax|None}; httponly - private static int GetSetCookieLength(StringSegment input, int startIndex, out SetCookieHeaderValue parsedValue) + private static int GetSetCookieLength(StringSegment input, int startIndex, out SetCookieHeaderValue? parsedValue) { Contract.Requires(startIndex >= 0); var offset = startIndex; @@ -537,7 +538,7 @@ namespace Microsoft.Net.Http.Headers return result; } - public override bool Equals(object obj) + public override bool Equals(object? obj) { var other = obj as SetCookieHeaderValue; diff --git a/src/Http/Headers/src/StringWithQualityHeaderValue.cs b/src/Http/Headers/src/StringWithQualityHeaderValue.cs index 153643b361..18fe33975c 100644 --- a/src/Http/Headers/src/StringWithQualityHeaderValue.cs +++ b/src/Http/Headers/src/StringWithQualityHeaderValue.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Diagnostics.Contracts; using System.Globalization; using Microsoft.Extensions.Primitives; @@ -12,9 +13,9 @@ namespace Microsoft.Net.Http.Headers public class StringWithQualityHeaderValue { private static readonly HttpHeaderParser SingleValueParser - = new GenericHeaderParser(false, GetStringWithQualityLength); + = new GenericHeaderParser(false, GetStringWithQualityLength!); private static readonly HttpHeaderParser MultipleValueParser - = new GenericHeaderParser(true, GetStringWithQualityLength); + = new GenericHeaderParser(true, GetStringWithQualityLength!); private StringSegment _value; private double? _quality; @@ -64,7 +65,7 @@ namespace Microsoft.Net.Http.Headers return _value.ToString(); } - public override bool Equals(object obj) + public override bool Equals(object? obj) { var other = obj as StringWithQualityHeaderValue; @@ -106,36 +107,36 @@ namespace Microsoft.Net.Http.Headers public static StringWithQualityHeaderValue Parse(StringSegment input) { var index = 0; - return SingleValueParser.ParseValue(input, ref index); + return SingleValueParser.ParseValue(input, ref index)!; } - public static bool TryParse(StringSegment input, out StringWithQualityHeaderValue parsedValue) + public static bool TryParse(StringSegment input, [NotNullWhen(true)] out StringWithQualityHeaderValue parsedValue) { var index = 0; - return SingleValueParser.TryParseValue(input, ref index, out parsedValue); + return SingleValueParser.TryParseValue(input, ref index, out parsedValue!); } - public static IList ParseList(IList input) + public static IList ParseList(IList? input) { return MultipleValueParser.ParseValues(input); } - public static IList ParseStrictList(IList input) + public static IList ParseStrictList(IList? input) { return MultipleValueParser.ParseStrictValues(input); } - public static bool TryParseList(IList input, out IList parsedValues) + public static bool TryParseList(IList? input, [NotNullWhen(true)] out IList? parsedValues) { return MultipleValueParser.TryParseValues(input, out parsedValues); } - public static bool TryParseStrictList(IList input, out IList parsedValues) + public static bool TryParseStrictList(IList? input, [NotNullWhen(true)] out IList? parsedValues) { return MultipleValueParser.TryParseStrictValues(input, out parsedValues); } - private static int GetStringWithQualityLength(StringSegment input, int startIndex, out StringWithQualityHeaderValue parsedValue) + private static int GetStringWithQualityLength(StringSegment input, int startIndex, out StringWithQualityHeaderValue? parsedValue) { Contract.Requires(startIndex >= 0); diff --git a/src/Http/Headers/src/StringWithQualityHeaderValueComparer.cs b/src/Http/Headers/src/StringWithQualityHeaderValueComparer.cs index 961cc07841..9655414a05 100644 --- a/src/Http/Headers/src/StringWithQualityHeaderValueComparer.cs +++ b/src/Http/Headers/src/StringWithQualityHeaderValueComparer.cs @@ -16,17 +16,11 @@ namespace Microsoft.Net.Http.Headers /// public class StringWithQualityHeaderValueComparer : IComparer { - private static readonly StringWithQualityHeaderValueComparer _qualityComparer = - new StringWithQualityHeaderValueComparer(); - private StringWithQualityHeaderValueComparer() { } - public static StringWithQualityHeaderValueComparer QualityComparer - { - get { return _qualityComparer; } - } + public static StringWithQualityHeaderValueComparer QualityComparer { get; } = new StringWithQualityHeaderValueComparer(); /// /// Compares two based on their quality value @@ -40,8 +34,8 @@ namespace Microsoft.Net.Http.Headers /// The second value to compare /// The result of the comparison. public int Compare( - StringWithQualityHeaderValue stringWithQuality1, - StringWithQualityHeaderValue stringWithQuality2) + StringWithQualityHeaderValue? stringWithQuality1, + StringWithQualityHeaderValue? stringWithQuality2) { if (stringWithQuality1 == null) { diff --git a/src/Http/Headers/test/CacheControlHeaderValueTest.cs b/src/Http/Headers/test/CacheControlHeaderValueTest.cs index 51e8ce5f58..8bca38b903 100644 --- a/src/Http/Headers/test/CacheControlHeaderValueTest.cs +++ b/src/Http/Headers/test/CacheControlHeaderValueTest.cs @@ -62,7 +62,7 @@ namespace Microsoft.Net.Http.Headers // NameValueHeaderValue collection property Assert.NotNull(cacheControl.Extensions); - Assert.Throws(() => cacheControl.Extensions.Add(null)); + Assert.Throws(() => cacheControl.Extensions.Add(null!)); cacheControl.Extensions.Add(new NameValueHeaderValue("name", "value")); Assert.Equal(1, cacheControl.Extensions.Count); Assert.Equal(new NameValueHeaderValue("name", "value"), cacheControl.Extensions.First()); @@ -351,9 +351,9 @@ namespace Microsoft.Net.Http.Headers cacheControl2.NoCacheHeaders.Add("token1"); cacheControl2.NoCacheHeaders.Add("token2"); - CompareValues(cacheControl1, cacheControl2, false); + CompareValues(cacheControl1!, cacheControl2, false); - cacheControl1.NoCacheHeaders.Add("token1"); + cacheControl1!.NoCacheHeaders.Add("token1"); CompareValues(cacheControl1, cacheControl2, true); // Since NoCache and Private generate different hash codes, even if NoCacheHeaders and PrivateHeaders @@ -569,28 +569,26 @@ namespace Microsoft.Net.Http.Headers Assert.Equal(areEqual, y.Equals(x)); } - private void CheckValidParse(string input, CacheControlHeaderValue expectedResult) + private void CheckValidParse(string? input, CacheControlHeaderValue expectedResult) { var result = CacheControlHeaderValue.Parse(input); Assert.Equal(expectedResult, result); } - private void CheckInvalidParse(string input) + private void CheckInvalidParse(string? input) { Assert.Throws(() => CacheControlHeaderValue.Parse(input)); } - private void CheckValidTryParse(string input, CacheControlHeaderValue expectedResult) + private void CheckValidTryParse(string? input, CacheControlHeaderValue expectedResult) { - CacheControlHeaderValue result = null; - Assert.True(CacheControlHeaderValue.TryParse(input, out result)); + Assert.True(CacheControlHeaderValue.TryParse(input, out var result)); Assert.Equal(expectedResult, result); } - private void CheckInvalidTryParse(string input) + private void CheckInvalidTryParse(string? input) { - CacheControlHeaderValue result = null; - Assert.False(CacheControlHeaderValue.TryParse(input, out result)); + Assert.False(CacheControlHeaderValue.TryParse(input, out var result)); Assert.Null(result); } diff --git a/src/Http/Headers/test/ContentDispositionHeaderValueTest.cs b/src/Http/Headers/test/ContentDispositionHeaderValueTest.cs index 6076b2cc15..4d0b1b7cf7 100644 --- a/src/Http/Headers/test/ContentDispositionHeaderValueTest.cs +++ b/src/Http/Headers/test/ContentDispositionHeaderValueTest.cs @@ -58,7 +58,7 @@ namespace Microsoft.Net.Http.Headers public void Parameters_AddNull_Throw() { var contentDisposition = new ContentDispositionHeaderValue("inline"); - Assert.Throws(() => contentDisposition.Parameters.Add(null)); + Assert.Throws(() => contentDisposition.Parameters.Add(null!)); } [Fact] @@ -414,7 +414,7 @@ namespace Microsoft.Net.Http.Headers Assert.False(contentDisposition1.Equals(contentDisposition2), "No params vs. name."); Assert.False(contentDisposition2.Equals(contentDisposition1), "name vs. no params."); Assert.False(contentDisposition1.Equals(null), "No params vs. ."); - Assert.False(contentDisposition1.Equals(contentDisposition3), "No params vs. custom param."); + Assert.False(contentDisposition1!.Equals(contentDisposition3), "No params vs. custom param."); Assert.False(contentDisposition2.Equals(contentDisposition3), "name vs. custom param."); Assert.True(contentDisposition1.Equals(contentDisposition4), "Different casing."); Assert.True(contentDisposition2.Equals(contentDisposition5), "Different casing in name."); @@ -615,28 +615,26 @@ namespace Microsoft.Net.Http.Headers public bool Valid { get; } } - private void CheckValidParse(string input, ContentDispositionHeaderValue expectedResult) + private void CheckValidParse(string? input, ContentDispositionHeaderValue expectedResult) { var result = ContentDispositionHeaderValue.Parse(input); Assert.Equal(expectedResult, result); } - private void CheckInvalidParse(string input) + private void CheckInvalidParse(string? input) { Assert.Throws(() => ContentDispositionHeaderValue.Parse(input)); } - private void CheckValidTryParse(string input, ContentDispositionHeaderValue expectedResult) + private void CheckValidTryParse(string? input, ContentDispositionHeaderValue expectedResult) { - ContentDispositionHeaderValue result = null; - Assert.True(ContentDispositionHeaderValue.TryParse(input, out result), input); + Assert.True(ContentDispositionHeaderValue.TryParse(input, out var result), input); Assert.Equal(expectedResult, result); } - private void CheckInvalidTryParse(string input) + private void CheckInvalidTryParse(string? input) { - ContentDispositionHeaderValue result = null; - Assert.False(ContentDispositionHeaderValue.TryParse(input, out result), input); + Assert.False(ContentDispositionHeaderValue.TryParse(input, out var result), input); Assert.Null(result); } diff --git a/src/Http/Headers/test/ContentRangeHeaderValueTest.cs b/src/Http/Headers/test/ContentRangeHeaderValueTest.cs index d8abdbdbf6..061cabd4a6 100644 --- a/src/Http/Headers/test/ContentRangeHeaderValueTest.cs +++ b/src/Http/Headers/test/ContentRangeHeaderValueTest.cs @@ -132,7 +132,7 @@ namespace Microsoft.Net.Http.Headers var range8 = new ContentRangeHeaderValue(1, 2, 6); Assert.False(range1.Equals(null), "bytes 1-2/5 vs. "); - Assert.False(range1.Equals(range2), "bytes 1-2/5 vs. bytes 1-2/*"); + Assert.False(range1!.Equals(range2), "bytes 1-2/5 vs. bytes 1-2/*"); Assert.False(range1.Equals(range3), "bytes 1-2/5 vs. bytes */5"); Assert.False(range2.Equals(range3), "bytes 1-2/* vs. bytes */5"); Assert.True(range1.Equals(range4), "bytes 1-2/5 vs. BYTES 1-2/5"); @@ -193,7 +193,7 @@ namespace Microsoft.Net.Http.Headers [InlineData("bytes 1-9999999999999999999/3")] [InlineData("bytes 9999999999999999999-3/3")] [InlineData("bytes 1-2/9999999999999999999")] - public void Parse_SetOfInvalidValueStrings_Throws(string input) + public void Parse_SetOfInvalidValueStrings_Throws(string? input) { Assert.Throws(() => ContentRangeHeaderValue.Parse(input)); } @@ -212,8 +212,7 @@ namespace Microsoft.Net.Http.Headers // Note that we don't have a public constructor for value 'bytes */*' since the RFC doesn't mention a // scenario for it. However, if a server returns this value, we're flexible and accept it. - ContentRangeHeaderValue result = null; - Assert.True(ContentRangeHeaderValue.TryParse("bytes */*", out result)); + Assert.True(ContentRangeHeaderValue.TryParse("bytes */*", out var result)); Assert.Equal("bytes", result.Unit); Assert.Null(result.From); Assert.Null(result.To); @@ -249,23 +248,21 @@ namespace Microsoft.Net.Http.Headers [InlineData("bytes 1-9999999999999999999/3")] [InlineData("bytes 9999999999999999999-3/3")] [InlineData("bytes 1-2/9999999999999999999")] - public void TryParse_SetOfInvalidValueStrings_ReturnsFalse(string input) + public void TryParse_SetOfInvalidValueStrings_ReturnsFalse(string? input) { - ContentRangeHeaderValue result = null; - Assert.False(ContentRangeHeaderValue.TryParse(input, out result)); + Assert.False(ContentRangeHeaderValue.TryParse(input, out var result)); Assert.Null(result); } - private void CheckValidParse(string input, ContentRangeHeaderValue expectedResult) + private void CheckValidParse(string? input, ContentRangeHeaderValue expectedResult) { var result = ContentRangeHeaderValue.Parse(input); Assert.Equal(expectedResult, result); } - private void CheckValidTryParse(string input, ContentRangeHeaderValue expectedResult) + private void CheckValidTryParse(string? input, ContentRangeHeaderValue expectedResult) { - ContentRangeHeaderValue result = null; - Assert.True(ContentRangeHeaderValue.TryParse(input, out result)); + Assert.True(ContentRangeHeaderValue.TryParse(input, out var result)); Assert.Equal(expectedResult, result); } } diff --git a/src/Http/Headers/test/CookieHeaderValueTest.cs b/src/Http/Headers/test/CookieHeaderValueTest.cs index edd55bb7ab..4d13310fe7 100644 --- a/src/Http/Headers/test/CookieHeaderValueTest.cs +++ b/src/Http/Headers/test/CookieHeaderValueTest.cs @@ -80,11 +80,11 @@ namespace Microsoft.Net.Http.Headers } } - public static TheoryData, string[]> ListOfCookieHeaderDataSet + public static TheoryData, string?[]> ListOfCookieHeaderDataSet { get { - var dataset = new TheoryData, string[]>(); + var dataset = new TheoryData, string?[]>(); var header1 = new CookieHeaderValue("name1", "n1=v1&n2=v2&n3=v3"); var string1 = "name1=n1=v1&n2=v2&n3=v3"; @@ -99,7 +99,7 @@ namespace Microsoft.Net.Http.Headers dataset.Add(new[] { header1 }.ToList(), new[] { string1 }); dataset.Add(new[] { header1, header1 }.ToList(), new[] { string1, string1 }); - dataset.Add(new[] { header1, header1 }.ToList(), new[] { string1, null, "", " ", ";", " , ", string1 }); + dataset.Add(new[] { header1, header1 }.ToList(), new [] { string1, null, "", " ", ";", " , ", string1 }); dataset.Add(new[] { header2 }.ToList(), new[] { string2 }); dataset.Add(new[] { header1, header2 }.ToList(), new[] { string1, string2 }); dataset.Add(new[] { header1, header2 }.ToList(), new[] { string1 + ", " + string2 }); @@ -112,11 +112,11 @@ namespace Microsoft.Net.Http.Headers } } - public static TheoryData, string[]> ListWithInvalidCookieHeaderDataSet + public static TheoryData?, string?[]> ListWithInvalidCookieHeaderDataSet { get { - var dataset = new TheoryData, string[]>(); + var dataset = new TheoryData?, string?[]>(); var header1 = new CookieHeaderValue("name1", "n1=v1&n2=v2&n3=v3"); var validString1 = "name1=n1=v1&n2=v2&n3=v3"; @@ -226,7 +226,7 @@ namespace Microsoft.Net.Http.Headers Assert.True(CookieHeaderValue.TryParse(expectedValue, out var header)); Assert.Equal(cookie, header); - Assert.Equal(expectedValue, header.ToString()); + Assert.Equal(expectedValue, header!.ToString()); } [Theory] diff --git a/src/Http/Headers/test/DateParserTest.cs b/src/Http/Headers/test/DateParserTest.cs index 5c211c4368..9801a5f501 100644 --- a/src/Http/Headers/test/DateParserTest.cs +++ b/src/Http/Headers/test/DateParserTest.cs @@ -35,9 +35,9 @@ namespace Microsoft.Net.Http.Headers Assert.Equal(new DateTimeOffset(), result); } - public static IEnumerable InvalidStringData() + public static IEnumerable InvalidStringData() { - yield return new object[] { null }; + yield return new object?[] { null }; yield return new object[] { string.Empty }; yield return new object[] { " " }; yield return new object[] { "!!Sunday, 06-Nov-94 08:49:37 GMT" }; diff --git a/src/Http/Headers/test/EntityTagHeaderValueTest.cs b/src/Http/Headers/test/EntityTagHeaderValueTest.cs index b4ae186fb4..7320b09128 100644 --- a/src/Http/Headers/test/EntityTagHeaderValueTest.cs +++ b/src/Http/Headers/test/EntityTagHeaderValueTest.cs @@ -92,7 +92,7 @@ namespace Microsoft.Net.Http.Headers Assert.False(etag1.Equals(etag2), "Different casing."); Assert.False(etag2.Equals(etag1), "Different casing."); Assert.False(etag1.Equals(null), "tag vs. ."); - Assert.False(etag1.Equals(etag3), "strong vs. weak."); + Assert.False(etag1!.Equals(etag3), "strong vs. weak."); Assert.False(etag3.Equals(etag1), "weak vs. strong."); Assert.False(etag1.Equals(etag4), "tag vs. tag1."); Assert.False(etag1.Equals(etag6), "tag vs. *."); @@ -264,8 +264,7 @@ namespace Microsoft.Net.Http.Headers [Fact] public void TryParseList_NullOrEmptyArray_ReturnsFalse() { - IList results = null; - Assert.False(EntityTagHeaderValue.TryParseList(null, out results)); + Assert.False(EntityTagHeaderValue.TryParseList(null, out var results)); Assert.False(EntityTagHeaderValue.TryParseList(new string[0], out results)); Assert.False(EntityTagHeaderValue.TryParseList(new string[] { "" }, out results)); } @@ -351,8 +350,7 @@ namespace Microsoft.Net.Http.Headers "\"tag\", \"tag\"", "W/\"tag\"", }; - IList results; - Assert.True(EntityTagHeaderValue.TryParseList(inputs, out results)); + Assert.True(EntityTagHeaderValue.TryParseList(inputs, out var results)); var expectedResults = new[] { new EntityTagHeaderValue("\"tag\""), @@ -384,8 +382,7 @@ namespace Microsoft.Net.Http.Headers "\"tag\", \"tag\"", "W/\"tag\"", }; - IList results; - Assert.True(EntityTagHeaderValue.TryParseStrictList(inputs, out results)); + Assert.True(EntityTagHeaderValue.TryParseStrictList(inputs, out var results)); var expectedResults = new[] { new EntityTagHeaderValue("\"tag\""), @@ -465,8 +462,7 @@ namespace Microsoft.Net.Http.Headers "\"tag\", \"tag\"", "W/\"tag\"", }; - IList results; - Assert.True(EntityTagHeaderValue.TryParseList(inputs, out results)); + Assert.True(EntityTagHeaderValue.TryParseList(inputs, out var results)); var expectedResults = new[] { new EntityTagHeaderValue("\"tag\""), @@ -496,32 +492,29 @@ namespace Microsoft.Net.Http.Headers "\"tag\", \"tag\"", "W/\"tag\"", }; - IList results; - Assert.False(EntityTagHeaderValue.TryParseStrictList(inputs, out results)); + Assert.False(EntityTagHeaderValue.TryParseStrictList(inputs, out var results)); } - private void CheckValidParse(string input, EntityTagHeaderValue expectedResult) + private void CheckValidParse(string? input, EntityTagHeaderValue expectedResult) { var result = EntityTagHeaderValue.Parse(input); Assert.Equal(expectedResult, result); } - private void CheckInvalidParse(string input) + private void CheckInvalidParse(string? input) { Assert.Throws(() => EntityTagHeaderValue.Parse(input)); } - private void CheckValidTryParse(string input, EntityTagHeaderValue expectedResult) + private void CheckValidTryParse(string? input, EntityTagHeaderValue expectedResult) { - EntityTagHeaderValue result = null; - Assert.True(EntityTagHeaderValue.TryParse(input, out result)); + Assert.True(EntityTagHeaderValue.TryParse(input, out var result)); Assert.Equal(expectedResult, result); } - private void CheckInvalidTryParse(string input) + private void CheckInvalidTryParse(string? input) { - EntityTagHeaderValue result = null; - Assert.False(EntityTagHeaderValue.TryParse(input, out result)); + Assert.False(EntityTagHeaderValue.TryParse(input, out var result)); Assert.Null(result); } diff --git a/src/Http/Headers/test/MediaTypeHeaderValueTest.cs b/src/Http/Headers/test/MediaTypeHeaderValueTest.cs index 63b2fa391b..025dcab4b1 100644 --- a/src/Http/Headers/test/MediaTypeHeaderValueTest.cs +++ b/src/Http/Headers/test/MediaTypeHeaderValueTest.cs @@ -40,8 +40,8 @@ namespace Microsoft.Net.Http.Headers AssertFormatException("text/plain;charset=utf-8"); // ctor takes only media-type name, no parameters } - public static TheoryData MediaTypesWithSuffixes => - new TheoryData + public static TheoryData MediaTypesWithSuffixes => + new TheoryData { // See https://tools.ietf.org/html/rfc6838#section-4.2 for allowed names spec { "application/json", "json", null }, @@ -124,7 +124,7 @@ namespace Microsoft.Net.Http.Headers public void Parameters_AddNull_Throw() { var mediaType = new MediaTypeHeaderValue("text/plain"); - Assert.Throws(() => mediaType.Parameters.Add(null)); + Assert.Throws(() => mediaType.Parameters.Add(null!)); } [Fact] @@ -381,7 +381,7 @@ namespace Microsoft.Net.Http.Headers Assert.False(mediaType1.Equals(mediaType2), "No params vs. charset."); Assert.False(mediaType2.Equals(mediaType1), "charset vs. no params."); Assert.False(mediaType1.Equals(null), "No params vs. ."); - Assert.False(mediaType1.Equals(mediaType3), "No params vs. custom param."); + Assert.False(mediaType1!.Equals(mediaType3), "No params vs. custom param."); Assert.False(mediaType2.Equals(mediaType3), "charset vs. custom param."); Assert.True(mediaType1.Equals(mediaType4), "Different casing."); Assert.True(mediaType2.Equals(mediaType5), "Different casing in charset."); @@ -536,8 +536,7 @@ namespace Microsoft.Net.Http.Headers [Fact] public void TryParseList_NullOrEmptyArray_ReturnsFalse() { - IList results; - Assert.False(MediaTypeHeaderValue.TryParseList(null, out results)); + Assert.False(MediaTypeHeaderValue.TryParseList(null, out var results)); Assert.False(MediaTypeHeaderValue.TryParseList(new string[0], out results)); Assert.False(MediaTypeHeaderValue.TryParseList(new string[] { "" }, out results)); } @@ -582,8 +581,7 @@ namespace Microsoft.Net.Http.Headers public void TryParseList_SetOfValidValueStrings_ReturnsTrue() { var inputs = new[] { "text/html,application/xhtml+xml,", "application/xml;q=0.9,image/webp,*/*;q=0.8" }; - IList results; - Assert.True(MediaTypeHeaderValue.TryParseList(inputs, out results)); + Assert.True(MediaTypeHeaderValue.TryParseList(inputs, out var results)); var expectedResults = new[] { @@ -601,8 +599,7 @@ namespace Microsoft.Net.Http.Headers public void TryParseStrictList_SetOfValidValueStrings_ReturnsTrue() { var inputs = new[] { "text/html,application/xhtml+xml,", "application/xml;q=0.9,image/webp,*/*;q=0.8" }; - IList results; - Assert.True(MediaTypeHeaderValue.TryParseStrictList(inputs, out results)); + Assert.True(MediaTypeHeaderValue.TryParseStrictList(inputs, out var results)); var expectedResults = new[] { @@ -659,8 +656,7 @@ namespace Microsoft.Net.Http.Headers "application/xml;q=0.9,image/webp,*/*;q=0.8", "application/xml;q=0 4" }; - IList results; - Assert.True(MediaTypeHeaderValue.TryParseList(inputs, out results)); + Assert.True(MediaTypeHeaderValue.TryParseList(inputs, out var results)); var expectedResults = new[] { @@ -684,8 +680,7 @@ namespace Microsoft.Net.Http.Headers "application/xml;q=0.9,image/webp,*/*;q=0.8", "application/xml;q=0 4" }; - IList results; - Assert.False(MediaTypeHeaderValue.TryParseStrictList(inputs, out results)); + Assert.False(MediaTypeHeaderValue.TryParseStrictList(inputs, out var results)); } [Theory] @@ -817,28 +812,26 @@ namespace Microsoft.Net.Http.Headers Assert.Equal(expected, result); } - private void CheckValidParse(string input, MediaTypeHeaderValue expectedResult) + private void CheckValidParse(string? input, MediaTypeHeaderValue expectedResult) { var result = MediaTypeHeaderValue.Parse(input); Assert.Equal(expectedResult, result); } - private void CheckInvalidParse(string input) + private void CheckInvalidParse(string? input) { Assert.Throws(() => MediaTypeHeaderValue.Parse(input)); } - private void CheckValidTryParse(string input, MediaTypeHeaderValue expectedResult) + private void CheckValidTryParse(string? input, MediaTypeHeaderValue expectedResult) { - MediaTypeHeaderValue result = null; - Assert.True(MediaTypeHeaderValue.TryParse(input, out result)); + Assert.True(MediaTypeHeaderValue.TryParse(input, out var result)); Assert.Equal(expectedResult, result); } - private void CheckInvalidTryParse(string input) + private void CheckInvalidTryParse(string? input) { - MediaTypeHeaderValue result = null; - Assert.False(MediaTypeHeaderValue.TryParse(input, out result)); + Assert.False(MediaTypeHeaderValue.TryParse(input, out var result)); Assert.Null(result); } diff --git a/src/Http/Headers/test/Microsoft.Net.Http.Headers.Tests.csproj b/src/Http/Headers/test/Microsoft.Net.Http.Headers.Tests.csproj index 40c26c701b..083c177f73 100644 --- a/src/Http/Headers/test/Microsoft.Net.Http.Headers.Tests.csproj +++ b/src/Http/Headers/test/Microsoft.Net.Http.Headers.Tests.csproj @@ -2,6 +2,7 @@ $(DefaultNetCoreTargetFramework) + enable diff --git a/src/Http/Headers/test/NameValueHeaderValueTest.cs b/src/Http/Headers/test/NameValueHeaderValueTest.cs index 4833b6898a..99f276ab62 100644 --- a/src/Http/Headers/test/NameValueHeaderValueTest.cs +++ b/src/Http/Headers/test/NameValueHeaderValueTest.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// 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; @@ -412,8 +412,7 @@ namespace Microsoft.Net.Http.Headers "name=value6,name=value7", "name=\"value 8\", name= \"value 9\"", }; - IList results; - Assert.True(NameValueHeaderValue.TryParseList(inputs, out results)); + Assert.True(NameValueHeaderValue.TryParseList(inputs, out var results)); var expectedResults = new[] { @@ -446,8 +445,7 @@ namespace Microsoft.Net.Http.Headers "name=value6,name=value7", "name=\"value 8\", name= \"value 9\"", }; - IList results; - Assert.True(NameValueHeaderValue.TryParseStrictList(inputs, out results)); + Assert.True(NameValueHeaderValue.TryParseStrictList(inputs, out var results)); var expectedResults = new[] { @@ -534,8 +532,7 @@ namespace Microsoft.Net.Http.Headers "name8=value8,name9=value9", "name10=\"value 10\", name11= \"value 11\"", }; - IList results; - Assert.True(NameValueHeaderValue.TryParseList(inputs, out results)); + Assert.True(NameValueHeaderValue.TryParseList(inputs, out var results)); var expectedResults = new[] { @@ -571,8 +568,7 @@ namespace Microsoft.Net.Http.Headers "name8=value8,name9=value9", "name10=\"value 10\", name11= \"value 11\"", }; - IList results; - Assert.False(NameValueHeaderValue.TryParseStrictList(inputs, out results)); + Assert.False(NameValueHeaderValue.TryParseStrictList(inputs, out var results)); } [Theory] @@ -658,38 +654,36 @@ namespace Microsoft.Net.Http.Headers #region Helper methods - private void CheckValidParse(string input, NameValueHeaderValue expectedResult) + private void CheckValidParse(string? input, NameValueHeaderValue expectedResult) { var result = NameValueHeaderValue.Parse(input); Assert.Equal(expectedResult, result); } - private void CheckInvalidParse(string input) + private void CheckInvalidParse(string? input) { Assert.Throws(() => NameValueHeaderValue.Parse(input)); } - private void CheckValidTryParse(string input, NameValueHeaderValue expectedResult) + private void CheckValidTryParse(string? input, NameValueHeaderValue expectedResult) { - NameValueHeaderValue result = null; - Assert.True(NameValueHeaderValue.TryParse(input, out result)); + Assert.True(NameValueHeaderValue.TryParse(input, out var result)); Assert.Equal(expectedResult, result); } - private void CheckInvalidTryParse(string input) + private void CheckInvalidTryParse(string? input) { - NameValueHeaderValue result = null; - Assert.False(NameValueHeaderValue.TryParse(input, out result)); + Assert.False(NameValueHeaderValue.TryParse(input, out var result)); Assert.Null(result); } - private static void CheckValue(string value) + private static void CheckValue(string? value) { var nameValue = new NameValueHeaderValue("text", value); Assert.Equal(value, nameValue.Value); } - private static void AssertFormatException(string name, string value) + private static void AssertFormatException(string name, string? value) { Assert.Throws(() => new NameValueHeaderValue(name, value)); } diff --git a/src/Http/Headers/test/RangeConditionHeaderValueTest.cs b/src/Http/Headers/test/RangeConditionHeaderValueTest.cs index dab3f670a4..58ddda041d 100644 --- a/src/Http/Headers/test/RangeConditionHeaderValueTest.cs +++ b/src/Http/Headers/test/RangeConditionHeaderValueTest.cs @@ -15,7 +15,7 @@ namespace Microsoft.Net.Http.Headers Assert.Equal(new EntityTagHeaderValue("\"x\""), rangeCondition.EntityTag); Assert.Null(rangeCondition.LastModified); - EntityTagHeaderValue input = null; + EntityTagHeaderValue input = null!; Assert.Throws(() => new RangeConditionHeaderValue(input)); } @@ -26,7 +26,7 @@ namespace Microsoft.Net.Http.Headers Assert.Equal(new EntityTagHeaderValue("\"y\""), rangeCondition.EntityTag); Assert.Null(rangeCondition.LastModified); - Assert.Throws(() => new RangeConditionHeaderValue((string)null)); + Assert.Throws(() => new RangeConditionHeaderValue((string?)null)); } [Fact] @@ -84,7 +84,7 @@ namespace Microsoft.Net.Http.Headers new EntityTagHeaderValue("\"x\"", true)); Assert.False(rangeCondition1.Equals(null), "\"x\" vs. "); - Assert.True(rangeCondition1.Equals(rangeCondition2), "\"x\" vs. \"x\""); + Assert.True(rangeCondition1!.Equals(rangeCondition2), "\"x\" vs. \"x\""); Assert.False(rangeCondition1.Equals(rangeCondition3), "\"x\" vs. date"); Assert.False(rangeCondition3.Equals(rangeCondition1), "date vs. \"x\""); Assert.False(rangeCondition3.Equals(rangeCondition4), "date vs. different date"); @@ -149,8 +149,7 @@ namespace Microsoft.Net.Http.Headers [InlineData("Wed 09 Nov 1994 08:49:37 GMT,")] public void TryParse_SetOfInvalidValueStrings_ReturnsFalse(string input) { - RangeConditionHeaderValue result = null; - Assert.False(RangeConditionHeaderValue.TryParse(input, out result)); + Assert.False(RangeConditionHeaderValue.TryParse(input, out var result)); Assert.Null(result); } @@ -164,8 +163,7 @@ namespace Microsoft.Net.Http.Headers private void CheckValidTryParse(string input, RangeConditionHeaderValue expectedResult) { - RangeConditionHeaderValue result = null; - Assert.True(RangeConditionHeaderValue.TryParse(input, out result)); + Assert.True(RangeConditionHeaderValue.TryParse(input, out var result)); Assert.Equal(expectedResult, result); } diff --git a/src/Http/Headers/test/RangeHeaderValueTest.cs b/src/Http/Headers/test/RangeHeaderValueTest.cs index 92a1d72521..48b4b42146 100644 --- a/src/Http/Headers/test/RangeHeaderValueTest.cs +++ b/src/Http/Headers/test/RangeHeaderValueTest.cs @@ -82,7 +82,7 @@ namespace Microsoft.Net.Http.Headers range7.Unit = "other"; Assert.False(range1.Equals(null), "bytes=1-2 vs. "); - Assert.True(range1.Equals(range2), "bytes=1-2 vs. BYTES=1-2"); + Assert.True(range1!.Equals(range2), "bytes=1-2 vs. BYTES=1-2"); Assert.False(range1.Equals(range3), "bytes=1-2 vs. bytes=1-"); Assert.False(range1.Equals(range4), "bytes=1-2 vs. bytes=-2"); Assert.False(range1.Equals(range5), "bytes=1-2 vs. bytes=1-2,3-4"); @@ -153,28 +153,26 @@ namespace Microsoft.Net.Http.Headers #region Helper methods - private void CheckValidParse(string input, RangeHeaderValue expectedResult) + private void CheckValidParse(string? input, RangeHeaderValue expectedResult) { var result = RangeHeaderValue.Parse(input); Assert.Equal(expectedResult, result); } - private void CheckInvalidParse(string input) + private void CheckInvalidParse(string? input) { Assert.Throws(() => RangeHeaderValue.Parse(input)); } - private void CheckValidTryParse(string input, RangeHeaderValue expectedResult) + private void CheckValidTryParse(string? input, RangeHeaderValue expectedResult) { - RangeHeaderValue result = null; - Assert.True(RangeHeaderValue.TryParse(input, out result)); + Assert.True(RangeHeaderValue.TryParse(input, out var result)); Assert.Equal(expectedResult, result); } - private void CheckInvalidTryParse(string input) + private void CheckInvalidTryParse(string? input) { - RangeHeaderValue result = null; - Assert.False(RangeHeaderValue.TryParse(input, out result)); + Assert.False(RangeHeaderValue.TryParse(input, out var result)); Assert.Null(result); } diff --git a/src/Http/Headers/test/RangeItemHeaderValueTest.cs b/src/Http/Headers/test/RangeItemHeaderValueTest.cs index 95598f0a46..300b0ced56 100644 --- a/src/Http/Headers/test/RangeItemHeaderValueTest.cs +++ b/src/Http/Headers/test/RangeItemHeaderValueTest.cs @@ -83,7 +83,7 @@ namespace Microsoft.Net.Http.Headers Assert.False(rangeItem1.Equals(rangeItem2), "1-2 vs. 1-."); Assert.False(rangeItem2.Equals(rangeItem1), "1- vs. 1-2."); Assert.False(rangeItem1.Equals(null), "1-2 vs. null."); - Assert.False(rangeItem1.Equals(rangeItem3), "1-2 vs. -2."); + Assert.False(rangeItem1!.Equals(rangeItem3), "1-2 vs. -2."); Assert.False(rangeItem3.Equals(rangeItem1), "-2 vs. 1-2."); Assert.False(rangeItem1.Equals(rangeItem4), "1-2 vs. 2-2."); Assert.True(rangeItem1.Equals(rangeItem5), "1-2 vs. 1-2."); diff --git a/src/Http/Headers/test/SetCookieHeaderValueTest.cs b/src/Http/Headers/test/SetCookieHeaderValueTest.cs index 4f33c54599..da75465926 100644 --- a/src/Http/Headers/test/SetCookieHeaderValueTest.cs +++ b/src/Http/Headers/test/SetCookieHeaderValueTest.cs @@ -111,11 +111,11 @@ namespace Microsoft.Net.Http.Headers } } - public static TheoryData, string[]> ListOfSetCookieHeaderDataSet + public static TheoryData, string?[]> ListOfSetCookieHeaderDataSet { get { - var dataset = new TheoryData, string[]>(); + var dataset = new TheoryData, string?[]>(); var header1 = new SetCookieHeaderValue("name1", "n1=v1&n2=v2&n3=v3") { Domain = "domain1", @@ -190,11 +190,11 @@ namespace Microsoft.Net.Http.Headers } } - public static TheoryData, string[]> ListWithInvalidSetCookieHeaderDataSet + public static TheoryData?, string?[]> ListWithInvalidSetCookieHeaderDataSet { get { - var dataset = new TheoryData, string[]>(); + var dataset = new TheoryData?, string?[]>(); var header1 = new SetCookieHeaderValue("name1", "n1=v1&n2=v2&n3=v3") { Domain = "domain1", @@ -341,7 +341,7 @@ namespace Microsoft.Net.Http.Headers Assert.True(SetCookieHeaderValue.TryParse(expectedValue, out var header)); Assert.Equal(cookie, header); - Assert.Equal(expectedValue, header.ToString()); + Assert.Equal(expectedValue, header!.ToString()); } [Theory] @@ -382,11 +382,9 @@ namespace Microsoft.Net.Http.Headers { string cookieHeaderValue = "cookiename=value; extensionname=value;"; - SetCookieHeaderValue setCookieHeaderValue; - SetCookieHeaderValue.TryParse(cookieHeaderValue, out setCookieHeaderValue); - - Assert.Equal("value", setCookieHeaderValue.Value); + SetCookieHeaderValue.TryParse(cookieHeaderValue, out var setCookieHeaderValue); + Assert.Equal("value", setCookieHeaderValue!.Value); } [Theory] diff --git a/src/Http/Headers/test/StringWithQualityHeaderValueTest.cs b/src/Http/Headers/test/StringWithQualityHeaderValueTest.cs index 971ad1028f..f124b0bfd0 100644 --- a/src/Http/Headers/test/StringWithQualityHeaderValueTest.cs +++ b/src/Http/Headers/test/StringWithQualityHeaderValueTest.cs @@ -94,7 +94,7 @@ namespace Microsoft.Net.Http.Headers var value9 = new StringWithQualityHeaderValue("x"); Assert.False(value1.Equals(null), "t; q=0.123 vs. "); - Assert.True(value1.Equals(value2), "t; q=0.123 vs. t; q=0.123"); + Assert.True(value1!.Equals(value2), "t; q=0.123 vs. t; q=0.123"); Assert.True(value1.Equals(value3), "t; q=0.123 vs. T; q=0.123"); Assert.False(value1.Equals(value4), "t; q=0.123 vs. t"); Assert.False(value4.Equals(value1), "t vs. t; q=0.123"); @@ -293,8 +293,7 @@ namespace Microsoft.Net.Http.Headers "text7,text8;q=0.5", " text9 , text10 ; q = 0.5 ", }; - IList results; - Assert.True(StringWithQualityHeaderValue.TryParseList(inputs, out results)); + Assert.True(StringWithQualityHeaderValue.TryParseList(inputs, out var results)); var expectedResults = new[] { @@ -331,8 +330,7 @@ namespace Microsoft.Net.Http.Headers "text7,text8;q=0.5", " text9 , text10 ; q = 0.5 ", }; - IList results; - Assert.True(StringWithQualityHeaderValue.TryParseStrictList(inputs, out results)); + Assert.True(StringWithQualityHeaderValue.TryParseStrictList(inputs, out var results)); var expectedResults = new[] { @@ -428,8 +426,7 @@ namespace Microsoft.Net.Http.Headers "text7,text8;q=0.5", " text9 , text10 ; q = 0.5 ", }; - IList results; - Assert.True(StringWithQualityHeaderValue.TryParseList(inputs, out results)); + Assert.True(StringWithQualityHeaderValue.TryParseList(inputs, out var results)); var expectedResults = new[] { @@ -467,29 +464,26 @@ namespace Microsoft.Net.Http.Headers "text7,text8;q=0.5", " text9 , text10 ; q = 0.5 ", }; - IList results; - Assert.False(StringWithQualityHeaderValue.TryParseStrictList(inputs, out results)); + Assert.False(StringWithQualityHeaderValue.TryParseStrictList(inputs, out var results)); } #region Helper methods - private void CheckValidParse(string input, StringWithQualityHeaderValue expectedResult) + private void CheckValidParse(string? input, StringWithQualityHeaderValue expectedResult) { var result = StringWithQualityHeaderValue.Parse(input); Assert.Equal(expectedResult, result); } - private void CheckValidTryParse(string input, StringWithQualityHeaderValue expectedResult) + private void CheckValidTryParse(string? input, StringWithQualityHeaderValue expectedResult) { - StringWithQualityHeaderValue result = null; - Assert.True(StringWithQualityHeaderValue.TryParse(input, out result)); + Assert.True(StringWithQualityHeaderValue.TryParse(input, out var result)); Assert.Equal(expectedResult, result); } - private void CheckInvalidTryParse(string input) + private void CheckInvalidTryParse(string? input) { - StringWithQualityHeaderValue result = null; - Assert.False(StringWithQualityHeaderValue.TryParse(input, out result)); + Assert.False(StringWithQualityHeaderValue.TryParse(input, out var result)); Assert.Null(result); } diff --git a/src/Http/Http.Abstractions/ref/Microsoft.AspNetCore.Http.Abstractions.csproj b/src/Http/Http.Abstractions/ref/Microsoft.AspNetCore.Http.Abstractions.csproj index 169218db01..de86fb1887 100644 --- a/src/Http/Http.Abstractions/ref/Microsoft.AspNetCore.Http.Abstractions.csproj +++ b/src/Http/Http.Abstractions/ref/Microsoft.AspNetCore.Http.Abstractions.csproj @@ -2,6 +2,7 @@ $(DefaultNetCoreTargetFramework) + annotations diff --git a/src/Http/Http.Abstractions/ref/Microsoft.AspNetCore.Http.Abstractions.netcoreapp.cs b/src/Http/Http.Abstractions/ref/Microsoft.AspNetCore.Http.Abstractions.netcoreapp.cs index cf0367cbda..df35a39469 100644 --- a/src/Http/Http.Abstractions/ref/Microsoft.AspNetCore.Http.Abstractions.netcoreapp.cs +++ b/src/Http/Http.Abstractions/ref/Microsoft.AspNetCore.Http.Abstractions.netcoreapp.cs @@ -6,9 +6,9 @@ namespace Microsoft.AspNetCore.Builder public abstract partial class EndpointBuilder { protected EndpointBuilder() { } - public string DisplayName { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public string? DisplayName { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } public System.Collections.Generic.IList Metadata { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } - public Microsoft.AspNetCore.Http.RequestDelegate RequestDelegate { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public Microsoft.AspNetCore.Http.RequestDelegate? RequestDelegate { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } public abstract Microsoft.AspNetCore.Http.Endpoint Build(); } public partial interface IApplicationBuilder @@ -66,7 +66,7 @@ namespace Microsoft.AspNetCore.Builder.Extensions public partial class MapOptions { public MapOptions() { } - public Microsoft.AspNetCore.Http.RequestDelegate Branch { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public Microsoft.AspNetCore.Http.RequestDelegate? Branch { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } public Microsoft.AspNetCore.Http.PathString PathMatch { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } public bool PreserveMatchedPathSegment { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } } @@ -79,8 +79,8 @@ namespace Microsoft.AspNetCore.Builder.Extensions public partial class MapWhenOptions { public MapWhenOptions() { } - public Microsoft.AspNetCore.Http.RequestDelegate Branch { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } - public System.Func Predicate { get { throw null; } set { } } + public Microsoft.AspNetCore.Http.RequestDelegate? Branch { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public System.Func? Predicate { get { throw null; } set { } } } public partial class UsePathBaseMiddleware { @@ -119,13 +119,13 @@ namespace Microsoft.AspNetCore.Http public partial class CookieBuilder { public CookieBuilder() { } - public virtual string Domain { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public virtual string? Domain { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } public virtual System.TimeSpan? Expiration { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } public virtual bool HttpOnly { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } public virtual bool IsEssential { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } public virtual System.TimeSpan? MaxAge { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } - public virtual string Name { get { throw null; } set { } } - public virtual string Path { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public virtual string? Name { get { throw null; } set { } } + public virtual string? Path { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } public virtual Microsoft.AspNetCore.Http.SameSiteMode SameSite { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } public virtual Microsoft.AspNetCore.Http.CookieSecurePolicy SecurePolicy { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } public Microsoft.AspNetCore.Http.CookieOptions Build(Microsoft.AspNetCore.Http.HttpContext context) { throw null; } @@ -143,12 +143,12 @@ namespace Microsoft.AspNetCore.Http public string DisplayName { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } public Microsoft.AspNetCore.Http.EndpointMetadataCollection Metadata { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } public Microsoft.AspNetCore.Http.RequestDelegate RequestDelegate { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } - public override string ToString() { throw null; } + public override string? ToString() { throw null; } } public static partial class EndpointHttpContextExtensions { - public static Microsoft.AspNetCore.Http.Endpoint GetEndpoint(this Microsoft.AspNetCore.Http.HttpContext context) { throw null; } - public static void SetEndpoint(this Microsoft.AspNetCore.Http.HttpContext context, Microsoft.AspNetCore.Http.Endpoint endpoint) { } + public static Microsoft.AspNetCore.Http.Endpoint? GetEndpoint(this Microsoft.AspNetCore.Http.HttpContext context) { throw null; } + public static void SetEndpoint(this Microsoft.AspNetCore.Http.HttpContext context, Microsoft.AspNetCore.Http.Endpoint? endpoint) { } } public sealed partial class EndpointMetadataCollection : System.Collections.Generic.IEnumerable, System.Collections.Generic.IReadOnlyCollection, System.Collections.Generic.IReadOnlyList, System.Collections.IEnumerable { @@ -158,16 +158,16 @@ namespace Microsoft.AspNetCore.Http public int Count { get { throw null; } } public object this[int index] { get { throw null; } } public Microsoft.AspNetCore.Http.EndpointMetadataCollection.Enumerator GetEnumerator() { throw null; } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]public T GetMetadata() where T : class { throw null; } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]public T? GetMetadata() where T : class { throw null; } [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]public System.Collections.Generic.IReadOnlyList GetOrderedMetadata() where T : class { throw null; } - System.Collections.Generic.IEnumerator System.Collections.Generic.IEnumerable.GetEnumerator() { throw null; } + System.Collections.Generic.IEnumerator System.Collections.Generic.IEnumerable.GetEnumerator() { throw null; } System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { throw null; } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] - public partial struct Enumerator : System.Collections.Generic.IEnumerator, System.Collections.IEnumerator, System.IDisposable + public partial struct Enumerator : System.Collections.Generic.IEnumerator, System.Collections.IEnumerator, System.IDisposable { private object _dummy; private int _dummyPrimitive; - public object Current { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } + public object? Current { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } public void Dispose() { } public bool MoveNext() { throw null; } public void Reset() { } @@ -183,7 +183,7 @@ namespace Microsoft.AspNetCore.Http public bool HasValue { get { throw null; } } public string Value { get { throw null; } } public bool Equals(Microsoft.AspNetCore.Http.FragmentString other) { throw null; } - public override bool Equals(object obj) { throw null; } + public override bool Equals(object? obj) { throw null; } public static Microsoft.AspNetCore.Http.FragmentString FromUriComponent(string uriComponent) { throw null; } public static Microsoft.AspNetCore.Http.FragmentString FromUriComponent(System.Uri uri) { throw null; } public override int GetHashCode() { throw null; } @@ -211,7 +211,7 @@ namespace Microsoft.AspNetCore.Http public int? Port { get { throw null; } } public string Value { get { throw null; } } public bool Equals(Microsoft.AspNetCore.Http.HostString other) { throw null; } - public override bool Equals(object obj) { throw null; } + public override bool Equals(object? obj) { throw null; } public static Microsoft.AspNetCore.Http.HostString FromUriComponent(string uriComponent) { throw null; } public static Microsoft.AspNetCore.Http.HostString FromUriComponent(System.Uri uri) { throw null; } public override int GetHashCode() { throw null; } @@ -226,12 +226,12 @@ namespace Microsoft.AspNetCore.Http protected HttpContext() { } public abstract Microsoft.AspNetCore.Http.ConnectionInfo Connection { get; } public abstract Microsoft.AspNetCore.Http.Features.IFeatureCollection Features { get; } - public abstract System.Collections.Generic.IDictionary Items { get; set; } + public abstract System.Collections.Generic.IDictionary Items { get; set; } public abstract Microsoft.AspNetCore.Http.HttpRequest Request { get; } public abstract System.Threading.CancellationToken RequestAborted { get; set; } public abstract System.IServiceProvider RequestServices { get; set; } public abstract Microsoft.AspNetCore.Http.HttpResponse Response { get; } - public abstract Microsoft.AspNetCore.Http.ISession Session { get; set; } + public abstract Microsoft.AspNetCore.Http.ISession? Session { get; set; } public abstract string TraceIdentifier { get; set; } public abstract System.Security.Claims.ClaimsPrincipal User { get; set; } public abstract Microsoft.AspNetCore.Http.WebSocketManager WebSockets { get; } @@ -339,7 +339,7 @@ namespace Microsoft.AspNetCore.Http } public partial interface IMiddlewareFactory { - Microsoft.AspNetCore.Http.IMiddleware Create(System.Type middlewareType); + Microsoft.AspNetCore.Http.IMiddleware? Create(System.Type middlewareType); void Release(Microsoft.AspNetCore.Http.IMiddleware middleware); } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] @@ -348,14 +348,14 @@ namespace Microsoft.AspNetCore.Http private readonly object _dummy; private readonly int _dummyPrimitive; public static readonly Microsoft.AspNetCore.Http.PathString Empty; - public PathString(string value) { throw null; } + public PathString(string? value) { throw null; } public bool HasValue { get { throw null; } } - public string Value { get { throw null; } } + public string? Value { get { throw null; } } public Microsoft.AspNetCore.Http.PathString Add(Microsoft.AspNetCore.Http.PathString other) { throw null; } public string Add(Microsoft.AspNetCore.Http.QueryString other) { throw null; } public bool Equals(Microsoft.AspNetCore.Http.PathString other) { throw null; } public bool Equals(Microsoft.AspNetCore.Http.PathString other, System.StringComparison comparisonType) { throw null; } - public override bool Equals(object obj) { throw null; } + public override bool Equals(object? obj) { throw null; } public static Microsoft.AspNetCore.Http.PathString FromUriComponent(string uriComponent) { throw null; } public static Microsoft.AspNetCore.Http.PathString FromUriComponent(System.Uri uri) { throw null; } public override int GetHashCode() { throw null; } @@ -365,7 +365,7 @@ namespace Microsoft.AspNetCore.Http public static string operator +(string left, Microsoft.AspNetCore.Http.PathString right) { throw null; } public static bool operator ==(Microsoft.AspNetCore.Http.PathString left, Microsoft.AspNetCore.Http.PathString right) { throw null; } public static implicit operator string (Microsoft.AspNetCore.Http.PathString path) { throw null; } - public static implicit operator Microsoft.AspNetCore.Http.PathString (string s) { throw null; } + public static implicit operator Microsoft.AspNetCore.Http.PathString (string? s) { throw null; } public static bool operator !=(Microsoft.AspNetCore.Http.PathString left, Microsoft.AspNetCore.Http.PathString right) { throw null; } public bool StartsWithSegments(Microsoft.AspNetCore.Http.PathString other) { throw null; } public bool StartsWithSegments(Microsoft.AspNetCore.Http.PathString other, out Microsoft.AspNetCore.Http.PathString remaining) { throw null; } @@ -382,16 +382,16 @@ namespace Microsoft.AspNetCore.Http private readonly object _dummy; private readonly int _dummyPrimitive; public static readonly Microsoft.AspNetCore.Http.QueryString Empty; - public QueryString(string value) { throw null; } + public QueryString(string? value) { throw null; } public bool HasValue { get { throw null; } } - public string Value { get { throw null; } } + public string? Value { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } public Microsoft.AspNetCore.Http.QueryString Add(Microsoft.AspNetCore.Http.QueryString other) { throw null; } public Microsoft.AspNetCore.Http.QueryString Add(string name, string value) { throw null; } public static Microsoft.AspNetCore.Http.QueryString Create(System.Collections.Generic.IEnumerable> parameters) { throw null; } - public static Microsoft.AspNetCore.Http.QueryString Create(System.Collections.Generic.IEnumerable> parameters) { throw null; } + public static Microsoft.AspNetCore.Http.QueryString Create(System.Collections.Generic.IEnumerable> parameters) { throw null; } public static Microsoft.AspNetCore.Http.QueryString Create(string name, string value) { throw null; } public bool Equals(Microsoft.AspNetCore.Http.QueryString other) { throw null; } - public override bool Equals(object obj) { throw null; } + public override bool Equals(object? obj) { throw null; } public static Microsoft.AspNetCore.Http.QueryString FromUriComponent(string uriComponent) { throw null; } public static Microsoft.AspNetCore.Http.QueryString FromUriComponent(System.Uri uri) { throw null; } public override int GetHashCode() { throw null; } @@ -489,14 +489,14 @@ namespace Microsoft.AspNetCore.Http public abstract bool IsWebSocketRequest { get; } public abstract System.Collections.Generic.IList WebSocketRequestedProtocols { get; } public virtual System.Threading.Tasks.Task AcceptWebSocketAsync() { throw null; } - public abstract System.Threading.Tasks.Task AcceptWebSocketAsync(string subProtocol); + public abstract System.Threading.Tasks.Task AcceptWebSocketAsync(string? subProtocol); } } namespace Microsoft.AspNetCore.Http.Features { public partial interface IEndpointFeature { - Microsoft.AspNetCore.Http.Endpoint Endpoint { get; set; } + Microsoft.AspNetCore.Http.Endpoint? Endpoint { get; set; } } public partial interface IRouteValuesFeature { @@ -505,40 +505,40 @@ namespace Microsoft.AspNetCore.Http.Features } namespace Microsoft.AspNetCore.Routing { - public partial class RouteValueDictionary : System.Collections.Generic.ICollection>, System.Collections.Generic.IDictionary, System.Collections.Generic.IEnumerable>, System.Collections.Generic.IReadOnlyCollection>, System.Collections.Generic.IReadOnlyDictionary, System.Collections.IEnumerable + public partial class RouteValueDictionary : System.Collections.Generic.ICollection>, System.Collections.Generic.IDictionary, System.Collections.Generic.IEnumerable>, System.Collections.Generic.IReadOnlyCollection>, System.Collections.Generic.IReadOnlyDictionary, System.Collections.IEnumerable { public RouteValueDictionary() { } - public RouteValueDictionary(object values) { } + public RouteValueDictionary(object? values) { } public System.Collections.Generic.IEqualityComparer Comparer { get { throw null; } } public int Count { get { throw null; } } - public object this[string key] { get { throw null; } set { } } + public object? this[string key] { get { throw null; } set { } } public System.Collections.Generic.ICollection Keys { get { throw null; } } - bool System.Collections.Generic.ICollection>.IsReadOnly { get { throw null; } } - System.Collections.Generic.IEnumerable System.Collections.Generic.IReadOnlyDictionary.Keys { get { throw null; } } - System.Collections.Generic.IEnumerable System.Collections.Generic.IReadOnlyDictionary.Values { get { throw null; } } - public System.Collections.Generic.ICollection Values { get { throw null; } } - public void Add(string key, object value) { } + bool System.Collections.Generic.ICollection>.IsReadOnly { get { throw null; } } + System.Collections.Generic.IEnumerable System.Collections.Generic.IReadOnlyDictionary.Keys { get { throw null; } } + System.Collections.Generic.IEnumerable System.Collections.Generic.IReadOnlyDictionary.Values { get { throw null; } } + public System.Collections.Generic.ICollection Values { get { throw null; } } + public void Add(string key, object? value) { } public void Clear() { } public bool ContainsKey(string key) { throw null; } public static Microsoft.AspNetCore.Routing.RouteValueDictionary FromArray(System.Collections.Generic.KeyValuePair[] items) { throw null; } public Microsoft.AspNetCore.Routing.RouteValueDictionary.Enumerator GetEnumerator() { throw null; } public bool Remove(string key) { throw null; } - public bool Remove(string key, out object value) { throw null; } - void System.Collections.Generic.ICollection>.Add(System.Collections.Generic.KeyValuePair item) { } - bool System.Collections.Generic.ICollection>.Contains(System.Collections.Generic.KeyValuePair item) { throw null; } - void System.Collections.Generic.ICollection>.CopyTo(System.Collections.Generic.KeyValuePair[] array, int arrayIndex) { } - bool System.Collections.Generic.ICollection>.Remove(System.Collections.Generic.KeyValuePair item) { throw null; } - System.Collections.Generic.IEnumerator> System.Collections.Generic.IEnumerable>.GetEnumerator() { throw null; } + public bool Remove(string key, out object? value) { throw null; } + void System.Collections.Generic.ICollection>.Add(System.Collections.Generic.KeyValuePair item) { } + bool System.Collections.Generic.ICollection>.Contains(System.Collections.Generic.KeyValuePair item) { throw null; } + void System.Collections.Generic.ICollection>.CopyTo(System.Collections.Generic.KeyValuePair[] array, int arrayIndex) { } + bool System.Collections.Generic.ICollection>.Remove(System.Collections.Generic.KeyValuePair item) { throw null; } + System.Collections.Generic.IEnumerator> System.Collections.Generic.IEnumerable>.GetEnumerator() { throw null; } System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { throw null; } public bool TryAdd(string key, object value) { throw null; } - public bool TryGetValue(string key, out object value) { throw null; } + public bool TryGetValue(string key, out object? value) { throw null; } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] - public partial struct Enumerator : System.Collections.Generic.IEnumerator>, System.Collections.IEnumerator, System.IDisposable + public partial struct Enumerator : System.Collections.Generic.IEnumerator>, System.Collections.IEnumerator, System.IDisposable { private object _dummy; private int _dummyPrimitive; public Enumerator(Microsoft.AspNetCore.Routing.RouteValueDictionary dictionary) { throw null; } - public System.Collections.Generic.KeyValuePair Current { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } + public System.Collections.Generic.KeyValuePair Current { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } object System.Collections.IEnumerator.Current { get { throw null; } } public void Dispose() { } [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]public bool MoveNext() { throw null; } diff --git a/src/Http/Http.Abstractions/src/CookieBuilder.cs b/src/Http/Http.Abstractions/src/CookieBuilder.cs index 429de53cf3..456bc05e99 100644 --- a/src/Http/Http.Abstractions/src/CookieBuilder.cs +++ b/src/Http/Http.Abstractions/src/CookieBuilder.cs @@ -11,12 +11,12 @@ namespace Microsoft.AspNetCore.Http /// public class CookieBuilder { - private string _name; + private string? _name; /// /// The name of the cookie. /// - public virtual string Name + public virtual string? Name { get => _name; set => _name = !string.IsNullOrEmpty(value) @@ -30,7 +30,7 @@ namespace Microsoft.AspNetCore.Http /// /// Determines the value that will set on . /// - public virtual string Path { get; set; } + public virtual string? Path { get; set; } /// /// The domain to associate the cookie with. @@ -38,7 +38,7 @@ namespace Microsoft.AspNetCore.Http /// /// Determines the value that will set on . /// - public virtual string Domain { get; set; } + public virtual string? Domain { get; set; } /// /// Indicates whether a cookie is accessible by client-side script. diff --git a/src/Http/Http.Abstractions/src/Extensions/EndpointBuilder.cs b/src/Http/Http.Abstractions/src/Extensions/EndpointBuilder.cs index 2db104bb45..470bb5031f 100644 --- a/src/Http/Http.Abstractions/src/Extensions/EndpointBuilder.cs +++ b/src/Http/Http.Abstractions/src/Extensions/EndpointBuilder.cs @@ -14,12 +14,12 @@ namespace Microsoft.AspNetCore.Builder /// /// Gets or sets the delegate used to process requests for the endpoint. /// - public RequestDelegate RequestDelegate { get; set; } + public RequestDelegate? RequestDelegate { get; set; } /// /// Gets or sets the informational display name of this endpoint. /// - public string DisplayName { get; set; } + public string? DisplayName { get; set; } /// /// Gets the collection of metadata associated with this endpoint. diff --git a/src/Http/Http.Abstractions/src/Extensions/MapExtensions.cs b/src/Http/Http.Abstractions/src/Extensions/MapExtensions.cs index fc33e8fe8a..a74a883b20 100644 --- a/src/Http/Http.Abstractions/src/Extensions/MapExtensions.cs +++ b/src/Http/Http.Abstractions/src/Extensions/MapExtensions.cs @@ -46,7 +46,7 @@ namespace Microsoft.AspNetCore.Builder throw new ArgumentNullException(nameof(configuration)); } - if (pathMatch.HasValue && pathMatch.Value.EndsWith("/", StringComparison.Ordinal)) + if (pathMatch.HasValue && pathMatch.Value!.EndsWith("/", StringComparison.Ordinal)) { throw new ArgumentException("The path must not end with a '/'", nameof(pathMatch)); } diff --git a/src/Http/Http.Abstractions/src/Extensions/MapMiddleware.cs b/src/Http/Http.Abstractions/src/Extensions/MapMiddleware.cs index 0ba76507c8..cf9e617bd8 100644 --- a/src/Http/Http.Abstractions/src/Extensions/MapMiddleware.cs +++ b/src/Http/Http.Abstractions/src/Extensions/MapMiddleware.cs @@ -32,6 +32,11 @@ namespace Microsoft.AspNetCore.Builder.Extensions throw new ArgumentNullException(nameof(options)); } + if (options.Branch == null) + { + throw new ArgumentException("Branch not set on options.", nameof(options)); + } + _next = next; _options = options; } @@ -62,7 +67,7 @@ namespace Microsoft.AspNetCore.Builder.Extensions try { - await _options.Branch(context); + await _options.Branch!(context); } finally { diff --git a/src/Http/Http.Abstractions/src/Extensions/MapOptions.cs b/src/Http/Http.Abstractions/src/Extensions/MapOptions.cs index d914aa4210..61c1e8d9a4 100644 --- a/src/Http/Http.Abstractions/src/Extensions/MapOptions.cs +++ b/src/Http/Http.Abstractions/src/Extensions/MapOptions.cs @@ -18,7 +18,7 @@ namespace Microsoft.AspNetCore.Builder.Extensions /// /// The branch taken for a positive match. /// - public RequestDelegate Branch { get; set; } + public RequestDelegate? Branch { get; set; } /// /// If false, matched path would be removed from Request.Path and added to Request.PathBase diff --git a/src/Http/Http.Abstractions/src/Extensions/MapWhenMiddleware.cs b/src/Http/Http.Abstractions/src/Extensions/MapWhenMiddleware.cs index 1441da4d99..4c384104e6 100644 --- a/src/Http/Http.Abstractions/src/Extensions/MapWhenMiddleware.cs +++ b/src/Http/Http.Abstractions/src/Extensions/MapWhenMiddleware.cs @@ -32,6 +32,16 @@ namespace Microsoft.AspNetCore.Builder.Extensions throw new ArgumentNullException(nameof(options)); } + if (options.Predicate == null) + { + throw new ArgumentException("Predicate not set on options.", nameof(options)); + } + + if (options.Branch == null) + { + throw new ArgumentException("Branch not set on options.", nameof(options)); + } + _next = next; _options = options; } @@ -48,9 +58,9 @@ namespace Microsoft.AspNetCore.Builder.Extensions throw new ArgumentNullException(nameof(context)); } - if (_options.Predicate(context)) + if (_options.Predicate!(context)) { - await _options.Branch(context); + await _options.Branch!(context); } else { @@ -58,4 +68,4 @@ namespace Microsoft.AspNetCore.Builder.Extensions } } } -} \ No newline at end of file +} diff --git a/src/Http/Http.Abstractions/src/Extensions/MapWhenOptions.cs b/src/Http/Http.Abstractions/src/Extensions/MapWhenOptions.cs index d18eb7f257..3696306962 100644 --- a/src/Http/Http.Abstractions/src/Extensions/MapWhenOptions.cs +++ b/src/Http/Http.Abstractions/src/Extensions/MapWhenOptions.cs @@ -11,12 +11,12 @@ namespace Microsoft.AspNetCore.Builder.Extensions /// public class MapWhenOptions { - private Func _predicate; + private Func? _predicate; /// /// The user callback that determines if the branch should be taken. /// - public Func Predicate + public Func? Predicate { get { @@ -36,6 +36,6 @@ namespace Microsoft.AspNetCore.Builder.Extensions /// /// The branch taken for a positive match. /// - public RequestDelegate Branch { get; set; } + public RequestDelegate? Branch { get; set; } } -} \ No newline at end of file +} diff --git a/src/Http/Http.Abstractions/src/Extensions/UseMiddlewareExtensions.cs b/src/Http/Http.Abstractions/src/Extensions/UseMiddlewareExtensions.cs index 3342b4e08d..f33707e671 100644 --- a/src/Http/Http.Abstractions/src/Extensions/UseMiddlewareExtensions.cs +++ b/src/Http/Http.Abstractions/src/Extensions/UseMiddlewareExtensions.cs @@ -20,7 +20,7 @@ namespace Microsoft.AspNetCore.Builder internal const string InvokeMethodName = "Invoke"; internal const string InvokeAsyncMethodName = "InvokeAsync"; - private static readonly MethodInfo GetServiceInfo = typeof(UseMiddlewareExtensions).GetMethod(nameof(GetService), BindingFlags.NonPublic | BindingFlags.Static); + private static readonly MethodInfo GetServiceInfo = typeof(UseMiddlewareExtensions).GetMethod(nameof(GetService), BindingFlags.NonPublic | BindingFlags.Static)!; /// /// Adds a middleware type to the application's request pipeline. @@ -116,7 +116,7 @@ namespace Microsoft.AspNetCore.Builder { return async context => { - var middlewareFactory = (IMiddlewareFactory)context.RequestServices.GetService(typeof(IMiddlewareFactory)); + var middlewareFactory = (IMiddlewareFactory?)context.RequestServices.GetService(typeof(IMiddlewareFactory)); if (middlewareFactory == null) { // No middleware factory @@ -198,7 +198,7 @@ namespace Microsoft.AspNetCore.Builder } Expression middlewareInstanceArg = instanceArg; - if (methodInfo.DeclaringType != typeof(T)) + if (methodInfo.DeclaringType != null && methodInfo.DeclaringType != typeof(T)) { middlewareInstanceArg = Expression.Convert(middlewareInstanceArg, methodInfo.DeclaringType); } diff --git a/src/Http/Http.Abstractions/src/FragmentString.cs b/src/Http/Http.Abstractions/src/FragmentString.cs index fbe936ce89..6233d7f2a1 100644 --- a/src/Http/Http.Abstractions/src/FragmentString.cs +++ b/src/Http/Http.Abstractions/src/FragmentString.cs @@ -114,7 +114,7 @@ namespace Microsoft.AspNetCore.Http return string.Equals(_value, other._value, StringComparison.Ordinal); } - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/src/Http/Http.Abstractions/src/HostString.cs b/src/Http/Http.Abstractions/src/HostString.cs index c15d59bf56..f9ba89d2f1 100644 --- a/src/Http/Http.Abstractions/src/HostString.cs +++ b/src/Http/Http.Abstractions/src/HostString.cs @@ -297,7 +297,7 @@ namespace Microsoft.AspNetCore.Http /// /// The to compare against. /// if they have the same value. - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/src/Http/Http.Abstractions/src/HttpContext.cs b/src/Http/Http.Abstractions/src/HttpContext.cs index 115e8a810d..a39b208e18 100644 --- a/src/Http/Http.Abstractions/src/HttpContext.cs +++ b/src/Http/Http.Abstractions/src/HttpContext.cs @@ -47,7 +47,7 @@ namespace Microsoft.AspNetCore.Http /// /// Gets or sets a key/value collection that can be used to share data within the scope of this request. /// - public abstract IDictionary Items { get; set; } + public abstract IDictionary Items { get; set; } /// /// Gets or sets the that provides access to the request's service container. @@ -68,7 +68,7 @@ namespace Microsoft.AspNetCore.Http /// /// Gets or sets the object used to manage user session data for this request. /// - public abstract ISession Session { get; set; } + public abstract ISession? Session { get; set; } /// /// Aborts the connection underlying this request. diff --git a/src/Http/Http.Abstractions/src/HttpRequest.cs b/src/Http/Http.Abstractions/src/HttpRequest.cs index 373b82588a..33f8a9ed8f 100644 --- a/src/Http/Http.Abstractions/src/HttpRequest.cs +++ b/src/Http/Http.Abstractions/src/HttpRequest.cs @@ -131,6 +131,6 @@ namespace Microsoft.AspNetCore.Http /// Gets the collection of route values for this request. /// /// The collection of route values for this request. - public virtual RouteValueDictionary RouteValues { get; set; } + public virtual RouteValueDictionary RouteValues { get; set; } = null!; } } diff --git a/src/Http/Http.Abstractions/src/IMiddlewareFactory.cs b/src/Http/Http.Abstractions/src/IMiddlewareFactory.cs index 5d9fda8a75..91a8a5a3d1 100644 --- a/src/Http/Http.Abstractions/src/IMiddlewareFactory.cs +++ b/src/Http/Http.Abstractions/src/IMiddlewareFactory.cs @@ -2,10 +2,6 @@ // 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 System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Microsoft.AspNetCore.Http { @@ -19,7 +15,7 @@ namespace Microsoft.AspNetCore.Http /// /// The concrete of the . /// The instance. - IMiddleware Create(Type middlewareType); + IMiddleware? Create(Type middlewareType); /// /// Releases a instance at the end of each request. diff --git a/src/Http/Http.Abstractions/src/Internal/HeaderSegment.cs b/src/Http/Http.Abstractions/src/Internal/HeaderSegment.cs index f86ea7db07..00bf3e8cf2 100644 --- a/src/Http/Http.Abstractions/src/Internal/HeaderSegment.cs +++ b/src/Http/Http.Abstractions/src/Internal/HeaderSegment.cs @@ -35,7 +35,7 @@ namespace Microsoft.AspNetCore.Http return _formatting.Equals(other._formatting) && _data.Equals(other._data); } - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/src/Http/Http.Abstractions/src/Internal/HeaderSegmentCollection.cs b/src/Http/Http.Abstractions/src/Internal/HeaderSegmentCollection.cs index 70d6b45109..b83bf4eeea 100644 --- a/src/Http/Http.Abstractions/src/Internal/HeaderSegmentCollection.cs +++ b/src/Http/Http.Abstractions/src/Internal/HeaderSegmentCollection.cs @@ -22,7 +22,7 @@ namespace Microsoft.AspNetCore.Http return StringValues.Equals(_headers, other._headers); } - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { diff --git a/src/Http/Http.Abstractions/src/Microsoft.AspNetCore.Http.Abstractions.csproj b/src/Http/Http.Abstractions/src/Microsoft.AspNetCore.Http.Abstractions.csproj index ede671fb99..dfc0ee4740 100644 --- a/src/Http/Http.Abstractions/src/Microsoft.AspNetCore.Http.Abstractions.csproj +++ b/src/Http/Http.Abstractions/src/Microsoft.AspNetCore.Http.Abstractions.csproj @@ -14,18 +14,16 @@ Microsoft.AspNetCore.Http.HttpResponse aspnetcore $(NoWarn);CS1591 false + enable - - - - + diff --git a/src/Http/Http.Abstractions/src/PathString.cs b/src/Http/Http.Abstractions/src/PathString.cs index 40fe610a82..79f82ddd1a 100644 --- a/src/Http/Http.Abstractions/src/PathString.cs +++ b/src/Http/Http.Abstractions/src/PathString.cs @@ -20,14 +20,14 @@ namespace Microsoft.AspNetCore.Http /// public static readonly PathString Empty = new PathString(string.Empty); - private readonly string _value; + private readonly string? _value; /// /// Initialize the path string with a given value. This value must be in unescaped format. Use /// PathString.FromUriComponent(value) if you have a path value which is in an escaped format. /// /// The unescaped path to be assigned to the Value property. - public PathString(string value) + public PathString(string? value) { if (!string.IsNullOrEmpty(value) && value[0] != '/') { @@ -39,7 +39,7 @@ namespace Microsoft.AspNetCore.Http /// /// The unescaped path value /// - public string Value + public string? Value { get { return _value; } } @@ -72,7 +72,7 @@ namespace Microsoft.AspNetCore.Http return string.Empty; } - var value = _value; + var value = _value!; var i = 0; for (; i < value.Length; i++) { @@ -92,7 +92,7 @@ namespace Microsoft.AspNetCore.Http private static string ToEscapedUriComponent(string value, int i) { - StringBuilder buffer = null; + StringBuilder? buffer = null; var start = 0; var count = i; @@ -174,7 +174,7 @@ namespace Microsoft.AspNetCore.Http } } - return buffer.ToString(); + return buffer?.ToString() ?? string.Empty; } } @@ -318,11 +318,11 @@ namespace Microsoft.AspNetCore.Http { if (HasValue && other.HasValue && - Value[Value.Length - 1] == '/') + Value![Value.Length - 1] == '/') { // If the path string has a trailing slash and the other string has a leading slash, we need // to trim one of them. - return new PathString(Value + other.Value.Substring(1)); + return new PathString(Value + other.Value!.Substring(1)); } return new PathString(Value + other.Value); @@ -367,7 +367,7 @@ namespace Microsoft.AspNetCore.Http /// /// The second PathString for comparison. /// True if both PathString values are equal - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { @@ -382,7 +382,7 @@ namespace Microsoft.AspNetCore.Http /// The hash code public override int GetHashCode() { - return (HasValue ? StringComparer.OrdinalIgnoreCase.GetHashCode(_value) : 0); + return (HasValue ? StringComparer.OrdinalIgnoreCase.GetHashCode(_value!) : 0); } /// @@ -457,7 +457,7 @@ namespace Microsoft.AspNetCore.Http /// Implicitly creates a new PathString from the given string. /// /// - public static implicit operator PathString(string s) + public static implicit operator PathString(string? s) => ConvertFromString(s); /// @@ -467,7 +467,7 @@ namespace Microsoft.AspNetCore.Http public static implicit operator string(PathString path) => path.ToString(); - internal static PathString ConvertFromString(string s) + internal static PathString ConvertFromString(string? s) => string.IsNullOrEmpty(s) ? new PathString(s) : FromUriComponent(s); } @@ -486,7 +486,7 @@ namespace Microsoft.AspNetCore.Http public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) => destinationType == typeof(string) - ? value.ToString() + ? value.ToString() ?? string.Empty : base.ConvertTo(context, culture, value, destinationType); } } diff --git a/src/Http/Http.Abstractions/src/QueryString.cs b/src/Http/Http.Abstractions/src/QueryString.cs index 64296e6bee..f9babe7889 100644 --- a/src/Http/Http.Abstractions/src/QueryString.cs +++ b/src/Http/Http.Abstractions/src/QueryString.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Text; using System.Text.Encodings.Web; using Microsoft.Extensions.Primitives; @@ -19,37 +20,29 @@ namespace Microsoft.AspNetCore.Http /// public static readonly QueryString Empty = new QueryString(string.Empty); - private readonly string _value; - /// /// Initialize the query string with a given value. This value must be in escaped and delimited format with /// a leading '?' character. /// /// The query string to be assigned to the Value property. - public QueryString(string value) + public QueryString(string? value) { if (!string.IsNullOrEmpty(value) && value[0] != '?') { throw new ArgumentException("The leading '?' must be included for a non-empty query.", nameof(value)); } - _value = value; + Value = value; } /// /// The escaped query string with the leading '?' character /// - public string Value - { - get { return _value; } - } + public string? Value { get; } /// /// True if the query string is not empty /// - public bool HasValue - { - get { return !string.IsNullOrEmpty(_value); } - } + public bool HasValue => !string.IsNullOrEmpty(Value); /// /// Provides the query string escaped in a way which is correct for combining into the URI representation. @@ -71,7 +64,7 @@ namespace Microsoft.AspNetCore.Http public string ToUriComponent() { // Escape things properly so System.Uri doesn't mis-interpret the data. - return HasValue ? _value.Replace("#", "%23") : string.Empty; + return !string.IsNullOrEmpty(Value) ? Value!.Replace("#", "%23") : string.Empty; } /// @@ -134,10 +127,10 @@ namespace Microsoft.AspNetCore.Http /// /// /// The resulting QueryString - public static QueryString Create(IEnumerable> parameters) + public static QueryString Create(IEnumerable> parameters) { var builder = new StringBuilder(); - bool first = true; + var first = true; foreach (var pair in parameters) { AppendKeyValuePair(builder, pair.Key, pair.Value, first); @@ -155,7 +148,7 @@ namespace Microsoft.AspNetCore.Http public static QueryString Create(IEnumerable> parameters) { var builder = new StringBuilder(); - bool first = true; + var first = true; foreach (var pair in parameters) { @@ -179,17 +172,17 @@ namespace Microsoft.AspNetCore.Http public QueryString Add(QueryString other) { - if (!HasValue || Value.Equals("?", StringComparison.Ordinal)) + if (!HasValue || Value!.Equals("?", StringComparison.Ordinal)) { return other; } - if (!other.HasValue || other.Value.Equals("?", StringComparison.Ordinal)) + if (!other.HasValue || other.Value!.Equals("?", StringComparison.Ordinal)) { return this; } // ?name1=value1 Add ?name2=value2 returns ?name1=value1&name2=value2 - return new QueryString(_value + "&" + other.Value.Substring(1)); + return new QueryString(Value + "&" + other.Value.Substring(1)); } public QueryString Add(string name, string value) @@ -199,7 +192,7 @@ namespace Microsoft.AspNetCore.Http throw new ArgumentNullException(nameof(name)); } - if (!HasValue || Value.Equals("?", StringComparison.Ordinal)) + if (!HasValue || Value!.Equals("?", StringComparison.Ordinal)) { return Create(name, value); } @@ -215,10 +208,10 @@ namespace Microsoft.AspNetCore.Http { return true; } - return string.Equals(_value, other._value, StringComparison.Ordinal); + return string.Equals(Value, other.Value, StringComparison.Ordinal); } - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) { @@ -229,7 +222,7 @@ namespace Microsoft.AspNetCore.Http public override int GetHashCode() { - return (HasValue ? _value.GetHashCode() : 0); + return (HasValue ? Value!.GetHashCode() : 0); } public static bool operator ==(QueryString left, QueryString right) @@ -247,7 +240,7 @@ namespace Microsoft.AspNetCore.Http return left.Add(right); } - private static void AppendKeyValuePair(StringBuilder builder, string key, string value, bool first) + private static void AppendKeyValuePair(StringBuilder builder, string key, string? value, bool first) { builder.Append(first ? "?" : "&"); builder.Append(UrlEncoder.Default.Encode(key)); diff --git a/src/Http/Http.Abstractions/src/Routing/Endpoint.cs b/src/Http/Http.Abstractions/src/Routing/Endpoint.cs index dbca2944e0..4733177674 100644 --- a/src/Http/Http.Abstractions/src/Routing/Endpoint.cs +++ b/src/Http/Http.Abstractions/src/Routing/Endpoint.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// 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. namespace Microsoft.AspNetCore.Http @@ -44,6 +44,6 @@ namespace Microsoft.AspNetCore.Http /// public RequestDelegate RequestDelegate { get; } - public override string ToString() => DisplayName ?? base.ToString(); + public override string? ToString() => DisplayName ?? base.ToString(); } } diff --git a/src/Http/Http.Abstractions/src/Routing/EndpointHttpContextExtensions.cs b/src/Http/Http.Abstractions/src/Routing/EndpointHttpContextExtensions.cs index d766e8336a..3eea0541f4 100644 --- a/src/Http/Http.Abstractions/src/Routing/EndpointHttpContextExtensions.cs +++ b/src/Http/Http.Abstractions/src/Routing/EndpointHttpContextExtensions.cs @@ -16,7 +16,7 @@ namespace Microsoft.AspNetCore.Http /// /// The context. /// The . - public static Endpoint GetEndpoint(this HttpContext context) + public static Endpoint? GetEndpoint(this HttpContext context) { if (context == null) { @@ -31,7 +31,7 @@ namespace Microsoft.AspNetCore.Http /// /// The context. /// The . - public static void SetEndpoint(this HttpContext context, Endpoint endpoint) + public static void SetEndpoint(this HttpContext context, Endpoint? endpoint) { if (context == null) { @@ -64,7 +64,7 @@ namespace Microsoft.AspNetCore.Http private class EndpointFeature : IEndpointFeature { - public Endpoint Endpoint { get; set; } + public Endpoint? Endpoint { get; set; } } } } diff --git a/src/Http/Http.Abstractions/src/Routing/EndpointMetadataCollection.cs b/src/Http/Http.Abstractions/src/Routing/EndpointMetadataCollection.cs index 47f9d6e1e5..6051068e52 100644 --- a/src/Http/Http.Abstractions/src/Routing/EndpointMetadataCollection.cs +++ b/src/Http/Http.Abstractions/src/Routing/EndpointMetadataCollection.cs @@ -72,7 +72,7 @@ namespace Microsoft.AspNetCore.Http /// The most significant metadata of type or null. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public T GetMetadata() where T : class + public T? GetMetadata() where T : class { if (_cache.TryGetValue(typeof(T), out var obj)) { @@ -84,7 +84,7 @@ namespace Microsoft.AspNetCore.Http return GetMetadataSlow(); } - private T GetMetadataSlow() where T : class + private T? GetMetadataSlow() where T : class { var result = GetOrderedMetadataSlow(); var length = result.Length; @@ -111,7 +111,7 @@ namespace Microsoft.AspNetCore.Http private T[] GetOrderedMetadataSlow() where T : class { // Perf: avoid allocations totally for the common case where there are no matching metadata. - List matches = null; + List? matches = null; var items = _items; for (var i = 0; i < items.Length; i++) @@ -149,7 +149,7 @@ namespace Microsoft.AspNetCore.Http /// /// Enumerates the elements of an . /// - public struct Enumerator : IEnumerator + public struct Enumerator : IEnumerator { // Intentionally not readonly to prevent defensive struct copies private object[] _items; @@ -165,7 +165,7 @@ namespace Microsoft.AspNetCore.Http /// /// Gets the element at the current position of the enumerator /// - public object Current { get; private set; } + public object? Current { get; private set; } /// /// Releases all resources used by the . diff --git a/src/Http/Http.Abstractions/src/Routing/IEndpointFeature.cs b/src/Http/Http.Abstractions/src/Routing/IEndpointFeature.cs index ff0762bb20..d8c1f1e7db 100644 --- a/src/Http/Http.Abstractions/src/Routing/IEndpointFeature.cs +++ b/src/Http/Http.Abstractions/src/Routing/IEndpointFeature.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// 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. namespace Microsoft.AspNetCore.Http.Features @@ -13,6 +13,6 @@ namespace Microsoft.AspNetCore.Http.Features /// Gets or sets the selected for the current /// request. /// - Endpoint Endpoint { get; set; } + Endpoint? Endpoint { get; set; } } } diff --git a/src/Http/Http.Abstractions/src/Routing/RouteValueDictionary.cs b/src/Http/Http.Abstractions/src/Routing/RouteValueDictionary.cs index 13c433b387..815a5d6f10 100644 --- a/src/Http/Http.Abstractions/src/Routing/RouteValueDictionary.cs +++ b/src/Http/Http.Abstractions/src/Routing/RouteValueDictionary.cs @@ -6,6 +6,7 @@ using System.Collections; using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using Microsoft.AspNetCore.Http.Abstractions; using Microsoft.Extensions.Internal; @@ -15,13 +16,13 @@ namespace Microsoft.AspNetCore.Routing /// /// An type for route values. /// - public class RouteValueDictionary : IDictionary, IReadOnlyDictionary + public class RouteValueDictionary : IDictionary, IReadOnlyDictionary { // 4 is a good default capacity here because that leaves enough space for area/controller/action/id private const int DefaultCapacity = 4; - internal KeyValuePair[] _arrayStorage; - internal PropertyStorage _propertyStorage; + internal KeyValuePair[] _arrayStorage; + internal PropertyStorage? _propertyStorage; private int _count; /// @@ -30,7 +31,7 @@ namespace Microsoft.AspNetCore.Routing /// /// The items array. /// A new . - public static RouteValueDictionary FromArray(KeyValuePair[] items) + public static RouteValueDictionary FromArray(KeyValuePair[] items) { if (items == null) { @@ -70,7 +71,7 @@ namespace Microsoft.AspNetCore.Routing return new RouteValueDictionary() { - _arrayStorage = items, + _arrayStorage = items!, _count = start, }; } @@ -80,7 +81,7 @@ namespace Microsoft.AspNetCore.Routing /// public RouteValueDictionary() { - _arrayStorage = Array.Empty>(); + _arrayStorage = Array.Empty>(); } /// @@ -96,7 +97,7 @@ namespace Microsoft.AspNetCore.Routing /// property names are keys, and property values are the values, and copied into the dictionary. /// Only public instance non-index properties are considered. /// - public RouteValueDictionary(object values) + public RouteValueDictionary(object? values) { if (values is RouteValueDictionary dictionary) { @@ -105,6 +106,7 @@ namespace Microsoft.AspNetCore.Routing // PropertyStorage is immutable so we can just copy it. _propertyStorage = dictionary._propertyStorage; _count = dictionary._count; + _arrayStorage = Array.Empty>(); return; } @@ -112,14 +114,14 @@ namespace Microsoft.AspNetCore.Routing if (count > 0) { var other = dictionary._arrayStorage; - var storage = new KeyValuePair[count]; + var storage = new KeyValuePair[count]; Array.Copy(other, 0, storage, 0, count); _arrayStorage = storage; _count = count; } else { - _arrayStorage = Array.Empty>(); + _arrayStorage = Array.Empty>(); } return; @@ -127,7 +129,7 @@ namespace Microsoft.AspNetCore.Routing if (values is IEnumerable> keyValueEnumerable) { - _arrayStorage = Array.Empty>(); + _arrayStorage = Array.Empty>(); foreach (var kvp in keyValueEnumerable) { @@ -139,7 +141,7 @@ namespace Microsoft.AspNetCore.Routing if (values is IEnumerable> stringValueEnumerable) { - _arrayStorage = Array.Empty>(); + _arrayStorage = Array.Empty>(); foreach (var kvp in stringValueEnumerable) { @@ -154,15 +156,16 @@ namespace Microsoft.AspNetCore.Routing var storage = new PropertyStorage(values); _propertyStorage = storage; _count = storage.Properties.Length; + _arrayStorage = Array.Empty>(); } else { - _arrayStorage = Array.Empty>(); + _arrayStorage = Array.Empty>(); } } /// - public object this[string key] + public object? this[string key] { get { @@ -171,8 +174,7 @@ namespace Microsoft.AspNetCore.Routing ThrowArgumentNullExceptionForKey(); } - object value; - TryGetValue(key, out value); + TryGetValue(key, out var value); return value; } @@ -192,11 +194,11 @@ namespace Microsoft.AspNetCore.Routing if (index < 0) { EnsureCapacity(_count + 1); - _arrayStorage[_count++] = new KeyValuePair(key, value); + _arrayStorage[_count++] = new KeyValuePair(key, value); } else { - _arrayStorage[index] = new KeyValuePair(key, value); + _arrayStorage[index] = new KeyValuePair(key, value); } } } @@ -213,7 +215,7 @@ namespace Microsoft.AspNetCore.Routing public int Count => _count; /// - bool ICollection>.IsReadOnly => false; + bool ICollection>.IsReadOnly => false; /// public ICollection Keys @@ -233,17 +235,17 @@ namespace Microsoft.AspNetCore.Routing } } - IEnumerable IReadOnlyDictionary.Keys => Keys; + IEnumerable IReadOnlyDictionary.Keys => Keys; /// - public ICollection Values + public ICollection Values { get { EnsureCapacity(_count); var array = _arrayStorage; - var values = new object[_count]; + var values = new object?[_count]; for (var i = 0; i < values.Length; i++) { values[i] = array[i].Value; @@ -253,16 +255,16 @@ namespace Microsoft.AspNetCore.Routing } } - IEnumerable IReadOnlyDictionary.Values => Values; + IEnumerable IReadOnlyDictionary.Values => Values; /// - void ICollection>.Add(KeyValuePair item) + void ICollection>.Add(KeyValuePair item) { Add(item.Key, item.Value); } /// - public void Add(string key, object value) + public void Add(string key, object? value) { if (key == null) { @@ -277,7 +279,7 @@ namespace Microsoft.AspNetCore.Routing throw new ArgumentException(message, nameof(key)); } - _arrayStorage[_count] = new KeyValuePair(key, value); + _arrayStorage[_count] = new KeyValuePair(key, value); _count++; } @@ -291,7 +293,7 @@ namespace Microsoft.AspNetCore.Routing if (_propertyStorage != null) { - _arrayStorage = Array.Empty>(); + _arrayStorage = Array.Empty>(); _propertyStorage = null; _count = 0; return; @@ -302,7 +304,7 @@ namespace Microsoft.AspNetCore.Routing } /// - bool ICollection>.Contains(KeyValuePair item) + bool ICollection>.Contains(KeyValuePair item) { return TryGetValue(item.Key, out var value) && EqualityComparer.Default.Equals(value, item.Value); } @@ -330,8 +332,8 @@ namespace Microsoft.AspNetCore.Routing } /// - void ICollection>.CopyTo( - KeyValuePair[] array, + void ICollection>.CopyTo( + KeyValuePair[] array, int arrayIndex) { if (array == null) @@ -362,7 +364,7 @@ namespace Microsoft.AspNetCore.Routing } /// - IEnumerator> IEnumerable>.GetEnumerator() + IEnumerator> IEnumerable>.GetEnumerator() { return GetEnumerator(); } @@ -374,13 +376,15 @@ namespace Microsoft.AspNetCore.Routing } /// - bool ICollection>.Remove(KeyValuePair item) + bool ICollection>.Remove(KeyValuePair item) { if (Count == 0) { return false; } + Debug.Assert(_arrayStorage != null); + EnsureCapacity(Count); var index = FindIndex(item.Key); @@ -435,7 +439,7 @@ namespace Microsoft.AspNetCore.Routing /// /// true if the object was removed successfully; otherwise, false. /// - public bool Remove(string key, out object value) + public bool Remove(string key, out object? value) { if (key == null) { @@ -487,13 +491,13 @@ namespace Microsoft.AspNetCore.Routing } EnsureCapacity(Count + 1); - _arrayStorage[Count] = new KeyValuePair(key, value); + _arrayStorage[Count] = new KeyValuePair(key, value); _count++; return true; } /// - public bool TryGetValue(string key, out object value) + public bool TryGetValue(string key, out object? value) { if (key == null) { @@ -508,7 +512,7 @@ namespace Microsoft.AspNetCore.Routing return TryGetValueSlow(key, out value); } - private bool TryGetValueSlow(string key, out object value) + private bool TryGetValueSlow(string key, [NotNullWhen(true)] out object? value) { if (_propertyStorage != null) { @@ -527,6 +531,7 @@ namespace Microsoft.AspNetCore.Routing return false; } + [DoesNotReturn] private static void ThrowArgumentNullExceptionForKey() { throw new ArgumentNullException("key"); @@ -546,16 +551,16 @@ namespace Microsoft.AspNetCore.Routing if (_propertyStorage != null) { var storage = _propertyStorage; - + // If we're converting from properties, it's likely due to an 'add' to make sure we have at least // the default amount of space. capacity = Math.Max(DefaultCapacity, Math.Max(storage.Properties.Length, capacity)); - var array = new KeyValuePair[capacity]; + var array = new KeyValuePair[capacity]; for (var i = 0; i < storage.Properties.Length; i++) { var property = storage.Properties[i]; - array[i] = new KeyValuePair(property.Name, property.GetValue(storage.Value)); + array[i] = new KeyValuePair(property.Name, property.GetValue(storage.Value)); } _arrayStorage = array; @@ -566,7 +571,7 @@ namespace Microsoft.AspNetCore.Routing if (_arrayStorage.Length < capacity) { capacity = _arrayStorage.Length == 0 ? DefaultCapacity : _arrayStorage.Length * 2; - var array = new KeyValuePair[capacity]; + var array = new KeyValuePair[capacity]; if (_count > 0) { Array.Copy(_arrayStorage, 0, array, 0, _count); @@ -596,7 +601,7 @@ namespace Microsoft.AspNetCore.Routing } [MethodImpl(MethodImplOptions.AggressiveInlining)] - private bool TryFindItem(string key, out object value) + private bool TryFindItem(string key, out object? value) { var array = _arrayStorage; var count = _count; @@ -642,6 +647,8 @@ namespace Microsoft.AspNetCore.Routing [MethodImpl(MethodImplOptions.AggressiveInlining)] private bool ContainsKeyProperties(string key) { + Debug.Assert(_propertyStorage != null); + var properties = _propertyStorage.Properties; for (var i = 0; i < properties.Length; i++) { @@ -654,7 +661,7 @@ namespace Microsoft.AspNetCore.Routing return false; } - public struct Enumerator : IEnumerator> + public struct Enumerator : IEnumerator> { private readonly RouteValueDictionary _dictionary; private int _index; @@ -672,7 +679,7 @@ namespace Microsoft.AspNetCore.Routing _index = 0; } - public KeyValuePair Current { get; private set; } + public KeyValuePair Current { get; private set; } object IEnumerator.Current => Current; @@ -699,12 +706,12 @@ namespace Microsoft.AspNetCore.Routing private bool MoveNextRare() { - var dictionary = _dictionary; + var dictionary = _dictionary; if (dictionary._propertyStorage != null && ((uint)_index < (uint)dictionary._count)) { var storage = dictionary._propertyStorage; var property = storage.Properties[_index]; - Current = new KeyValuePair(property.Name, property.GetValue(storage.Value)); + Current = new KeyValuePair(property.Name, property.GetValue(storage.Value)); _index++; return true; } @@ -735,7 +742,7 @@ namespace Microsoft.AspNetCore.Routing // Cache the properties so we can know if we've already validated them for duplicates. var type = Value.GetType(); - if (!_propertyCache.TryGetValue(type, out Properties)) + if (!_propertyCache.TryGetValue(type, out Properties!)) { Properties = PropertyHelper.GetVisibleProperties(type); ValidatePropertyNames(type, Properties); @@ -765,4 +772,4 @@ namespace Microsoft.AspNetCore.Routing } } } -} \ No newline at end of file +} diff --git a/src/Http/Http.Abstractions/src/WebSocketManager.cs b/src/Http/Http.Abstractions/src/WebSocketManager.cs index 79afefa5c0..1fe47d5958 100644 --- a/src/Http/Http.Abstractions/src/WebSocketManager.cs +++ b/src/Http/Http.Abstractions/src/WebSocketManager.cs @@ -36,6 +36,6 @@ namespace Microsoft.AspNetCore.Http /// /// The sub-protocol to use. /// A task representing the completion of the transition. - public abstract Task AcceptWebSocketAsync(string subProtocol); + public abstract Task AcceptWebSocketAsync(string? subProtocol); } } diff --git a/src/Http/Http.Abstractions/test/EndpointHttpContextExtensionsTests.cs b/src/Http/Http.Abstractions/test/EndpointHttpContextExtensionsTests.cs index a011145bec..4b5120a5af 100644 --- a/src/Http/Http.Abstractions/test/EndpointHttpContextExtensionsTests.cs +++ b/src/Http/Http.Abstractions/test/EndpointHttpContextExtensionsTests.cs @@ -149,7 +149,7 @@ namespace Microsoft.AspNetCore.Http.Abstractions.Tests private class EndpointFeature : IEndpointFeature { - public Endpoint Endpoint { get; set; } + public Endpoint? Endpoint { get; set; } } } } diff --git a/src/Http/Http.Abstractions/test/MapPathMiddlewareTests.cs b/src/Http/Http.Abstractions/test/MapPathMiddlewareTests.cs index f9d935b086..7131f28bc2 100644 --- a/src/Http/Http.Abstractions/test/MapPathMiddlewareTests.cs +++ b/src/Http/Http.Abstractions/test/MapPathMiddlewareTests.cs @@ -18,7 +18,7 @@ namespace Microsoft.AspNetCore.Builder.Extensions context.Response.StatusCode = 200; context.Items["test.PathBase"] = context.Request.PathBase.Value; context.Items["test.Path"] = context.Request.Path.Value; - return Task.FromResult(null); + return Task.FromResult(null); } private static void UseSuccess(IApplicationBuilder app) @@ -42,8 +42,8 @@ namespace Microsoft.AspNetCore.Builder.Extensions var builder = new ApplicationBuilder(serviceProvider: null); var noMiddleware = new ApplicationBuilder(serviceProvider: null).Build(); var noOptions = new MapOptions(); - Assert.Throws(() => builder.Map("/foo", configuration: null)); - Assert.Throws(() => new MapMiddleware(noMiddleware, null)); + Assert.Throws(() => builder.Map("/foo", configuration: null!)); + Assert.Throws(() => new MapMiddleware(noMiddleware, null!)); } [Theory] @@ -91,7 +91,7 @@ namespace Microsoft.AspNetCore.Builder.Extensions await app.Invoke(context); Assert.Equal(200, context.Response.StatusCode); - Assert.Equal(basePath + requestPath.Substring(0, matchPath.Length), (string)context.Items["test.PathBase"]); + Assert.Equal(basePath + requestPath.Substring(0, matchPath.Length), (string)context.Items["test.PathBase"]!); Assert.Equal(requestPath.Substring(matchPath.Length), context.Items["test.Path"]); } @@ -119,7 +119,7 @@ namespace Microsoft.AspNetCore.Builder.Extensions await app.Invoke(context); Assert.Equal(200, context.Response.StatusCode); - Assert.Equal(basePath, (string)context.Items["test.PathBase"]); + Assert.Equal(basePath, (string)context.Items["test.PathBase"]!); Assert.Equal(requestPath, context.Items["test.Path"]); } diff --git a/src/Http/Http.Abstractions/test/MapPredicateMiddlewareTests.cs b/src/Http/Http.Abstractions/test/MapPredicateMiddlewareTests.cs index 048d522579..1765859e02 100644 --- a/src/Http/Http.Abstractions/test/MapPredicateMiddlewareTests.cs +++ b/src/Http/Http.Abstractions/test/MapPredicateMiddlewareTests.cs @@ -3,7 +3,6 @@ using System; using System.Threading.Tasks; -using Microsoft.AspNetCore.Builder.Internal; using Microsoft.AspNetCore.Http; using Xunit; @@ -18,7 +17,7 @@ namespace Microsoft.AspNetCore.Builder.Extensions private static Task Success(HttpContext context) { context.Response.StatusCode = 200; - return Task.FromResult(null); + return Task.FromResult(null!); } private static void UseSuccess(IApplicationBuilder app) @@ -52,12 +51,12 @@ namespace Microsoft.AspNetCore.Builder.Extensions var builder = new ApplicationBuilder(serviceProvider: null); var noMiddleware = new ApplicationBuilder(serviceProvider: null).Build(); var noOptions = new MapWhenOptions(); - Assert.Throws(() => builder.MapWhen(null, UseNotImplemented)); - Assert.Throws(() => builder.MapWhen(NotImplementedPredicate, configuration: null)); - Assert.Throws(() => new MapWhenMiddleware(null, noOptions)); - Assert.Throws(() => new MapWhenMiddleware(noMiddleware, null)); - Assert.Throws(() => new MapWhenMiddleware(null, noOptions)); - Assert.Throws(() => new MapWhenMiddleware(noMiddleware, null)); + Assert.Throws(() => builder.MapWhen(null!, UseNotImplemented)); + Assert.Throws(() => builder.MapWhen(NotImplementedPredicate, configuration: null!)); + Assert.Throws(() => new MapWhenMiddleware(null!, noOptions)); + Assert.Throws(() => new MapWhenMiddleware(noMiddleware, null!)); + Assert.Throws(() => new MapWhenMiddleware(null!, noOptions)); + Assert.Throws(() => new MapWhenMiddleware(noMiddleware, null!)); } [Fact] diff --git a/src/Http/Http.Abstractions/test/Microsoft.AspNetCore.Http.Abstractions.Tests.csproj b/src/Http/Http.Abstractions/test/Microsoft.AspNetCore.Http.Abstractions.Tests.csproj index b8bfa1c1c8..34d82b7501 100644 --- a/src/Http/Http.Abstractions/test/Microsoft.AspNetCore.Http.Abstractions.Tests.csproj +++ b/src/Http/Http.Abstractions/test/Microsoft.AspNetCore.Http.Abstractions.Tests.csproj @@ -2,6 +2,7 @@ $(DefaultNetCoreTargetFramework) + enable diff --git a/src/Http/Http.Abstractions/test/QueryStringTests.cs b/src/Http/Http.Abstractions/test/QueryStringTests.cs index a78a853a1c..d4bb0d77d6 100644 --- a/src/Http/Http.Abstractions/test/QueryStringTests.cs +++ b/src/Http/Http.Abstractions/test/QueryStringTests.cs @@ -70,11 +70,11 @@ namespace Microsoft.AspNetCore.Http.Abstractions { var query = QueryString.Create(new[] { - new KeyValuePair("key1", "value1"), - new KeyValuePair("key2", "value2"), - new KeyValuePair("key3", "value3"), - new KeyValuePair("key4", null), - new KeyValuePair("key5", "") + new KeyValuePair("key1", "value1"), + new KeyValuePair("key2", "value2"), + new KeyValuePair("key3", "value3"), + new KeyValuePair("key4", null), + new KeyValuePair("key5", "") }); Assert.Equal("?key1=value1&key2=value2&key3=value3&key4=&key5=", query.Value); } diff --git a/src/Http/Http.Abstractions/test/RouteValueDictionaryTests.cs b/src/Http/Http.Abstractions/test/RouteValueDictionaryTests.cs index ab5925e219..8d861b6dff 100644 --- a/src/Http/Http.Abstractions/test/RouteValueDictionaryTests.cs +++ b/src/Http/Http.Abstractions/test/RouteValueDictionaryTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// 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; @@ -54,8 +54,8 @@ namespace Microsoft.AspNetCore.Routing.Tests Assert.Single(dict._arrayStorage); Assert.Null(dict._propertyStorage); - var storage = Assert.IsType[]>(dict._arrayStorage); - var otherStorage = Assert.IsType[]>(other._arrayStorage); + var storage = Assert.IsType[]>(dict._arrayStorage); + var otherStorage = Assert.IsType[]>(other._arrayStorage); Assert.NotSame(otherStorage, storage); } @@ -70,7 +70,7 @@ namespace Microsoft.AspNetCore.Routing.Tests // Assert Assert.Equal(other, dict); - Assert.Null(dict._arrayStorage); + AssertEmptyArrayStorage(dict); var storage = dict._propertyStorage; var otherStorage = other._propertyStorage; @@ -83,9 +83,9 @@ namespace Microsoft.AspNetCore.Routing.Tests { var routeValues = new[] { - new KeyValuePair("Name", "James"), - new KeyValuePair("Age", 30), - new KeyValuePair("Address", new Address() { City = "Redmond", State = "WA" }) + new KeyValuePair("Name", "James"), + new KeyValuePair("Age", 30), + new KeyValuePair("Address", new Address() { City = "Redmond", State = "WA" }) }; yield return new object[] { routeValues.ToDictionary(kvp => kvp.Key, kvp => kvp.Value) }; @@ -123,7 +123,7 @@ namespace Microsoft.AspNetCore.Routing.Tests var dict = new RouteValueDictionary(values); // Assert - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); Assert.Collection( dict.OrderBy(kvp => kvp.Key), kvp => @@ -145,7 +145,7 @@ namespace Microsoft.AspNetCore.Routing.Tests var dict = new RouteValueDictionary(values); // Assert - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); Assert.Collection( dict.OrderBy(kvp => kvp.Key), kvp => { Assert.Equal("First Name", kvp.Key); Assert.Equal("James", kvp.Value); }, @@ -157,10 +157,10 @@ namespace Microsoft.AspNetCore.Routing.Tests public void CreateFromIEnumerableKeyValuePair_ThrowsExceptionForDuplicateKey() { // Arrange - var values = new List>() + var values = new List>() { - new KeyValuePair("name", "Billy"), - new KeyValuePair("Name", "Joey"), + new KeyValuePair("name", "Billy"), + new KeyValuePair("Name", "Joey"), }; // Act & Assert @@ -262,7 +262,7 @@ namespace Microsoft.AspNetCore.Routing.Tests // Assert Assert.NotNull(dict._propertyStorage); - Assert.Null(dict._arrayStorage); + AssertEmptyArrayStorage(dict); Assert.Empty(dict); } @@ -277,7 +277,7 @@ namespace Microsoft.AspNetCore.Routing.Tests // Assert Assert.NotNull(dict._propertyStorage); - Assert.Null(dict._arrayStorage); + AssertEmptyArrayStorage(dict); Assert.Empty(dict); } @@ -292,7 +292,7 @@ namespace Microsoft.AspNetCore.Routing.Tests // Assert Assert.NotNull(dict._propertyStorage); - Assert.Null(dict._arrayStorage); + AssertEmptyArrayStorage(dict); Assert.Collection( dict.OrderBy(kvp => kvp.Key), kvp => @@ -320,7 +320,7 @@ namespace Microsoft.AspNetCore.Routing.Tests // Assert Assert.NotNull(dict._propertyStorage); - Assert.Null(dict._arrayStorage); + AssertEmptyArrayStorage(dict); Assert.Collection( dict.OrderBy(kvp => kvp.Key), kvp => { Assert.Equal("DerivedProperty", kvp.Key); Assert.Equal(5, kvp.Value); }); @@ -337,7 +337,7 @@ namespace Microsoft.AspNetCore.Routing.Tests // Assert Assert.NotNull(dict._propertyStorage); - Assert.Null(dict._arrayStorage); + AssertEmptyArrayStorage(dict); Assert.Empty(dict); } @@ -382,7 +382,7 @@ namespace Microsoft.AspNetCore.Routing.Tests var dict = new RouteValueDictionary(); // Act - var result = ((ICollection>)dict).IsReadOnly; + var result = ((ICollection>)dict).IsReadOnly; // Assert Assert.False(result); @@ -470,7 +470,7 @@ namespace Microsoft.AspNetCore.Routing.Tests // Assert Assert.Null(value); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -487,7 +487,7 @@ namespace Microsoft.AspNetCore.Routing.Tests // Assert Assert.Equal("value", value); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -504,7 +504,7 @@ namespace Microsoft.AspNetCore.Routing.Tests // Assert Assert.Equal("value", value); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -531,7 +531,7 @@ namespace Microsoft.AspNetCore.Routing.Tests // Assert Assert.Collection(dict, kvp => { Assert.Equal("key", kvp.Key); Assert.Equal("value", kvp.Value); }); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -548,7 +548,7 @@ namespace Microsoft.AspNetCore.Routing.Tests dict.OrderBy(kvp => kvp.Key), kvp => { Assert.Equal("age", kvp.Key); Assert.Equal(30, kvp.Value); }, kvp => { Assert.Equal("key", kvp.Key); Assert.Equal("value", kvp.Value); }); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -562,7 +562,7 @@ namespace Microsoft.AspNetCore.Routing.Tests // Assert Assert.Collection(dict, kvp => { Assert.Equal("key", kvp.Key); Assert.Equal("value", kvp.Value); }); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -576,7 +576,7 @@ namespace Microsoft.AspNetCore.Routing.Tests // Assert Assert.Collection(dict, kvp => { Assert.Equal("kEy", kvp.Key); Assert.Equal("value", kvp.Value); }); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -596,7 +596,7 @@ namespace Microsoft.AspNetCore.Routing.Tests dict.OrderBy(kvp => kvp.Key), kvp => { Assert.Equal("age", kvp.Key); Assert.Equal(30, kvp.Value); }, kvp => { Assert.Equal("key", kvp.Key); Assert.Equal("value", kvp.Value); }); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -613,7 +613,7 @@ namespace Microsoft.AspNetCore.Routing.Tests // Assert Assert.Collection(dict, kvp => { Assert.Equal("key", kvp.Key); Assert.Equal("value", kvp.Value); }); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -630,7 +630,7 @@ namespace Microsoft.AspNetCore.Routing.Tests // Assert Assert.Collection(dict, kvp => { Assert.Equal("key", kvp.Key); Assert.Equal("value", kvp.Value); }); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -674,7 +674,7 @@ namespace Microsoft.AspNetCore.Routing.Tests // Assert Assert.Equal(1, count); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -688,7 +688,7 @@ namespace Microsoft.AspNetCore.Routing.Tests // Assert Assert.Empty(keys); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -702,7 +702,7 @@ namespace Microsoft.AspNetCore.Routing.Tests // Assert Assert.Equal(new[] { "key" }, keys); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -719,7 +719,7 @@ namespace Microsoft.AspNetCore.Routing.Tests // Assert Assert.Equal(new[] { "key" }, keys); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -733,7 +733,7 @@ namespace Microsoft.AspNetCore.Routing.Tests // Assert Assert.Empty(values); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -747,7 +747,7 @@ namespace Microsoft.AspNetCore.Routing.Tests // Assert Assert.Equal(new object[] { "value" }, values); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -764,7 +764,7 @@ namespace Microsoft.AspNetCore.Routing.Tests // Assert Assert.Equal(new object[] { "value" }, values); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -778,7 +778,7 @@ namespace Microsoft.AspNetCore.Routing.Tests // Assert Assert.Collection(dict, kvp => { Assert.Equal("key", kvp.Key); Assert.Equal("value", kvp.Value); }); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -808,13 +808,13 @@ namespace Microsoft.AspNetCore.Routing.Tests dict.OrderBy(kvp => kvp.Key), kvp => { Assert.Equal("age", kvp.Key); Assert.Equal(30, kvp.Value); }, kvp => { Assert.Equal("key", kvp.Key); Assert.Equal("value", kvp.Value); }); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); // The upgrade from property -> array should make space for at least 4 entries Assert.Collection( dict._arrayStorage, - kvp => Assert.Equal(new KeyValuePair("age", 30), kvp), - kvp => Assert.Equal(new KeyValuePair("key", "value"), kvp), + kvp => Assert.Equal(new KeyValuePair("age", 30), kvp), + kvp => Assert.Equal(new KeyValuePair("key", "value"), kvp), kvp => Assert.Equal(default, kvp), kvp => Assert.Equal(default, kvp)); } @@ -836,7 +836,7 @@ namespace Microsoft.AspNetCore.Routing.Tests dict.OrderBy(kvp => kvp.Key), kvp => { Assert.Equal("age", kvp.Key); Assert.Equal(30, kvp.Value); }, kvp => { Assert.Equal("key", kvp.Key); Assert.Equal("value", kvp.Value); }); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -857,7 +857,7 @@ namespace Microsoft.AspNetCore.Routing.Tests Assert.Collection( dict.OrderBy(kvp => kvp.Key), kvp => { Assert.Equal("key", kvp.Key); Assert.Equal("value", kvp.Value); }); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -878,7 +878,7 @@ namespace Microsoft.AspNetCore.Routing.Tests Assert.Collection( dict.OrderBy(kvp => kvp.Key), kvp => { Assert.Equal("key", kvp.Key); Assert.Equal("value", kvp.Value); }); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -891,14 +891,14 @@ namespace Microsoft.AspNetCore.Routing.Tests }; // Act - ((ICollection>)dict).Add(new KeyValuePair("key", "value")); + ((ICollection>)dict).Add(new KeyValuePair("key", "value")); // Assert Assert.Collection( dict.OrderBy(kvp => kvp.Key), kvp => { Assert.Equal("age", kvp.Key); Assert.Equal(30, kvp.Value); }, kvp => { Assert.Equal("key", kvp.Key); Assert.Equal("value", kvp.Value); }); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -926,7 +926,7 @@ namespace Microsoft.AspNetCore.Routing.Tests // Assert Assert.Empty(dict); Assert.NotNull(dict._propertyStorage); - Assert.Null(dict._arrayStorage); + AssertEmptyArrayStorage(dict); } [Fact] @@ -958,7 +958,7 @@ namespace Microsoft.AspNetCore.Routing.Tests // Assert Assert.Empty(dict); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); Assert.Null(dict._propertyStorage); } @@ -971,14 +971,14 @@ namespace Microsoft.AspNetCore.Routing.Tests { "key", "value" }, }; - var input = new KeyValuePair("key", "value"); + var input = new KeyValuePair("key", "value"); // Act - var result = ((ICollection>)dict).Contains(input); + var result = ((ICollection>)dict).Contains(input); // Assert Assert.True(result); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -990,14 +990,14 @@ namespace Microsoft.AspNetCore.Routing.Tests { "key", "value" }, }; - var input = new KeyValuePair("KEY", "value"); + var input = new KeyValuePair("KEY", "value"); // Act - var result = ((ICollection>)dict).Contains(input); + var result = ((ICollection>)dict).Contains(input); // Assert Assert.True(result); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -1009,14 +1009,14 @@ namespace Microsoft.AspNetCore.Routing.Tests { "key", "value" }, }; - var input = new KeyValuePair("other", "value"); + var input = new KeyValuePair("other", "value"); // Act - var result = ((ICollection>)dict).Contains(input); + var result = ((ICollection>)dict).Contains(input); // Assert Assert.False(result); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } // Value comparisons use the default equality comparer. @@ -1029,14 +1029,14 @@ namespace Microsoft.AspNetCore.Routing.Tests { "key", "value" }, }; - var input = new KeyValuePair("key", "valUE"); + var input = new KeyValuePair("key", "valUE"); // Act - var result = ((ICollection>)dict).Contains(input); + var result = ((ICollection>)dict).Contains(input); // Assert Assert.False(result); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -1045,18 +1045,18 @@ namespace Microsoft.AspNetCore.Routing.Tests // Arrange var dict = new RouteValueDictionary(new { key = "value" }); - var input = new KeyValuePair("key", "value"); + var input = new KeyValuePair("key", "value"); // Act - var result = ((ICollection>)dict).Contains(input); + var result = ((ICollection>)dict).Contains(input); // Assert Assert.True(result); Assert.NotNull(dict._propertyStorage); - Assert.Null(dict._arrayStorage); + AssertEmptyArrayStorage(dict); Assert.Collection( dict, - kvp => Assert.Equal(new KeyValuePair("key", "value"), kvp)); + kvp => Assert.Equal(new KeyValuePair("key", "value"), kvp)); } [Fact] @@ -1065,18 +1065,18 @@ namespace Microsoft.AspNetCore.Routing.Tests // Arrange var dict = new RouteValueDictionary(new { key = "value" }); - var input = new KeyValuePair("KEY", "value"); + var input = new KeyValuePair("KEY", "value"); // Act - var result = ((ICollection>)dict).Contains(input); + var result = ((ICollection>)dict).Contains(input); // Assert Assert.True(result); Assert.NotNull(dict._propertyStorage); - Assert.Null(dict._arrayStorage); + AssertEmptyArrayStorage(dict); Assert.Collection( dict, - kvp => Assert.Equal(new KeyValuePair("key", "value"), kvp)); + kvp => Assert.Equal(new KeyValuePair("key", "value"), kvp)); } [Fact] @@ -1085,18 +1085,18 @@ namespace Microsoft.AspNetCore.Routing.Tests // Arrange var dict = new RouteValueDictionary(new { key = "value" }); - var input = new KeyValuePair("other", "value"); + var input = new KeyValuePair("other", "value"); // Act - var result = ((ICollection>)dict).Contains(input); + var result = ((ICollection>)dict).Contains(input); // Assert Assert.False(result); Assert.NotNull(dict._propertyStorage); - Assert.Null(dict._arrayStorage); + AssertEmptyArrayStorage(dict); Assert.Collection( dict, - kvp => Assert.Equal(new KeyValuePair("key", "value"), kvp)); + kvp => Assert.Equal(new KeyValuePair("key", "value"), kvp)); } // Value comparisons use the default equality comparer. @@ -1106,18 +1106,18 @@ namespace Microsoft.AspNetCore.Routing.Tests // Arrange var dict = new RouteValueDictionary(new { key = "value" }); - var input = new KeyValuePair("key", "valUE"); + var input = new KeyValuePair("key", "valUE"); // Act - var result = ((ICollection>)dict).Contains(input); + var result = ((ICollection>)dict).Contains(input); // Assert Assert.False(result); Assert.NotNull(dict._propertyStorage); - Assert.Null(dict._arrayStorage); + AssertEmptyArrayStorage(dict); Assert.Collection( dict, - kvp => Assert.Equal(new KeyValuePair("key", "value"), kvp)); + kvp => Assert.Equal(new KeyValuePair("key", "value"), kvp)); } [Fact] @@ -1158,7 +1158,7 @@ namespace Microsoft.AspNetCore.Routing.Tests // Assert Assert.False(result); Assert.NotNull(dict._propertyStorage); - Assert.Null(dict._arrayStorage); + AssertEmptyArrayStorage(dict); } [Fact] @@ -1173,7 +1173,7 @@ namespace Microsoft.AspNetCore.Routing.Tests // Assert Assert.True(result); Assert.NotNull(dict._propertyStorage); - Assert.Null(dict._arrayStorage); + AssertEmptyArrayStorage(dict); } [Fact] @@ -1188,7 +1188,7 @@ namespace Microsoft.AspNetCore.Routing.Tests // Assert Assert.True(result); Assert.NotNull(dict._propertyStorage); - Assert.Null(dict._arrayStorage); + AssertEmptyArrayStorage(dict); } [Fact] @@ -1205,7 +1205,7 @@ namespace Microsoft.AspNetCore.Routing.Tests // Assert Assert.False(result); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -1222,7 +1222,7 @@ namespace Microsoft.AspNetCore.Routing.Tests // Assert Assert.True(result); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -1239,7 +1239,7 @@ namespace Microsoft.AspNetCore.Routing.Tests // Assert Assert.True(result); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -1251,20 +1251,20 @@ namespace Microsoft.AspNetCore.Routing.Tests { "key", "value" }, }; - var array = new KeyValuePair[2]; + var array = new KeyValuePair[2]; // Act - ((ICollection>)dict).CopyTo(array, 1); + ((ICollection>)dict).CopyTo(array, 1); // Assert Assert.Equal( - new KeyValuePair[] + new KeyValuePair[] { - default(KeyValuePair), - new KeyValuePair("key", "value") + default(KeyValuePair), + new KeyValuePair("key", "value") }, array); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -1276,15 +1276,15 @@ namespace Microsoft.AspNetCore.Routing.Tests { "key", "value" }, }; - var input = new KeyValuePair("key", "value"); + var input = new KeyValuePair("key", "value"); // Act - var result = ((ICollection>)dict).Remove(input); + var result = ((ICollection>)dict).Remove(input); // Assert Assert.True(result); Assert.Empty(dict); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -1296,15 +1296,15 @@ namespace Microsoft.AspNetCore.Routing.Tests { "key", "value" }, }; - var input = new KeyValuePair("KEY", "value"); + var input = new KeyValuePair("KEY", "value"); // Act - var result = ((ICollection>)dict).Remove(input); + var result = ((ICollection>)dict).Remove(input); // Assert Assert.True(result); Assert.Empty(dict); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -1316,15 +1316,15 @@ namespace Microsoft.AspNetCore.Routing.Tests { "key", "value" }, }; - var input = new KeyValuePair("other", "value"); + var input = new KeyValuePair("other", "value"); // Act - var result = ((ICollection>)dict).Remove(input); + var result = ((ICollection>)dict).Remove(input); // Assert Assert.False(result); Assert.Collection(dict, kvp => { Assert.Equal("key", kvp.Key); Assert.Equal("value", kvp.Value); }); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } // Value comparisons use the default equality comparer. @@ -1337,15 +1337,15 @@ namespace Microsoft.AspNetCore.Routing.Tests { "key", "value" }, }; - var input = new KeyValuePair("key", "valUE"); + var input = new KeyValuePair("key", "valUE"); // Act - var result = ((ICollection>)dict).Remove(input); + var result = ((ICollection>)dict).Remove(input); // Assert Assert.False(result); Assert.Collection(dict, kvp => { Assert.Equal("key", kvp.Key); Assert.Equal("value", kvp.Value); }); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -1401,7 +1401,7 @@ namespace Microsoft.AspNetCore.Routing.Tests // Assert Assert.False(result); Assert.Collection(dict, kvp => { Assert.Equal("key", kvp.Key); Assert.Equal("value", kvp.Value); }); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -1416,7 +1416,7 @@ namespace Microsoft.AspNetCore.Routing.Tests // Assert Assert.True(result); Assert.Empty(dict); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -1431,7 +1431,7 @@ namespace Microsoft.AspNetCore.Routing.Tests // Assert Assert.True(result); Assert.Empty(dict); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -1449,7 +1449,7 @@ namespace Microsoft.AspNetCore.Routing.Tests // Assert Assert.False(result); Assert.Collection(dict, kvp => { Assert.Equal("key", kvp.Key); Assert.Equal("value", kvp.Value); }); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -1467,7 +1467,7 @@ namespace Microsoft.AspNetCore.Routing.Tests // Assert Assert.True(result); Assert.Empty(dict); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -1485,7 +1485,7 @@ namespace Microsoft.AspNetCore.Routing.Tests // Assert Assert.True(result); Assert.Empty(dict); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } @@ -1546,7 +1546,7 @@ namespace Microsoft.AspNetCore.Routing.Tests Assert.False(result); Assert.Null(removedValue); Assert.Collection(dict, kvp => { Assert.Equal("key", kvp.Key); Assert.Equal("value", kvp.Value); }); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -1563,7 +1563,7 @@ namespace Microsoft.AspNetCore.Routing.Tests Assert.True(result); Assert.Same(value, removedValue); Assert.Empty(dict); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -1580,7 +1580,7 @@ namespace Microsoft.AspNetCore.Routing.Tests Assert.True(result); Assert.Same(value, removedValue); Assert.Empty(dict); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -1599,7 +1599,7 @@ namespace Microsoft.AspNetCore.Routing.Tests Assert.False(result); Assert.Null(removedValue); Assert.Collection(dict, kvp => { Assert.Equal("key", kvp.Key); Assert.Equal("value", kvp.Value); }); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -1619,7 +1619,7 @@ namespace Microsoft.AspNetCore.Routing.Tests Assert.True(result); Assert.Same(value, removedValue); Assert.Empty(dict); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -1639,7 +1639,7 @@ namespace Microsoft.AspNetCore.Routing.Tests Assert.True(result); Assert.Same(value, removedValue); Assert.Empty(dict); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -1664,7 +1664,7 @@ namespace Microsoft.AspNetCore.Routing.Tests Assert.False(dict.ContainsKey("key")); Assert.True(dict.ContainsKey("other")); Assert.True(dict.ContainsKey("dotnet")); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -1689,7 +1689,7 @@ namespace Microsoft.AspNetCore.Routing.Tests Assert.False(dict.ContainsKey("key")); Assert.True(dict.ContainsKey("other")); Assert.True(dict.ContainsKey("dotnet")); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -1714,7 +1714,7 @@ namespace Microsoft.AspNetCore.Routing.Tests Assert.False(dict.ContainsKey("key")); Assert.True(dict.ContainsKey("other")); Assert.True(dict.ContainsKey("dotnet")); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -1744,8 +1744,8 @@ namespace Microsoft.AspNetCore.Routing.Tests Assert.Null(dict._propertyStorage); Assert.Collection( dict._arrayStorage, - kvp => Assert.Equal(new KeyValuePair("key", "value"), kvp), - kvp => Assert.Equal(new KeyValuePair("otherKey", "value"), kvp), + kvp => Assert.Equal(new KeyValuePair("key", "value"), kvp), + kvp => Assert.Equal(new KeyValuePair("otherKey", "value"), kvp), kvp => Assert.Equal(default, kvp), kvp => Assert.Equal(default, kvp)); } @@ -1761,11 +1761,11 @@ namespace Microsoft.AspNetCore.Routing.Tests // Assert Assert.False(result); - Assert.Null(dict._arrayStorage); + AssertEmptyArrayStorage(dict); Assert.NotNull(dict._propertyStorage); Assert.Collection( dict, - kvp => Assert.Equal(new KeyValuePair("key", "value"), kvp)); + kvp => Assert.Equal(new KeyValuePair("key", "value"), kvp)); } [Fact] @@ -1781,7 +1781,7 @@ namespace Microsoft.AspNetCore.Routing.Tests Assert.True(result); Assert.Collection( dict._arrayStorage, - kvp => Assert.Equal(new KeyValuePair("key", "value"), kvp), + kvp => Assert.Equal(new KeyValuePair("key", "value"), kvp), kvp => Assert.Equal(default, kvp), kvp => Assert.Equal(default, kvp), kvp => Assert.Equal(default, kvp)); @@ -1803,8 +1803,8 @@ namespace Microsoft.AspNetCore.Routing.Tests Assert.True(result); Assert.Collection( dict._arrayStorage, - kvp => Assert.Equal(new KeyValuePair("key0", "value0"), kvp), - kvp => Assert.Equal(new KeyValuePair("key1", "value1"), kvp), + kvp => Assert.Equal(new KeyValuePair("key0", "value0"), kvp), + kvp => Assert.Equal(new KeyValuePair("key1", "value1"), kvp), kvp => Assert.Equal(default, kvp), kvp => Assert.Equal(default, kvp)); } @@ -1828,11 +1828,11 @@ namespace Microsoft.AspNetCore.Routing.Tests Assert.True(result); Assert.Collection( dict._arrayStorage, - kvp => Assert.Equal(new KeyValuePair("key0", "value0"), kvp), - kvp => Assert.Equal(new KeyValuePair("key1", "value1"), kvp), - kvp => Assert.Equal(new KeyValuePair("key2", "value2"), kvp), - kvp => Assert.Equal(new KeyValuePair("key3", "value3"), kvp), - kvp => Assert.Equal(new KeyValuePair("key4", "value4"), kvp), + kvp => Assert.Equal(new KeyValuePair("key0", "value0"), kvp), + kvp => Assert.Equal(new KeyValuePair("key1", "value1"), kvp), + kvp => Assert.Equal(new KeyValuePair("key2", "value2"), kvp), + kvp => Assert.Equal(new KeyValuePair("key3", "value3"), kvp), + kvp => Assert.Equal(new KeyValuePair("key4", "value4"), kvp), kvp => Assert.Equal(default, kvp), kvp => Assert.Equal(default, kvp), kvp => Assert.Equal(default, kvp)); @@ -1854,7 +1854,7 @@ namespace Microsoft.AspNetCore.Routing.Tests Assert.False(result); Assert.Collection( dict._arrayStorage, - kvp => Assert.Equal(new KeyValuePair("key0", "value0"), kvp), + kvp => Assert.Equal(new KeyValuePair("key0", "value0"), kvp), kvp => Assert.Equal(default, kvp), kvp => Assert.Equal(default, kvp), kvp => Assert.Equal(default, kvp)); @@ -1867,8 +1867,7 @@ namespace Microsoft.AspNetCore.Routing.Tests var dict = new RouteValueDictionary(); // Act - object value; - var result = dict.TryGetValue("key", out value); + var result = dict.TryGetValue("key", out var value); // Assert Assert.False(result); @@ -1896,8 +1895,7 @@ namespace Microsoft.AspNetCore.Routing.Tests var dict = new RouteValueDictionary(new { key = "value" }); // Act - object value; - var result = dict.TryGetValue("other", out value); + var result = dict.TryGetValue("other", out var value); // Assert Assert.False(result); @@ -1912,8 +1910,7 @@ namespace Microsoft.AspNetCore.Routing.Tests var dict = new RouteValueDictionary(new { key = "value" }); // Act - object value; - var result = dict.TryGetValue("key", out value); + var result = dict.TryGetValue("key", out var value); // Assert Assert.True(result); @@ -1928,8 +1925,7 @@ namespace Microsoft.AspNetCore.Routing.Tests var dict = new RouteValueDictionary(new { key = "value" }); // Act - object value; - var result = dict.TryGetValue("kEy", out value); + var result = dict.TryGetValue("kEy", out var value); // Assert Assert.True(result); @@ -1947,13 +1943,12 @@ namespace Microsoft.AspNetCore.Routing.Tests }; // Act - object value; - var result = dict.TryGetValue("other", out value); + var result = dict.TryGetValue("other", out var value); // Assert Assert.False(result); Assert.Null(value); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -1966,13 +1961,12 @@ namespace Microsoft.AspNetCore.Routing.Tests }; // Act - object value; - var result = dict.TryGetValue("key", out value); + var result = dict.TryGetValue("key", out var value); // Assert Assert.True(result); Assert.Equal("value", value); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -1985,13 +1979,12 @@ namespace Microsoft.AspNetCore.Routing.Tests }; // Act - object value; - var result = dict.TryGetValue("kEy", out value); + var result = dict.TryGetValue("kEy", out var value); // Assert Assert.True(result); Assert.Equal("value", value); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -2004,7 +1997,7 @@ namespace Microsoft.AspNetCore.Routing.Tests dict.Add("key", "value"); // Assert 1 - var storage = Assert.IsType[]>(dict._arrayStorage); + var storage = Assert.IsType[]>(dict._arrayStorage); Assert.Equal(4, storage.Length); // Act 2 @@ -2014,7 +2007,7 @@ namespace Microsoft.AspNetCore.Routing.Tests dict.Add("key5", "value5"); // Assert 2 - storage = Assert.IsType[]>(dict._arrayStorage); + storage = Assert.IsType[]>(dict._arrayStorage); Assert.Equal(8, storage.Length); } @@ -2028,14 +2021,14 @@ namespace Microsoft.AspNetCore.Routing.Tests dict.Add("key3", "value3"); // Assert 1 - var storage = Assert.IsType[]>(dict._arrayStorage); + var storage = Assert.IsType[]>(dict._arrayStorage); Assert.Equal(3, dict.Count); // Act dict.Remove("key2"); // Assert 2 - storage = Assert.IsType[]>(dict._arrayStorage); + storage = Assert.IsType[]>(dict._arrayStorage); Assert.Equal(2, dict.Count); Assert.Equal("key", storage[0].Key); Assert.Equal("value", storage[0].Value); @@ -2047,17 +2040,17 @@ namespace Microsoft.AspNetCore.Routing.Tests public void FromArray_TakesOwnershipOfArray() { // Arrange - var array = new KeyValuePair[] + var array = new KeyValuePair[] { - new KeyValuePair("a", 0), - new KeyValuePair("b", 1), - new KeyValuePair("c", 2), + new KeyValuePair("a", 0), + new KeyValuePair("b", 1), + new KeyValuePair("c", 2), }; var dictionary = RouteValueDictionary.FromArray(array); // Act - modifying the array should modify the dictionary - array[0] = new KeyValuePair("aa", 10); + array[0] = new KeyValuePair("aa", 10); // Assert Assert.Equal(3, dictionary.Count); @@ -2068,7 +2061,7 @@ namespace Microsoft.AspNetCore.Routing.Tests public void FromArray_EmptyArray() { // Arrange - var array = Array.Empty>(); + var array = Array.Empty>(); // Act var dictionary = RouteValueDictionary.FromArray(array); @@ -2081,16 +2074,16 @@ namespace Microsoft.AspNetCore.Routing.Tests public void FromArray_RemovesGapsInArray() { // Arrange - var array = new KeyValuePair[] + var array = new KeyValuePair[] { - new KeyValuePair(null, null), - new KeyValuePair("a", 0), - new KeyValuePair(null, null), - new KeyValuePair(null, null), - new KeyValuePair("b", 1), - new KeyValuePair("c", 2), - new KeyValuePair("d", 3), - new KeyValuePair(null, null), + new KeyValuePair(null!, null), + new KeyValuePair("a", 0), + new KeyValuePair(null!, null), + new KeyValuePair(null!, null), + new KeyValuePair("b", 1), + new KeyValuePair("c", 2), + new KeyValuePair("d", 3), + new KeyValuePair(null!, null), }; // Act - calling From should modify the array @@ -2099,20 +2092,25 @@ namespace Microsoft.AspNetCore.Routing.Tests // Assert Assert.Equal(4, dictionary.Count); Assert.Equal( - new KeyValuePair[] + new KeyValuePair[] { - new KeyValuePair("d", 3), - new KeyValuePair("a", 0), - new KeyValuePair("c", 2), - new KeyValuePair("b", 1), - new KeyValuePair(null, null), - new KeyValuePair(null, null), - new KeyValuePair(null, null), - new KeyValuePair(null, null), + new KeyValuePair("d", 3), + new KeyValuePair("a", 0), + new KeyValuePair("c", 2), + new KeyValuePair("b", 1), + new KeyValuePair(null!, null), + new KeyValuePair(null!, null), + new KeyValuePair(null!, null), + new KeyValuePair(null!, null), }, array); } + private void AssertEmptyArrayStorage(RouteValueDictionary value) + { + Assert.Same(Array.Empty>(), value._arrayStorage); + } + private class RegularType { public bool IsAwesome { get; set; } @@ -2122,7 +2120,7 @@ namespace Microsoft.AspNetCore.Routing.Tests private class Visibility { - private string PrivateYo { get; set; } + private string? PrivateYo { get; set; } internal int ItsInternalDealWithIt { get; set; } @@ -2167,9 +2165,9 @@ namespace Microsoft.AspNetCore.Routing.Tests private class Address { - public string City { get; set; } + public string? City { get; set; } - public string State { get; set; } + public string? State { get; set; } } } -} \ No newline at end of file +} diff --git a/src/Http/Http.Abstractions/test/UseMiddlewareTest.cs b/src/Http/Http.Abstractions/test/UseMiddlewareTest.cs index 749309319f..71fd2324d9 100644 --- a/src/Http/Http.Abstractions/test/UseMiddlewareTest.cs +++ b/src/Http/Http.Abstractions/test/UseMiddlewareTest.cs @@ -244,10 +244,10 @@ namespace Microsoft.AspNetCore.Http public class BasicMiddlewareFactory : IMiddlewareFactory { - public IMiddleware Created { get; private set; } - public IMiddleware Released { get; private set; } + public IMiddleware? Created { get; private set; } + public IMiddleware? Released { get; private set; } - public IMiddleware Create(Type middlewareType) + public IMiddleware? Create(Type middlewareType) { Created = Activator.CreateInstance(middlewareType) as IMiddleware; return Created; @@ -261,7 +261,7 @@ namespace Microsoft.AspNetCore.Http public class BadMiddlewareFactory : IMiddlewareFactory { - public IMiddleware Create(Type middlewareType) => null; + public IMiddleware? Create(Type middlewareType) => null; public void Release(IMiddleware middleware) { } } @@ -272,14 +272,14 @@ namespace Microsoft.AspNetCore.Http public void AddService(Type type, object value) => _services[type] = value; - public object GetService(Type serviceType) + public object? GetService(Type serviceType) { if (serviceType == typeof(IServiceProvider)) { return this; } - if (_services.TryGetValue(serviceType, out object value)) + if (_services.TryGetValue(serviceType, out var value)) { return value; } @@ -291,7 +291,7 @@ namespace Microsoft.AspNetCore.Http { public MiddlewareInjectWithOutAndRefParams(RequestDelegate next) { } - public Task Invoke(HttpContext context, ref IServiceProvider sp1, out IServiceProvider sp2) + public Task Invoke(HttpContext context, ref IServiceProvider? sp1, out IServiceProvider? sp2) { sp1 = null; sp2 = null; diff --git a/src/Http/Http.Abstractions/test/UsePathBaseExtensionsTests.cs b/src/Http/Http.Abstractions/test/UsePathBaseExtensionsTests.cs index e5f7903bc5..f67d23487f 100644 --- a/src/Http/Http.Abstractions/test/UsePathBaseExtensionsTests.cs +++ b/src/Http/Http.Abstractions/test/UsePathBaseExtensionsTests.cs @@ -145,8 +145,9 @@ namespace Microsoft.AspNetCore.Builder.Extensions await builder.Build().Invoke(requestContext); // Assert path and pathBase are split after middleware - Assert.Equal(expectedPath, ((PathString)requestContext.Items["test.Path"]).Value); - Assert.Equal(expectedPathBase, ((PathString)requestContext.Items["test.PathBase"]).Value); + Assert.Equal(expectedPath, ((PathString?)requestContext.Items["test.Path"])!.Value.Value); + Assert.Equal(expectedPathBase, ((PathString?)requestContext.Items["test.PathBase"])!.Value.Value); + // Assert path and pathBase are reset after request Assert.Equal(pathBase, requestContext.Request.PathBase.Value); Assert.Equal(requestPath, requestContext.Request.Path.Value); diff --git a/src/Http/Http.Abstractions/test/UseWhenExtensionsTests.cs b/src/Http/Http.Abstractions/test/UseWhenExtensionsTests.cs index 901454b62e..2173df9138 100644 --- a/src/Http/Http.Abstractions/test/UseWhenExtensionsTests.cs +++ b/src/Http/Http.Abstractions/test/UseWhenExtensionsTests.cs @@ -18,8 +18,8 @@ namespace Microsoft.AspNetCore.Builder.Extensions var builder = CreateBuilder(); // Act - Action nullPredicate = () => builder.UseWhen(null, app => { }); - Action nullConfiguration = () => builder.UseWhen(TruePredicate, null); + Action nullPredicate = () => builder.UseWhen(null!, app => { }); + Action nullConfiguration = () => builder.UseWhen(TruePredicate, null!); // Assert Assert.Throws(nullPredicate); @@ -146,7 +146,7 @@ namespace Microsoft.AspNetCore.Builder.Extensions } } - return terminate ? Task.FromResult(null) : next(); + return terminate ? Task.FromResult(null) : next(); }; } diff --git a/src/Http/Http.Features/ref/Microsoft.AspNetCore.Http.Features.csproj b/src/Http/Http.Features/ref/Microsoft.AspNetCore.Http.Features.csproj index 3009140234..af5a85a960 100644 --- a/src/Http/Http.Features/ref/Microsoft.AspNetCore.Http.Features.csproj +++ b/src/Http/Http.Features/ref/Microsoft.AspNetCore.Http.Features.csproj @@ -3,6 +3,7 @@ netstandard2.0;$(DefaultNetCoreTargetFramework) $(DefaultNetCoreTargetFramework) + annotations diff --git a/src/Http/Http.Features/ref/Microsoft.AspNetCore.Http.Features.netcoreapp.cs b/src/Http/Http.Features/ref/Microsoft.AspNetCore.Http.Features.netcoreapp.cs index 45f7f9d135..76eaa03447 100644 --- a/src/Http/Http.Features/ref/Microsoft.AspNetCore.Http.Features.netcoreapp.cs +++ b/src/Http/Http.Features/ref/Microsoft.AspNetCore.Http.Features.netcoreapp.cs @@ -6,12 +6,12 @@ namespace Microsoft.AspNetCore.Http public partial class CookieOptions { public CookieOptions() { } - public string Domain { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public string? Domain { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } public System.DateTimeOffset? Expires { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } public bool HttpOnly { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } public bool IsEssential { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } public System.TimeSpan? MaxAge { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } - public string Path { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public string? Path { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } public Microsoft.AspNetCore.Http.SameSiteMode SameSite { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } public bool Secure { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } } @@ -92,7 +92,7 @@ namespace Microsoft.AspNetCore.Http public partial class WebSocketAcceptContext { public WebSocketAcceptContext() { } - public virtual string SubProtocol { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public virtual string? SubProtocol { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } } } namespace Microsoft.AspNetCore.Http.Features @@ -102,9 +102,10 @@ namespace Microsoft.AspNetCore.Http.Features public FeatureCollection() { } public FeatureCollection(Microsoft.AspNetCore.Http.Features.IFeatureCollection defaults) { } public bool IsReadOnly { get { throw null; } } - public object this[System.Type key] { get { throw null; } set { } } + public object? this[System.Type key] { get { throw null; } set { } } public virtual int Revision { get { throw null; } } public System.Collections.Generic.IEnumerator> GetEnumerator() { throw null; } + [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] public TFeature Get() { throw null; } public void Set(TFeature instance) { } System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { throw null; } @@ -114,12 +115,14 @@ namespace Microsoft.AspNetCore.Http.Features { private object _dummy; private int _dummyPrimitive; + [System.Diagnostics.CodeAnalysis.AllowNullAttribute] + [System.Diagnostics.CodeAnalysis.MaybeNullAttribute] public TCache Cache; public FeatureReferences(Microsoft.AspNetCore.Http.Features.IFeatureCollection collection) { throw null; } public Microsoft.AspNetCore.Http.Features.IFeatureCollection Collection { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } public int Revision { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } - public TFeature Fetch(ref TFeature cached, System.Func factory) where TFeature : class { throw null; } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]public TFeature Fetch(ref TFeature cached, TState state, System.Func factory) where TFeature : class { throw null; } + public TFeature Fetch([System.Diagnostics.CodeAnalysis.AllowNullAttribute, System.Diagnostics.CodeAnalysis.MaybeNullAttribute] ref TFeature cached, System.Func factory) where TFeature : class { throw null; } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]public TFeature Fetch([System.Diagnostics.CodeAnalysis.AllowNullAttribute, System.Diagnostics.CodeAnalysis.MaybeNullAttribute] ref TFeature cached, TState state, System.Func factory) where TFeature : class { throw null; } [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]public void Initalize(Microsoft.AspNetCore.Http.Features.IFeatureCollection collection) { } [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]public void Initalize(Microsoft.AspNetCore.Http.Features.IFeatureCollection collection, int revision) { } } @@ -129,6 +132,7 @@ namespace Microsoft.AspNetCore.Http.Features private T _feature; private int _dummyPrimitive; public static readonly Microsoft.AspNetCore.Http.Features.FeatureReference Default; + [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] public T Fetch(Microsoft.AspNetCore.Http.Features.IFeatureCollection features) { throw null; } public T Update(Microsoft.AspNetCore.Http.Features.IFeatureCollection features, T feature) { throw null; } } @@ -141,7 +145,7 @@ namespace Microsoft.AspNetCore.Http.Features public partial interface IFeatureCollection : System.Collections.Generic.IEnumerable>, System.Collections.IEnumerable { bool IsReadOnly { get; } - object this[System.Type key] { get; set; } + object? this[System.Type key] { get; set; } int Revision { get; } TFeature Get(); void Set(TFeature instance); diff --git a/src/Http/Http.Features/ref/Microsoft.AspNetCore.Http.Features.netstandard2.0.cs b/src/Http/Http.Features/ref/Microsoft.AspNetCore.Http.Features.netstandard2.0.cs index 45f7f9d135..802000e099 100644 --- a/src/Http/Http.Features/ref/Microsoft.AspNetCore.Http.Features.netstandard2.0.cs +++ b/src/Http/Http.Features/ref/Microsoft.AspNetCore.Http.Features.netstandard2.0.cs @@ -6,12 +6,12 @@ namespace Microsoft.AspNetCore.Http public partial class CookieOptions { public CookieOptions() { } - public string Domain { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public string? Domain { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } public System.DateTimeOffset? Expires { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } public bool HttpOnly { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } public bool IsEssential { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } public System.TimeSpan? MaxAge { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } - public string Path { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public string? Path { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } public Microsoft.AspNetCore.Http.SameSiteMode SameSite { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } public bool Secure { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } } @@ -92,7 +92,7 @@ namespace Microsoft.AspNetCore.Http public partial class WebSocketAcceptContext { public WebSocketAcceptContext() { } - public virtual string SubProtocol { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public virtual string? SubProtocol { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } } } namespace Microsoft.AspNetCore.Http.Features @@ -102,7 +102,7 @@ namespace Microsoft.AspNetCore.Http.Features public FeatureCollection() { } public FeatureCollection(Microsoft.AspNetCore.Http.Features.IFeatureCollection defaults) { } public bool IsReadOnly { get { throw null; } } - public object this[System.Type key] { get { throw null; } set { } } + public object? this[System.Type key] { get { throw null; } set { } } public virtual int Revision { get { throw null; } } public System.Collections.Generic.IEnumerator> GetEnumerator() { throw null; } public TFeature Get() { throw null; } @@ -141,7 +141,7 @@ namespace Microsoft.AspNetCore.Http.Features public partial interface IFeatureCollection : System.Collections.Generic.IEnumerable>, System.Collections.IEnumerable { bool IsReadOnly { get; } - object this[System.Type key] { get; set; } + object? this[System.Type key] { get; set; } int Revision { get; } TFeature Get(); void Set(TFeature instance); diff --git a/src/Http/Http.Features/src/CookieOptions.cs b/src/Http/Http.Features/src/CookieOptions.cs index 833eeedea2..74512d2360 100644 --- a/src/Http/Http.Features/src/CookieOptions.cs +++ b/src/Http/Http.Features/src/CookieOptions.cs @@ -22,13 +22,13 @@ namespace Microsoft.AspNetCore.Http /// Gets or sets the domain to associate the cookie with. /// /// The domain to associate the cookie with. - public string Domain { get; set; } + public string? Domain { get; set; } /// /// Gets or sets the cookie path. /// /// The cookie path. - public string Path { get; set; } + public string? Path { get; set; } /// /// Gets or sets the expiration date and time for the cookie. diff --git a/src/Http/Http.Features/src/FeatureCollection.cs b/src/Http/Http.Features/src/FeatureCollection.cs index e79ecfee22..b5f70b7c4e 100644 --- a/src/Http/Http.Features/src/FeatureCollection.cs +++ b/src/Http/Http.Features/src/FeatureCollection.cs @@ -4,6 +4,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Linq; namespace Microsoft.AspNetCore.Http.Features @@ -11,8 +12,8 @@ namespace Microsoft.AspNetCore.Http.Features public class FeatureCollection : IFeatureCollection { private static KeyComparer FeatureKeyComparer = new KeyComparer(); - private readonly IFeatureCollection _defaults; - private IDictionary _features; + private readonly IFeatureCollection? _defaults; + private IDictionary? _features; private volatile int _containerRevision; public FeatureCollection() @@ -31,7 +32,7 @@ namespace Microsoft.AspNetCore.Http.Features public bool IsReadOnly { get { return false; } } - public object this[Type key] + public object? this[Type key] { get { @@ -40,7 +41,7 @@ namespace Microsoft.AspNetCore.Http.Features throw new ArgumentNullException(nameof(key)); } - object result; + object? result; return _features != null && _features.TryGetValue(key, out result) ? result : _defaults?[key]; } set @@ -93,6 +94,7 @@ namespace Microsoft.AspNetCore.Http.Features } } + [return: MaybeNull] public TFeature Get() { return (TFeature)this[typeof(TFeature)]; @@ -116,4 +118,4 @@ namespace Microsoft.AspNetCore.Http.Features } } } -} \ No newline at end of file +} diff --git a/src/Http/Http.Features/src/FeatureReference.cs b/src/Http/Http.Features/src/FeatureReference.cs index 5016602123..516fb70e90 100644 --- a/src/Http/Http.Features/src/FeatureReference.cs +++ b/src/Http/Http.Features/src/FeatureReference.cs @@ -1,6 +1,8 @@ // 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.Diagnostics.CodeAnalysis; + namespace Microsoft.AspNetCore.Http.Features { public struct FeatureReference @@ -14,15 +16,16 @@ namespace Microsoft.AspNetCore.Http.Features _revision = revision; } - public static readonly FeatureReference Default = new FeatureReference(default(T), -1); + public static readonly FeatureReference Default = new FeatureReference(default(T)!, -1); + [return: MaybeNull] public T Fetch(IFeatureCollection features) { if (_revision == features.Revision) { return _feature; } - _feature = (T)features[typeof(T)]; + _feature = (T)features[typeof(T)]!; _revision = features.Revision; return _feature; } @@ -35,4 +38,4 @@ namespace Microsoft.AspNetCore.Http.Features return feature; } } -} \ No newline at end of file +} diff --git a/src/Http/Http.Features/src/FeatureReferences.cs b/src/Http/Http.Features/src/FeatureReferences.cs index f19938bfe9..fa32c41347 100644 --- a/src/Http/Http.Features/src/FeatureReferences.cs +++ b/src/Http/Http.Features/src/FeatureReferences.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; namespace Microsoft.AspNetCore.Http.Features @@ -36,6 +37,7 @@ namespace Microsoft.AspNetCore.Http.Features // be able to pass ref values that "dot through" the TCache struct memory, // if it was a Property then that getter would return a copy of the memory // preventing the use of "ref" + [AllowNull, MaybeNull] public TCache Cache; // Careful with modifications to the Fetch method; it is carefully constructed for inlining @@ -60,7 +62,7 @@ namespace Microsoft.AspNetCore.Http.Features // Generally Fetch is called at a ratio > x4 of UpdateCached so this is a large gain [MethodImpl(MethodImplOptions.AggressiveInlining)] public TFeature Fetch( - ref TFeature cached, + [AllowNull, MaybeNull]ref TFeature cached, TState state, Func factory) where TFeature : class { @@ -69,12 +71,12 @@ namespace Microsoft.AspNetCore.Http.Features if (Revision != revision) { // Clear cached value to force call to UpdateCached - cached = null; + cached = null!; // Collection changed, clear whole feature cache flush = true; } - return cached ?? UpdateCached(ref cached, state, factory, revision, flush); + return cached ?? UpdateCached(ref cached!, state, factory, revision, flush); } // Update and cache clearing logic, when the fast-path in Fetch isn't applicable @@ -106,8 +108,8 @@ namespace Microsoft.AspNetCore.Http.Features return cached; } - public TFeature Fetch(ref TFeature cached, Func factory) - where TFeature : class => Fetch(ref cached, Collection, factory); + public TFeature Fetch([AllowNull, MaybeNull]ref TFeature cached, Func factory) + where TFeature : class => Fetch(ref cached!, Collection, factory); private static int ContextDisposed() { diff --git a/src/Http/Http.Features/src/IFeatureCollection.cs b/src/Http/Http.Features/src/IFeatureCollection.cs index f7b23ed16f..6d087df337 100644 --- a/src/Http/Http.Features/src/IFeatureCollection.cs +++ b/src/Http/Http.Features/src/IFeatureCollection.cs @@ -26,7 +26,7 @@ namespace Microsoft.AspNetCore.Http.Features /// /// /// The requested feature, or null if it is not present. - object this[Type key] { get; set; } + object? this[Type key] { get; set; } /// /// Retrieves the requested feature from the collection. diff --git a/src/Http/Http.Features/src/Microsoft.AspNetCore.Http.Features.csproj b/src/Http/Http.Features/src/Microsoft.AspNetCore.Http.Features.csproj index 85f9fdc847..0b7b768ca7 100644 --- a/src/Http/Http.Features/src/Microsoft.AspNetCore.Http.Features.csproj +++ b/src/Http/Http.Features/src/Microsoft.AspNetCore.Http.Features.csproj @@ -1,4 +1,4 @@ - + ASP.NET Core HTTP feature interface definitions. @@ -8,8 +8,10 @@ $(NoWarn);CS1591 true aspnetcore + enable + diff --git a/src/Http/Http.Features/src/WebSocketAcceptContext.cs b/src/Http/Http.Features/src/WebSocketAcceptContext.cs index 5e3659d647..beb7e0a59d 100644 --- a/src/Http/Http.Features/src/WebSocketAcceptContext.cs +++ b/src/Http/Http.Features/src/WebSocketAcceptContext.cs @@ -5,6 +5,6 @@ namespace Microsoft.AspNetCore.Http { public class WebSocketAcceptContext { - public virtual string SubProtocol { get; set; } + public virtual string? SubProtocol { get; set; } } -} \ No newline at end of file +} diff --git a/src/Http/Http.Features/test/FeatureCollectionTests.cs b/src/Http/Http.Features/test/FeatureCollectionTests.cs index 36ad77f678..a09ad7cedf 100644 --- a/src/Http/Http.Features/test/FeatureCollectionTests.cs +++ b/src/Http/Http.Features/test/FeatureCollectionTests.cs @@ -15,7 +15,7 @@ namespace Microsoft.AspNetCore.Http.Features interfaces[typeof(IThing)] = thing; - object thing2 = interfaces[typeof(IThing)]; + var thing2 = interfaces[typeof(IThing)]; Assert.Equal(thing2, thing); } @@ -41,7 +41,7 @@ namespace Microsoft.AspNetCore.Http.Features interfaces[typeof(IThing)] = null; - object thing2 = interfaces[typeof(IThing)]; + var thing2 = interfaces[typeof(IThing)]; Assert.Null(thing2); } } diff --git a/src/Http/Http.Features/test/Microsoft.AspNetCore.Http.Features.Tests.csproj b/src/Http/Http.Features/test/Microsoft.AspNetCore.Http.Features.Tests.csproj index 1a041d50b7..44552938d5 100644 --- a/src/Http/Http.Features/test/Microsoft.AspNetCore.Http.Features.Tests.csproj +++ b/src/Http/Http.Features/test/Microsoft.AspNetCore.Http.Features.Tests.csproj @@ -2,6 +2,7 @@ $(DefaultNetCoreTargetFramework) + enable diff --git a/src/Http/Http/ref/Microsoft.AspNetCore.Http.netcoreapp.cs b/src/Http/Http/ref/Microsoft.AspNetCore.Http.netcoreapp.cs index ed6962230f..4cadeb6789 100644 --- a/src/Http/Http/ref/Microsoft.AspNetCore.Http.netcoreapp.cs +++ b/src/Http/Http/ref/Microsoft.AspNetCore.Http.netcoreapp.cs @@ -64,7 +64,7 @@ namespace Microsoft.AspNetCore.Http public System.Collections.Generic.ICollection Keys { get { throw null; } } public bool ContainsKey(string key) { throw null; } public Microsoft.AspNetCore.Http.FormCollection.Enumerator GetEnumerator() { throw null; } - System.Collections.Generic.IEnumerator> System.Collections.Generic.IEnumerable>.GetEnumerator() { throw null; } + System.Collections.Generic.IEnumerator> System.Collections.Generic.IEnumerable>.GetEnumerator() { throw null; } System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { throw null; } public bool TryGetValue(string key, out Microsoft.Extensions.Primitives.StringValues value) { throw null; } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] @@ -110,7 +110,7 @@ namespace Microsoft.AspNetCore.Http public bool IsReadOnly { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } public Microsoft.Extensions.Primitives.StringValues this[string key] { get { throw null; } set { } } public System.Collections.Generic.ICollection Keys { get { throw null; } } - Microsoft.Extensions.Primitives.StringValues System.Collections.Generic.IDictionary.this[string key] { get { throw null; } set { } } + Microsoft.Extensions.Primitives.StringValues System.Collections.Generic.IDictionary.this[string key] { get { throw null; } set { } } public System.Collections.Generic.ICollection Values { get { throw null; } } public void Add(System.Collections.Generic.KeyValuePair item) { } public void Add(string key, Microsoft.Extensions.Primitives.StringValues value) { } @@ -121,7 +121,7 @@ namespace Microsoft.AspNetCore.Http public Microsoft.AspNetCore.Http.HeaderDictionary.Enumerator GetEnumerator() { throw null; } public bool Remove(System.Collections.Generic.KeyValuePair item) { throw null; } public bool Remove(string key) { throw null; } - System.Collections.Generic.IEnumerator> System.Collections.Generic.IEnumerable>.GetEnumerator() { throw null; } + System.Collections.Generic.IEnumerator> System.Collections.Generic.IEnumerable>.GetEnumerator() { throw null; } System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { throw null; } public bool TryGetValue(string key, out Microsoft.Extensions.Primitives.StringValues value) { throw null; } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] @@ -176,7 +176,7 @@ namespace Microsoft.AspNetCore.Http public System.Collections.Generic.ICollection Keys { get { throw null; } } public bool ContainsKey(string key) { throw null; } public Microsoft.AspNetCore.Http.QueryCollection.Enumerator GetEnumerator() { throw null; } - System.Collections.Generic.IEnumerator> System.Collections.Generic.IEnumerable>.GetEnumerator() { throw null; } + System.Collections.Generic.IEnumerator> System.Collections.Generic.IEnumerable>.GetEnumerator() { throw null; } System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { throw null; } public bool TryGetValue(string key, out Microsoft.Extensions.Primitives.StringValues value) { throw null; } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] diff --git a/src/Http/HttpAbstractions.sln b/src/Http/HttpAbstractions.sln index e2595c4f40..8c2474ef3d 100644 --- a/src/Http/HttpAbstractions.sln +++ b/src/Http/HttpAbstractions.sln @@ -117,6 +117,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Author EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Cors", "..\Middleware\CORS\src\Microsoft.AspNetCore.Cors.csproj", "{09168958-FD5B-4D25-8FBF-75E2C80D903B}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Metadata", "Metadata", "{B1C66DEF-EBEE-4F3C-A5F5-65FA9964AC67}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Metadata", "Metadata\src\Microsoft.AspNetCore.Metadata.csproj", "{CAAB06B8-0E70-49FE-92A5-46A35A089481}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -631,6 +635,18 @@ Global {09168958-FD5B-4D25-8FBF-75E2C80D903B}.Release|x64.Build.0 = Release|Any CPU {09168958-FD5B-4D25-8FBF-75E2C80D903B}.Release|x86.ActiveCfg = Release|Any CPU {09168958-FD5B-4D25-8FBF-75E2C80D903B}.Release|x86.Build.0 = Release|Any CPU + {CAAB06B8-0E70-49FE-92A5-46A35A089481}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CAAB06B8-0E70-49FE-92A5-46A35A089481}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CAAB06B8-0E70-49FE-92A5-46A35A089481}.Debug|x64.ActiveCfg = Debug|Any CPU + {CAAB06B8-0E70-49FE-92A5-46A35A089481}.Debug|x64.Build.0 = Debug|Any CPU + {CAAB06B8-0E70-49FE-92A5-46A35A089481}.Debug|x86.ActiveCfg = Debug|Any CPU + {CAAB06B8-0E70-49FE-92A5-46A35A089481}.Debug|x86.Build.0 = Debug|Any CPU + {CAAB06B8-0E70-49FE-92A5-46A35A089481}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CAAB06B8-0E70-49FE-92A5-46A35A089481}.Release|Any CPU.Build.0 = Release|Any CPU + {CAAB06B8-0E70-49FE-92A5-46A35A089481}.Release|x64.ActiveCfg = Release|Any CPU + {CAAB06B8-0E70-49FE-92A5-46A35A089481}.Release|x64.Build.0 = Release|Any CPU + {CAAB06B8-0E70-49FE-92A5-46A35A089481}.Release|x86.ActiveCfg = Release|Any CPU + {CAAB06B8-0E70-49FE-92A5-46A35A089481}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -681,6 +697,7 @@ Global {21AC56E7-4E77-4B0E-B63E-C8E836E4D14E} = {80A090C8-ED02-4DE3-875A-30DCCDBD84BA} {8BCAA9EC-0ACD-435C-BF8A-8C843499FF7B} = {793FFE24-138A-4C3D-81AB-18D625E36230} {09168958-FD5B-4D25-8FBF-75E2C80D903B} = {793FFE24-138A-4C3D-81AB-18D625E36230} + {CAAB06B8-0E70-49FE-92A5-46A35A089481} = {B1C66DEF-EBEE-4F3C-A5F5-65FA9964AC67} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {85B5E151-2E9D-419C-83DD-0DDCF446C83A} diff --git a/src/Http/Metadata/ref/Microsoft.AspNetCore.Metadata.csproj b/src/Http/Metadata/ref/Microsoft.AspNetCore.Metadata.csproj index 75a5dfb139..76bdd78a7c 100644 --- a/src/Http/Metadata/ref/Microsoft.AspNetCore.Metadata.csproj +++ b/src/Http/Metadata/ref/Microsoft.AspNetCore.Metadata.csproj @@ -3,6 +3,7 @@ netstandard2.0;$(DefaultNetCoreTargetFramework) $(DefaultNetCoreTargetFramework) + annotations diff --git a/src/Http/Metadata/ref/Microsoft.AspNetCore.Metadata.netcoreapp.cs b/src/Http/Metadata/ref/Microsoft.AspNetCore.Metadata.netcoreapp.cs index effddb3203..97888d8eec 100644 --- a/src/Http/Metadata/ref/Microsoft.AspNetCore.Metadata.netcoreapp.cs +++ b/src/Http/Metadata/ref/Microsoft.AspNetCore.Metadata.netcoreapp.cs @@ -8,8 +8,8 @@ namespace Microsoft.AspNetCore.Authorization } public partial interface IAuthorizeData { - string AuthenticationSchemes { get; set; } - string Policy { get; set; } - string Roles { get; set; } + string? AuthenticationSchemes { get; set; } + string? Policy { get; set; } + string? Roles { get; set; } } } diff --git a/src/Http/Metadata/ref/Microsoft.AspNetCore.Metadata.netstandard2.0.cs b/src/Http/Metadata/ref/Microsoft.AspNetCore.Metadata.netstandard2.0.cs index effddb3203..97888d8eec 100644 --- a/src/Http/Metadata/ref/Microsoft.AspNetCore.Metadata.netstandard2.0.cs +++ b/src/Http/Metadata/ref/Microsoft.AspNetCore.Metadata.netstandard2.0.cs @@ -8,8 +8,8 @@ namespace Microsoft.AspNetCore.Authorization } public partial interface IAuthorizeData { - string AuthenticationSchemes { get; set; } - string Policy { get; set; } - string Roles { get; set; } + string? AuthenticationSchemes { get; set; } + string? Policy { get; set; } + string? Roles { get; set; } } } diff --git a/src/Http/Metadata/src/IAuthorizeData.cs b/src/Http/Metadata/src/IAuthorizeData.cs index 1196db82d4..3aa738bf00 100644 --- a/src/Http/Metadata/src/IAuthorizeData.cs +++ b/src/Http/Metadata/src/IAuthorizeData.cs @@ -11,16 +11,16 @@ namespace Microsoft.AspNetCore.Authorization /// /// Gets or sets the policy name that determines access to the resource. /// - string Policy { get; set; } + string? Policy { get; set; } /// /// Gets or sets a comma delimited list of roles that are allowed to access the resource. /// - string Roles { get; set; } + string? Roles { get; set; } /// /// Gets or sets a comma delimited list of schemes from which user information is constructed. /// - string AuthenticationSchemes { get; set; } + string? AuthenticationSchemes { get; set; } } } diff --git a/src/Http/Metadata/src/Microsoft.AspNetCore.Metadata.csproj b/src/Http/Metadata/src/Microsoft.AspNetCore.Metadata.csproj index 7869ec0eb5..0a760c3f29 100644 --- a/src/Http/Metadata/src/Microsoft.AspNetCore.Metadata.csproj +++ b/src/Http/Metadata/src/Microsoft.AspNetCore.Metadata.csproj @@ -7,6 +7,7 @@ $(NoWarn);CS1591 true aspnetcore + enable diff --git a/src/Http/Routing.Abstractions/ref/Microsoft.AspNetCore.Routing.Abstractions.csproj b/src/Http/Routing.Abstractions/ref/Microsoft.AspNetCore.Routing.Abstractions.csproj index f4cfdfddb8..92bfe8bb84 100644 --- a/src/Http/Routing.Abstractions/ref/Microsoft.AspNetCore.Routing.Abstractions.csproj +++ b/src/Http/Routing.Abstractions/ref/Microsoft.AspNetCore.Routing.Abstractions.csproj @@ -2,6 +2,7 @@ $(DefaultNetCoreTargetFramework) + annotations diff --git a/src/Http/Routing.Abstractions/ref/Microsoft.AspNetCore.Routing.Abstractions.netcoreapp.cs b/src/Http/Routing.Abstractions/ref/Microsoft.AspNetCore.Routing.Abstractions.netcoreapp.cs index 6aea07474a..12862c2b4d 100644 --- a/src/Http/Routing.Abstractions/ref/Microsoft.AspNetCore.Routing.Abstractions.netcoreapp.cs +++ b/src/Http/Routing.Abstractions/ref/Microsoft.AspNetCore.Routing.Abstractions.netcoreapp.cs @@ -30,10 +30,10 @@ namespace Microsoft.AspNetCore.Routing public abstract partial class LinkGenerator { protected LinkGenerator() { } - public abstract string GetPathByAddress(Microsoft.AspNetCore.Http.HttpContext httpContext, TAddress address, Microsoft.AspNetCore.Routing.RouteValueDictionary values, Microsoft.AspNetCore.Routing.RouteValueDictionary ambientValues = null, Microsoft.AspNetCore.Http.PathString? pathBase = default(Microsoft.AspNetCore.Http.PathString?), Microsoft.AspNetCore.Http.FragmentString fragment = default(Microsoft.AspNetCore.Http.FragmentString), Microsoft.AspNetCore.Routing.LinkOptions options = null); - public abstract string GetPathByAddress(TAddress address, Microsoft.AspNetCore.Routing.RouteValueDictionary values, Microsoft.AspNetCore.Http.PathString pathBase = default(Microsoft.AspNetCore.Http.PathString), Microsoft.AspNetCore.Http.FragmentString fragment = default(Microsoft.AspNetCore.Http.FragmentString), Microsoft.AspNetCore.Routing.LinkOptions options = null); - public abstract string GetUriByAddress(Microsoft.AspNetCore.Http.HttpContext httpContext, TAddress address, Microsoft.AspNetCore.Routing.RouteValueDictionary values, Microsoft.AspNetCore.Routing.RouteValueDictionary ambientValues = null, string scheme = null, Microsoft.AspNetCore.Http.HostString? host = default(Microsoft.AspNetCore.Http.HostString?), Microsoft.AspNetCore.Http.PathString? pathBase = default(Microsoft.AspNetCore.Http.PathString?), Microsoft.AspNetCore.Http.FragmentString fragment = default(Microsoft.AspNetCore.Http.FragmentString), Microsoft.AspNetCore.Routing.LinkOptions options = null); - public abstract string GetUriByAddress(TAddress address, Microsoft.AspNetCore.Routing.RouteValueDictionary values, string scheme, Microsoft.AspNetCore.Http.HostString host, Microsoft.AspNetCore.Http.PathString pathBase = default(Microsoft.AspNetCore.Http.PathString), Microsoft.AspNetCore.Http.FragmentString fragment = default(Microsoft.AspNetCore.Http.FragmentString), Microsoft.AspNetCore.Routing.LinkOptions options = null); + public abstract string GetPathByAddress(Microsoft.AspNetCore.Http.HttpContext httpContext, TAddress address, Microsoft.AspNetCore.Routing.RouteValueDictionary values, Microsoft.AspNetCore.Routing.RouteValueDictionary? ambientValues = null, Microsoft.AspNetCore.Http.PathString? pathBase = default(Microsoft.AspNetCore.Http.PathString?), Microsoft.AspNetCore.Http.FragmentString fragment = default(Microsoft.AspNetCore.Http.FragmentString), Microsoft.AspNetCore.Routing.LinkOptions? options = null); + public abstract string GetPathByAddress(TAddress address, Microsoft.AspNetCore.Routing.RouteValueDictionary values, Microsoft.AspNetCore.Http.PathString pathBase = default(Microsoft.AspNetCore.Http.PathString), Microsoft.AspNetCore.Http.FragmentString fragment = default(Microsoft.AspNetCore.Http.FragmentString), Microsoft.AspNetCore.Routing.LinkOptions? options = null); + public abstract string GetUriByAddress(Microsoft.AspNetCore.Http.HttpContext httpContext, TAddress address, Microsoft.AspNetCore.Routing.RouteValueDictionary values, Microsoft.AspNetCore.Routing.RouteValueDictionary? ambientValues = null, string? scheme = null, Microsoft.AspNetCore.Http.HostString? host = default(Microsoft.AspNetCore.Http.HostString?), Microsoft.AspNetCore.Http.PathString? pathBase = default(Microsoft.AspNetCore.Http.PathString?), Microsoft.AspNetCore.Http.FragmentString fragment = default(Microsoft.AspNetCore.Http.FragmentString), Microsoft.AspNetCore.Routing.LinkOptions? options = null); + public abstract string GetUriByAddress(TAddress address, Microsoft.AspNetCore.Routing.RouteValueDictionary values, string scheme, Microsoft.AspNetCore.Http.HostString host, Microsoft.AspNetCore.Http.PathString pathBase = default(Microsoft.AspNetCore.Http.PathString), Microsoft.AspNetCore.Http.FragmentString fragment = default(Microsoft.AspNetCore.Http.FragmentString), Microsoft.AspNetCore.Routing.LinkOptions? options = null); } public partial class LinkOptions { @@ -45,7 +45,7 @@ namespace Microsoft.AspNetCore.Routing public partial class RouteContext { public RouteContext(Microsoft.AspNetCore.Http.HttpContext httpContext) { } - public Microsoft.AspNetCore.Http.RequestDelegate Handler { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public Microsoft.AspNetCore.Http.RequestDelegate? Handler { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } public Microsoft.AspNetCore.Http.HttpContext HttpContext { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } public Microsoft.AspNetCore.Routing.RouteData RouteData { get { throw null; } set { } } } @@ -75,15 +75,15 @@ namespace Microsoft.AspNetCore.Routing public static partial class RoutingHttpContextExtensions { public static Microsoft.AspNetCore.Routing.RouteData GetRouteData(this Microsoft.AspNetCore.Http.HttpContext httpContext) { throw null; } - public static object GetRouteValue(this Microsoft.AspNetCore.Http.HttpContext httpContext, string key) { throw null; } + public static object? GetRouteValue(this Microsoft.AspNetCore.Http.HttpContext httpContext, string key) { throw null; } } public partial class VirtualPathContext { public VirtualPathContext(Microsoft.AspNetCore.Http.HttpContext httpContext, Microsoft.AspNetCore.Routing.RouteValueDictionary ambientValues, Microsoft.AspNetCore.Routing.RouteValueDictionary values) { } - public VirtualPathContext(Microsoft.AspNetCore.Http.HttpContext httpContext, Microsoft.AspNetCore.Routing.RouteValueDictionary ambientValues, Microsoft.AspNetCore.Routing.RouteValueDictionary values, string routeName) { } + public VirtualPathContext(Microsoft.AspNetCore.Http.HttpContext httpContext, Microsoft.AspNetCore.Routing.RouteValueDictionary ambientValues, Microsoft.AspNetCore.Routing.RouteValueDictionary values, string? routeName) { } public Microsoft.AspNetCore.Routing.RouteValueDictionary AmbientValues { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } public Microsoft.AspNetCore.Http.HttpContext HttpContext { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } - public string RouteName { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } + public string? RouteName { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } public Microsoft.AspNetCore.Routing.RouteValueDictionary Values { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } } public partial class VirtualPathData diff --git a/src/Http/Routing.Abstractions/src/LinkGenerator.cs b/src/Http/Routing.Abstractions/src/LinkGenerator.cs index add5eaf119..90a28ea966 100644 --- a/src/Http/Routing.Abstractions/src/LinkGenerator.cs +++ b/src/Http/Routing.Abstractions/src/LinkGenerator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// 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 Microsoft.AspNetCore.Http; @@ -45,10 +45,10 @@ namespace Microsoft.AspNetCore.Routing HttpContext httpContext, TAddress address, RouteValueDictionary values, - RouteValueDictionary ambientValues = default, + RouteValueDictionary? ambientValues = default, PathString? pathBase = default, FragmentString fragment = default, - LinkOptions options = default); + LinkOptions? options = default); /// /// Generates a URI with an absolute path based on the provided values. @@ -68,7 +68,7 @@ namespace Microsoft.AspNetCore.Routing RouteValueDictionary values, PathString pathBase = default, FragmentString fragment = default, - LinkOptions options = default); + LinkOptions? options = default); /// /// Generates an absolute URI based on the provided values and . @@ -106,12 +106,12 @@ namespace Microsoft.AspNetCore.Routing HttpContext httpContext, TAddress address, RouteValueDictionary values, - RouteValueDictionary ambientValues = default, - string scheme = default, + RouteValueDictionary? ambientValues = default, + string? scheme = default, HostString? host = default, PathString? pathBase = default, FragmentString fragment = default, - LinkOptions options = default); + LinkOptions? options = default); /// /// Generates an absolute URI based on the provided values. @@ -146,6 +146,6 @@ namespace Microsoft.AspNetCore.Routing HostString host, PathString pathBase = default, FragmentString fragment = default, - LinkOptions options = default); + LinkOptions? options = default); } } diff --git a/src/Http/Routing.Abstractions/src/Microsoft.AspNetCore.Routing.Abstractions.csproj b/src/Http/Routing.Abstractions/src/Microsoft.AspNetCore.Routing.Abstractions.csproj index c500cb5ba7..01a9d07382 100644 --- a/src/Http/Routing.Abstractions/src/Microsoft.AspNetCore.Routing.Abstractions.csproj +++ b/src/Http/Routing.Abstractions/src/Microsoft.AspNetCore.Routing.Abstractions.csproj @@ -1,4 +1,4 @@ - + ASP.NET Core abstractions for routing requests to application logic and for generating links. @@ -11,6 +11,7 @@ Microsoft.AspNetCore.Routing.RouteData true aspnetcore;routing false + annotations diff --git a/src/Http/Routing.Abstractions/src/RouteContext.cs b/src/Http/Routing.Abstractions/src/RouteContext.cs index 7162446e7d..21b8d7e0c2 100644 --- a/src/Http/Routing.Abstractions/src/RouteContext.cs +++ b/src/Http/Routing.Abstractions/src/RouteContext.cs @@ -19,7 +19,7 @@ namespace Microsoft.AspNetCore.Routing /// The associated with the current request. public RouteContext(HttpContext httpContext) { - HttpContext = httpContext; + HttpContext = httpContext ?? throw new ArgumentNullException(nameof(httpContext)); RouteData = new RouteData(); } @@ -28,7 +28,7 @@ namespace Microsoft.AspNetCore.Routing /// Gets or sets the handler for the request. An should set /// when it matches. /// - public RequestDelegate Handler { get; set; } + public RequestDelegate? Handler { get; set; } /// /// Gets the associated with the current request. diff --git a/src/Http/Routing.Abstractions/src/RoutingHttpContextExtensions.cs b/src/Http/Routing.Abstractions/src/RoutingHttpContextExtensions.cs index a13571bdb8..89fcf0ad2d 100644 --- a/src/Http/Routing.Abstractions/src/RoutingHttpContextExtensions.cs +++ b/src/Http/Routing.Abstractions/src/RoutingHttpContextExtensions.cs @@ -35,7 +35,7 @@ namespace Microsoft.AspNetCore.Routing /// The associated with the current request. /// The key of the route value. /// The corresponding route value, or null. - public static object GetRouteValue(this HttpContext httpContext, string key) + public static object? GetRouteValue(this HttpContext httpContext, string key) { if (httpContext == null) { diff --git a/src/Http/Routing.Abstractions/src/VirtualPathContext.cs b/src/Http/Routing.Abstractions/src/VirtualPathContext.cs index 88f899e925..a1483d1b9b 100644 --- a/src/Http/Routing.Abstractions/src/VirtualPathContext.cs +++ b/src/Http/Routing.Abstractions/src/VirtualPathContext.cs @@ -35,7 +35,7 @@ namespace Microsoft.AspNetCore.Routing HttpContext httpContext, RouteValueDictionary ambientValues, RouteValueDictionary values, - string routeName) + string? routeName) { HttpContext = httpContext; AmbientValues = ambientValues; @@ -56,7 +56,7 @@ namespace Microsoft.AspNetCore.Routing /// /// Gets the name of the route to use for virtual path generation. /// - public string RouteName { get; } + public string? RouteName { get; } /// /// Gets or sets the set of new values provided for virtual path generation. diff --git a/src/Http/Routing/ref/Microsoft.AspNetCore.Routing.csproj b/src/Http/Routing/ref/Microsoft.AspNetCore.Routing.csproj index 750e814c69..de1041504e 100644 --- a/src/Http/Routing/ref/Microsoft.AspNetCore.Routing.csproj +++ b/src/Http/Routing/ref/Microsoft.AspNetCore.Routing.csproj @@ -2,6 +2,7 @@ $(DefaultNetCoreTargetFramework) + annotations diff --git a/src/Http/Routing/src/Microsoft.AspNetCore.Routing.csproj b/src/Http/Routing/src/Microsoft.AspNetCore.Routing.csproj index 52fd97828a..7652fc21d2 100644 --- a/src/Http/Routing/src/Microsoft.AspNetCore.Routing.csproj +++ b/src/Http/Routing/src/Microsoft.AspNetCore.Routing.csproj @@ -12,6 +12,7 @@ Microsoft.AspNetCore.Routing.RouteCollection aspnetcore;routing true false + annotations diff --git a/src/Servers/Connections.Abstractions/ref/Microsoft.AspNetCore.Connections.Abstractions.csproj b/src/Servers/Connections.Abstractions/ref/Microsoft.AspNetCore.Connections.Abstractions.csproj index 262c012733..ef53667e23 100644 --- a/src/Servers/Connections.Abstractions/ref/Microsoft.AspNetCore.Connections.Abstractions.csproj +++ b/src/Servers/Connections.Abstractions/ref/Microsoft.AspNetCore.Connections.Abstractions.csproj @@ -3,6 +3,7 @@ netstandard2.0;netstandard2.1;$(DefaultNetCoreTargetFramework) $(DefaultNetCoreTargetFramework) + annotations diff --git a/src/Servers/Connections.Abstractions/ref/Microsoft.AspNetCore.Connections.Abstractions.netcoreapp.cs b/src/Servers/Connections.Abstractions/ref/Microsoft.AspNetCore.Connections.Abstractions.netcoreapp.cs index 75ed809b6d..5e5e0a6ec1 100644 --- a/src/Servers/Connections.Abstractions/ref/Microsoft.AspNetCore.Connections.Abstractions.netcoreapp.cs +++ b/src/Servers/Connections.Abstractions/ref/Microsoft.AspNetCore.Connections.Abstractions.netcoreapp.cs @@ -12,11 +12,11 @@ namespace Microsoft.AspNetCore.Connections { protected BaseConnectionContext() { } public virtual System.Threading.CancellationToken ConnectionClosed { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } - public abstract string ConnectionId { get; set; } + public abstract string? ConnectionId { get; set; } public abstract Microsoft.AspNetCore.Http.Features.IFeatureCollection Features { get; } - public abstract System.Collections.Generic.IDictionary Items { get; set; } - public virtual System.Net.EndPoint LocalEndPoint { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } - public virtual System.Net.EndPoint RemoteEndPoint { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public abstract System.Collections.Generic.IDictionary? Items { get; set; } + public virtual System.Net.EndPoint? LocalEndPoint { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public virtual System.Net.EndPoint? RemoteEndPoint { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } public abstract void Abort(); public abstract void Abort(Microsoft.AspNetCore.Connections.ConnectionAbortedException abortReason); public virtual System.Threading.Tasks.ValueTask DisposeAsync() { throw null; } @@ -43,7 +43,7 @@ namespace Microsoft.AspNetCore.Connections public abstract partial class ConnectionContext : Microsoft.AspNetCore.Connections.BaseConnectionContext, System.IAsyncDisposable { protected ConnectionContext() { } - public abstract System.IO.Pipelines.IDuplexPipe Transport { get; set; } + public abstract System.IO.Pipelines.IDuplexPipe? Transport { get; set; } public override void Abort() { } public override void Abort(Microsoft.AspNetCore.Connections.ConnectionAbortedException abortReason) { } } @@ -53,26 +53,26 @@ namespace Microsoft.AspNetCore.Connections protected ConnectionHandler() { } public abstract System.Threading.Tasks.Task OnConnectedAsync(Microsoft.AspNetCore.Connections.ConnectionContext connection); } - public partial class ConnectionItems : System.Collections.Generic.ICollection>, System.Collections.Generic.IDictionary, System.Collections.Generic.IEnumerable>, System.Collections.IEnumerable + public partial class ConnectionItems : System.Collections.Generic.ICollection>, System.Collections.Generic.IDictionary, System.Collections.Generic.IEnumerable>, System.Collections.IEnumerable { public ConnectionItems() { } - public ConnectionItems(System.Collections.Generic.IDictionary items) { } - public System.Collections.Generic.IDictionary Items { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } - int System.Collections.Generic.ICollection>.Count { get { throw null; } } - bool System.Collections.Generic.ICollection>.IsReadOnly { get { throw null; } } - object System.Collections.Generic.IDictionary.this[object key] { get { throw null; } set { } } - System.Collections.Generic.ICollection System.Collections.Generic.IDictionary.Keys { get { throw null; } } - System.Collections.Generic.ICollection System.Collections.Generic.IDictionary.Values { get { throw null; } } - void System.Collections.Generic.ICollection>.Add(System.Collections.Generic.KeyValuePair item) { } - void System.Collections.Generic.ICollection>.Clear() { } - bool System.Collections.Generic.ICollection>.Contains(System.Collections.Generic.KeyValuePair item) { throw null; } - void System.Collections.Generic.ICollection>.CopyTo(System.Collections.Generic.KeyValuePair[] array, int arrayIndex) { } - bool System.Collections.Generic.ICollection>.Remove(System.Collections.Generic.KeyValuePair item) { throw null; } - void System.Collections.Generic.IDictionary.Add(object key, object value) { } - bool System.Collections.Generic.IDictionary.ContainsKey(object key) { throw null; } - bool System.Collections.Generic.IDictionary.Remove(object key) { throw null; } - bool System.Collections.Generic.IDictionary.TryGetValue(object key, out object value) { throw null; } - System.Collections.Generic.IEnumerator> System.Collections.Generic.IEnumerable>.GetEnumerator() { throw null; } + public ConnectionItems(System.Collections.Generic.IDictionary items) { } + public System.Collections.Generic.IDictionary Items { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } + int System.Collections.Generic.ICollection>.Count { get { throw null; } } + bool System.Collections.Generic.ICollection>.IsReadOnly { get { throw null; } } + object? System.Collections.Generic.IDictionary.this[object key] { get { throw null; } set { } } + System.Collections.Generic.ICollection System.Collections.Generic.IDictionary.Keys { get { throw null; } } + System.Collections.Generic.ICollection System.Collections.Generic.IDictionary.Values { get { throw null; } } + void System.Collections.Generic.ICollection>.Add(System.Collections.Generic.KeyValuePair item) { } + void System.Collections.Generic.ICollection>.Clear() { } + bool System.Collections.Generic.ICollection>.Contains(System.Collections.Generic.KeyValuePair item) { throw null; } + void System.Collections.Generic.ICollection>.CopyTo(System.Collections.Generic.KeyValuePair[] array, int arrayIndex) { } + bool System.Collections.Generic.ICollection>.Remove(System.Collections.Generic.KeyValuePair item) { throw null; } + void System.Collections.Generic.IDictionary.Add(object key, object? value) { } + bool System.Collections.Generic.IDictionary.ContainsKey(object key) { throw null; } + bool System.Collections.Generic.IDictionary.Remove(object key) { throw null; } + bool System.Collections.Generic.IDictionary.TryGetValue(object key, out object? value) { throw null; } + System.Collections.Generic.IEnumerator> System.Collections.Generic.IEnumerable>.GetEnumerator() { throw null; } System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { throw null; } } public partial class ConnectionResetException : System.IO.IOException @@ -85,15 +85,15 @@ namespace Microsoft.AspNetCore.Connections public DefaultConnectionContext() { } public DefaultConnectionContext(string id) { } public DefaultConnectionContext(string id, System.IO.Pipelines.IDuplexPipe transport, System.IO.Pipelines.IDuplexPipe application) { } - public System.IO.Pipelines.IDuplexPipe Application { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public System.IO.Pipelines.IDuplexPipe? Application { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } public override System.Threading.CancellationToken ConnectionClosed { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } - public override string ConnectionId { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public override string? ConnectionId { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } public override Microsoft.AspNetCore.Http.Features.IFeatureCollection Features { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } - public override System.Collections.Generic.IDictionary Items { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } - public override System.Net.EndPoint LocalEndPoint { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } - public override System.Net.EndPoint RemoteEndPoint { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } - public override System.IO.Pipelines.IDuplexPipe Transport { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } - public System.Security.Claims.ClaimsPrincipal User { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public override System.Collections.Generic.IDictionary? Items { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public override System.Net.EndPoint? LocalEndPoint { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public override System.Net.EndPoint? RemoteEndPoint { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public override System.IO.Pipelines.IDuplexPipe? Transport { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public System.Security.Claims.ClaimsPrincipal? User { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } public override void Abort(Microsoft.AspNetCore.Connections.ConnectionAbortedException abortReason) { } public override System.Threading.Tasks.ValueTask DisposeAsync() { throw null; } } @@ -137,17 +137,17 @@ namespace Microsoft.AspNetCore.Connections } public partial interface IMultiplexedConnectionFactory { - System.Threading.Tasks.ValueTask ConnectAsync(System.Net.EndPoint endpoint, Microsoft.AspNetCore.Http.Features.IFeatureCollection features = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.ValueTask ConnectAsync(System.Net.EndPoint endpoint, Microsoft.AspNetCore.Http.Features.IFeatureCollection? features = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); } public partial interface IMultiplexedConnectionListener : System.IAsyncDisposable { System.Net.EndPoint EndPoint { get; } - System.Threading.Tasks.ValueTask AcceptAsync(Microsoft.AspNetCore.Http.Features.IFeatureCollection features = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.ValueTask AcceptAsync(Microsoft.AspNetCore.Http.Features.IFeatureCollection? features = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); System.Threading.Tasks.ValueTask UnbindAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); } public partial interface IMultiplexedConnectionListenerFactory { - System.Threading.Tasks.ValueTask BindAsync(System.Net.EndPoint endpoint, Microsoft.AspNetCore.Http.Features.IFeatureCollection features = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.ValueTask BindAsync(System.Net.EndPoint endpoint, Microsoft.AspNetCore.Http.Features.IFeatureCollection? features = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); } public partial class MultiplexedConnectionBuilder : Microsoft.AspNetCore.Connections.IMultiplexedConnectionBuilder { @@ -160,7 +160,7 @@ namespace Microsoft.AspNetCore.Connections { protected MultiplexedConnectionContext() { } public abstract System.Threading.Tasks.ValueTask AcceptAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); - public abstract System.Threading.Tasks.ValueTask ConnectAsync(Microsoft.AspNetCore.Http.Features.IFeatureCollection features = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + public abstract System.Threading.Tasks.ValueTask ConnectAsync(Microsoft.AspNetCore.Http.Features.IFeatureCollection? features = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); } public delegate System.Threading.Tasks.Task MultiplexedConnectionDelegate(Microsoft.AspNetCore.Connections.MultiplexedConnectionContext connection); [System.FlagsAttribute] @@ -184,8 +184,8 @@ namespace Microsoft.AspNetCore.Connections.Features } public partial interface IConnectionEndPointFeature { - System.Net.EndPoint LocalEndPoint { get; set; } - System.Net.EndPoint RemoteEndPoint { get; set; } + System.Net.EndPoint? LocalEndPoint { get; set; } + System.Net.EndPoint? RemoteEndPoint { get; set; } } public partial interface IConnectionHeartbeatFeature { @@ -193,7 +193,7 @@ namespace Microsoft.AspNetCore.Connections.Features } public partial interface IConnectionIdFeature { - string ConnectionId { get; set; } + string? ConnectionId { get; set; } } public partial interface IConnectionInherentKeepAliveFeature { @@ -201,7 +201,7 @@ namespace Microsoft.AspNetCore.Connections.Features } public partial interface IConnectionItemsFeature { - System.Collections.Generic.IDictionary Items { get; set; } + System.Collections.Generic.IDictionary? Items { get; set; } } public partial interface IConnectionLifetimeFeature { @@ -215,11 +215,11 @@ namespace Microsoft.AspNetCore.Connections.Features } public partial interface IConnectionTransportFeature { - System.IO.Pipelines.IDuplexPipe Transport { get; set; } + System.IO.Pipelines.IDuplexPipe? Transport { get; set; } } public partial interface IConnectionUserFeature { - System.Security.Claims.ClaimsPrincipal User { get; set; } + System.Security.Claims.ClaimsPrincipal? User { get; set; } } public partial interface IMemoryPoolFeature { diff --git a/src/Servers/Connections.Abstractions/ref/Microsoft.AspNetCore.Connections.Abstractions.netstandard2.0.cs b/src/Servers/Connections.Abstractions/ref/Microsoft.AspNetCore.Connections.Abstractions.netstandard2.0.cs index 75ed809b6d..5e5e0a6ec1 100644 --- a/src/Servers/Connections.Abstractions/ref/Microsoft.AspNetCore.Connections.Abstractions.netstandard2.0.cs +++ b/src/Servers/Connections.Abstractions/ref/Microsoft.AspNetCore.Connections.Abstractions.netstandard2.0.cs @@ -12,11 +12,11 @@ namespace Microsoft.AspNetCore.Connections { protected BaseConnectionContext() { } public virtual System.Threading.CancellationToken ConnectionClosed { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } - public abstract string ConnectionId { get; set; } + public abstract string? ConnectionId { get; set; } public abstract Microsoft.AspNetCore.Http.Features.IFeatureCollection Features { get; } - public abstract System.Collections.Generic.IDictionary Items { get; set; } - public virtual System.Net.EndPoint LocalEndPoint { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } - public virtual System.Net.EndPoint RemoteEndPoint { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public abstract System.Collections.Generic.IDictionary? Items { get; set; } + public virtual System.Net.EndPoint? LocalEndPoint { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public virtual System.Net.EndPoint? RemoteEndPoint { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } public abstract void Abort(); public abstract void Abort(Microsoft.AspNetCore.Connections.ConnectionAbortedException abortReason); public virtual System.Threading.Tasks.ValueTask DisposeAsync() { throw null; } @@ -43,7 +43,7 @@ namespace Microsoft.AspNetCore.Connections public abstract partial class ConnectionContext : Microsoft.AspNetCore.Connections.BaseConnectionContext, System.IAsyncDisposable { protected ConnectionContext() { } - public abstract System.IO.Pipelines.IDuplexPipe Transport { get; set; } + public abstract System.IO.Pipelines.IDuplexPipe? Transport { get; set; } public override void Abort() { } public override void Abort(Microsoft.AspNetCore.Connections.ConnectionAbortedException abortReason) { } } @@ -53,26 +53,26 @@ namespace Microsoft.AspNetCore.Connections protected ConnectionHandler() { } public abstract System.Threading.Tasks.Task OnConnectedAsync(Microsoft.AspNetCore.Connections.ConnectionContext connection); } - public partial class ConnectionItems : System.Collections.Generic.ICollection>, System.Collections.Generic.IDictionary, System.Collections.Generic.IEnumerable>, System.Collections.IEnumerable + public partial class ConnectionItems : System.Collections.Generic.ICollection>, System.Collections.Generic.IDictionary, System.Collections.Generic.IEnumerable>, System.Collections.IEnumerable { public ConnectionItems() { } - public ConnectionItems(System.Collections.Generic.IDictionary items) { } - public System.Collections.Generic.IDictionary Items { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } - int System.Collections.Generic.ICollection>.Count { get { throw null; } } - bool System.Collections.Generic.ICollection>.IsReadOnly { get { throw null; } } - object System.Collections.Generic.IDictionary.this[object key] { get { throw null; } set { } } - System.Collections.Generic.ICollection System.Collections.Generic.IDictionary.Keys { get { throw null; } } - System.Collections.Generic.ICollection System.Collections.Generic.IDictionary.Values { get { throw null; } } - void System.Collections.Generic.ICollection>.Add(System.Collections.Generic.KeyValuePair item) { } - void System.Collections.Generic.ICollection>.Clear() { } - bool System.Collections.Generic.ICollection>.Contains(System.Collections.Generic.KeyValuePair item) { throw null; } - void System.Collections.Generic.ICollection>.CopyTo(System.Collections.Generic.KeyValuePair[] array, int arrayIndex) { } - bool System.Collections.Generic.ICollection>.Remove(System.Collections.Generic.KeyValuePair item) { throw null; } - void System.Collections.Generic.IDictionary.Add(object key, object value) { } - bool System.Collections.Generic.IDictionary.ContainsKey(object key) { throw null; } - bool System.Collections.Generic.IDictionary.Remove(object key) { throw null; } - bool System.Collections.Generic.IDictionary.TryGetValue(object key, out object value) { throw null; } - System.Collections.Generic.IEnumerator> System.Collections.Generic.IEnumerable>.GetEnumerator() { throw null; } + public ConnectionItems(System.Collections.Generic.IDictionary items) { } + public System.Collections.Generic.IDictionary Items { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } + int System.Collections.Generic.ICollection>.Count { get { throw null; } } + bool System.Collections.Generic.ICollection>.IsReadOnly { get { throw null; } } + object? System.Collections.Generic.IDictionary.this[object key] { get { throw null; } set { } } + System.Collections.Generic.ICollection System.Collections.Generic.IDictionary.Keys { get { throw null; } } + System.Collections.Generic.ICollection System.Collections.Generic.IDictionary.Values { get { throw null; } } + void System.Collections.Generic.ICollection>.Add(System.Collections.Generic.KeyValuePair item) { } + void System.Collections.Generic.ICollection>.Clear() { } + bool System.Collections.Generic.ICollection>.Contains(System.Collections.Generic.KeyValuePair item) { throw null; } + void System.Collections.Generic.ICollection>.CopyTo(System.Collections.Generic.KeyValuePair[] array, int arrayIndex) { } + bool System.Collections.Generic.ICollection>.Remove(System.Collections.Generic.KeyValuePair item) { throw null; } + void System.Collections.Generic.IDictionary.Add(object key, object? value) { } + bool System.Collections.Generic.IDictionary.ContainsKey(object key) { throw null; } + bool System.Collections.Generic.IDictionary.Remove(object key) { throw null; } + bool System.Collections.Generic.IDictionary.TryGetValue(object key, out object? value) { throw null; } + System.Collections.Generic.IEnumerator> System.Collections.Generic.IEnumerable>.GetEnumerator() { throw null; } System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { throw null; } } public partial class ConnectionResetException : System.IO.IOException @@ -85,15 +85,15 @@ namespace Microsoft.AspNetCore.Connections public DefaultConnectionContext() { } public DefaultConnectionContext(string id) { } public DefaultConnectionContext(string id, System.IO.Pipelines.IDuplexPipe transport, System.IO.Pipelines.IDuplexPipe application) { } - public System.IO.Pipelines.IDuplexPipe Application { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public System.IO.Pipelines.IDuplexPipe? Application { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } public override System.Threading.CancellationToken ConnectionClosed { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } - public override string ConnectionId { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public override string? ConnectionId { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } public override Microsoft.AspNetCore.Http.Features.IFeatureCollection Features { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } - public override System.Collections.Generic.IDictionary Items { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } - public override System.Net.EndPoint LocalEndPoint { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } - public override System.Net.EndPoint RemoteEndPoint { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } - public override System.IO.Pipelines.IDuplexPipe Transport { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } - public System.Security.Claims.ClaimsPrincipal User { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public override System.Collections.Generic.IDictionary? Items { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public override System.Net.EndPoint? LocalEndPoint { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public override System.Net.EndPoint? RemoteEndPoint { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public override System.IO.Pipelines.IDuplexPipe? Transport { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public System.Security.Claims.ClaimsPrincipal? User { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } public override void Abort(Microsoft.AspNetCore.Connections.ConnectionAbortedException abortReason) { } public override System.Threading.Tasks.ValueTask DisposeAsync() { throw null; } } @@ -137,17 +137,17 @@ namespace Microsoft.AspNetCore.Connections } public partial interface IMultiplexedConnectionFactory { - System.Threading.Tasks.ValueTask ConnectAsync(System.Net.EndPoint endpoint, Microsoft.AspNetCore.Http.Features.IFeatureCollection features = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.ValueTask ConnectAsync(System.Net.EndPoint endpoint, Microsoft.AspNetCore.Http.Features.IFeatureCollection? features = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); } public partial interface IMultiplexedConnectionListener : System.IAsyncDisposable { System.Net.EndPoint EndPoint { get; } - System.Threading.Tasks.ValueTask AcceptAsync(Microsoft.AspNetCore.Http.Features.IFeatureCollection features = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.ValueTask AcceptAsync(Microsoft.AspNetCore.Http.Features.IFeatureCollection? features = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); System.Threading.Tasks.ValueTask UnbindAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); } public partial interface IMultiplexedConnectionListenerFactory { - System.Threading.Tasks.ValueTask BindAsync(System.Net.EndPoint endpoint, Microsoft.AspNetCore.Http.Features.IFeatureCollection features = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.ValueTask BindAsync(System.Net.EndPoint endpoint, Microsoft.AspNetCore.Http.Features.IFeatureCollection? features = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); } public partial class MultiplexedConnectionBuilder : Microsoft.AspNetCore.Connections.IMultiplexedConnectionBuilder { @@ -160,7 +160,7 @@ namespace Microsoft.AspNetCore.Connections { protected MultiplexedConnectionContext() { } public abstract System.Threading.Tasks.ValueTask AcceptAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); - public abstract System.Threading.Tasks.ValueTask ConnectAsync(Microsoft.AspNetCore.Http.Features.IFeatureCollection features = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + public abstract System.Threading.Tasks.ValueTask ConnectAsync(Microsoft.AspNetCore.Http.Features.IFeatureCollection? features = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); } public delegate System.Threading.Tasks.Task MultiplexedConnectionDelegate(Microsoft.AspNetCore.Connections.MultiplexedConnectionContext connection); [System.FlagsAttribute] @@ -184,8 +184,8 @@ namespace Microsoft.AspNetCore.Connections.Features } public partial interface IConnectionEndPointFeature { - System.Net.EndPoint LocalEndPoint { get; set; } - System.Net.EndPoint RemoteEndPoint { get; set; } + System.Net.EndPoint? LocalEndPoint { get; set; } + System.Net.EndPoint? RemoteEndPoint { get; set; } } public partial interface IConnectionHeartbeatFeature { @@ -193,7 +193,7 @@ namespace Microsoft.AspNetCore.Connections.Features } public partial interface IConnectionIdFeature { - string ConnectionId { get; set; } + string? ConnectionId { get; set; } } public partial interface IConnectionInherentKeepAliveFeature { @@ -201,7 +201,7 @@ namespace Microsoft.AspNetCore.Connections.Features } public partial interface IConnectionItemsFeature { - System.Collections.Generic.IDictionary Items { get; set; } + System.Collections.Generic.IDictionary? Items { get; set; } } public partial interface IConnectionLifetimeFeature { @@ -215,11 +215,11 @@ namespace Microsoft.AspNetCore.Connections.Features } public partial interface IConnectionTransportFeature { - System.IO.Pipelines.IDuplexPipe Transport { get; set; } + System.IO.Pipelines.IDuplexPipe? Transport { get; set; } } public partial interface IConnectionUserFeature { - System.Security.Claims.ClaimsPrincipal User { get; set; } + System.Security.Claims.ClaimsPrincipal? User { get; set; } } public partial interface IMemoryPoolFeature { diff --git a/src/Servers/Connections.Abstractions/ref/Microsoft.AspNetCore.Connections.Abstractions.netstandard2.1.cs b/src/Servers/Connections.Abstractions/ref/Microsoft.AspNetCore.Connections.Abstractions.netstandard2.1.cs index 75ed809b6d..5e5e0a6ec1 100644 --- a/src/Servers/Connections.Abstractions/ref/Microsoft.AspNetCore.Connections.Abstractions.netstandard2.1.cs +++ b/src/Servers/Connections.Abstractions/ref/Microsoft.AspNetCore.Connections.Abstractions.netstandard2.1.cs @@ -12,11 +12,11 @@ namespace Microsoft.AspNetCore.Connections { protected BaseConnectionContext() { } public virtual System.Threading.CancellationToken ConnectionClosed { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } - public abstract string ConnectionId { get; set; } + public abstract string? ConnectionId { get; set; } public abstract Microsoft.AspNetCore.Http.Features.IFeatureCollection Features { get; } - public abstract System.Collections.Generic.IDictionary Items { get; set; } - public virtual System.Net.EndPoint LocalEndPoint { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } - public virtual System.Net.EndPoint RemoteEndPoint { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public abstract System.Collections.Generic.IDictionary? Items { get; set; } + public virtual System.Net.EndPoint? LocalEndPoint { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public virtual System.Net.EndPoint? RemoteEndPoint { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } public abstract void Abort(); public abstract void Abort(Microsoft.AspNetCore.Connections.ConnectionAbortedException abortReason); public virtual System.Threading.Tasks.ValueTask DisposeAsync() { throw null; } @@ -43,7 +43,7 @@ namespace Microsoft.AspNetCore.Connections public abstract partial class ConnectionContext : Microsoft.AspNetCore.Connections.BaseConnectionContext, System.IAsyncDisposable { protected ConnectionContext() { } - public abstract System.IO.Pipelines.IDuplexPipe Transport { get; set; } + public abstract System.IO.Pipelines.IDuplexPipe? Transport { get; set; } public override void Abort() { } public override void Abort(Microsoft.AspNetCore.Connections.ConnectionAbortedException abortReason) { } } @@ -53,26 +53,26 @@ namespace Microsoft.AspNetCore.Connections protected ConnectionHandler() { } public abstract System.Threading.Tasks.Task OnConnectedAsync(Microsoft.AspNetCore.Connections.ConnectionContext connection); } - public partial class ConnectionItems : System.Collections.Generic.ICollection>, System.Collections.Generic.IDictionary, System.Collections.Generic.IEnumerable>, System.Collections.IEnumerable + public partial class ConnectionItems : System.Collections.Generic.ICollection>, System.Collections.Generic.IDictionary, System.Collections.Generic.IEnumerable>, System.Collections.IEnumerable { public ConnectionItems() { } - public ConnectionItems(System.Collections.Generic.IDictionary items) { } - public System.Collections.Generic.IDictionary Items { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } - int System.Collections.Generic.ICollection>.Count { get { throw null; } } - bool System.Collections.Generic.ICollection>.IsReadOnly { get { throw null; } } - object System.Collections.Generic.IDictionary.this[object key] { get { throw null; } set { } } - System.Collections.Generic.ICollection System.Collections.Generic.IDictionary.Keys { get { throw null; } } - System.Collections.Generic.ICollection System.Collections.Generic.IDictionary.Values { get { throw null; } } - void System.Collections.Generic.ICollection>.Add(System.Collections.Generic.KeyValuePair item) { } - void System.Collections.Generic.ICollection>.Clear() { } - bool System.Collections.Generic.ICollection>.Contains(System.Collections.Generic.KeyValuePair item) { throw null; } - void System.Collections.Generic.ICollection>.CopyTo(System.Collections.Generic.KeyValuePair[] array, int arrayIndex) { } - bool System.Collections.Generic.ICollection>.Remove(System.Collections.Generic.KeyValuePair item) { throw null; } - void System.Collections.Generic.IDictionary.Add(object key, object value) { } - bool System.Collections.Generic.IDictionary.ContainsKey(object key) { throw null; } - bool System.Collections.Generic.IDictionary.Remove(object key) { throw null; } - bool System.Collections.Generic.IDictionary.TryGetValue(object key, out object value) { throw null; } - System.Collections.Generic.IEnumerator> System.Collections.Generic.IEnumerable>.GetEnumerator() { throw null; } + public ConnectionItems(System.Collections.Generic.IDictionary items) { } + public System.Collections.Generic.IDictionary Items { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } + int System.Collections.Generic.ICollection>.Count { get { throw null; } } + bool System.Collections.Generic.ICollection>.IsReadOnly { get { throw null; } } + object? System.Collections.Generic.IDictionary.this[object key] { get { throw null; } set { } } + System.Collections.Generic.ICollection System.Collections.Generic.IDictionary.Keys { get { throw null; } } + System.Collections.Generic.ICollection System.Collections.Generic.IDictionary.Values { get { throw null; } } + void System.Collections.Generic.ICollection>.Add(System.Collections.Generic.KeyValuePair item) { } + void System.Collections.Generic.ICollection>.Clear() { } + bool System.Collections.Generic.ICollection>.Contains(System.Collections.Generic.KeyValuePair item) { throw null; } + void System.Collections.Generic.ICollection>.CopyTo(System.Collections.Generic.KeyValuePair[] array, int arrayIndex) { } + bool System.Collections.Generic.ICollection>.Remove(System.Collections.Generic.KeyValuePair item) { throw null; } + void System.Collections.Generic.IDictionary.Add(object key, object? value) { } + bool System.Collections.Generic.IDictionary.ContainsKey(object key) { throw null; } + bool System.Collections.Generic.IDictionary.Remove(object key) { throw null; } + bool System.Collections.Generic.IDictionary.TryGetValue(object key, out object? value) { throw null; } + System.Collections.Generic.IEnumerator> System.Collections.Generic.IEnumerable>.GetEnumerator() { throw null; } System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { throw null; } } public partial class ConnectionResetException : System.IO.IOException @@ -85,15 +85,15 @@ namespace Microsoft.AspNetCore.Connections public DefaultConnectionContext() { } public DefaultConnectionContext(string id) { } public DefaultConnectionContext(string id, System.IO.Pipelines.IDuplexPipe transport, System.IO.Pipelines.IDuplexPipe application) { } - public System.IO.Pipelines.IDuplexPipe Application { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public System.IO.Pipelines.IDuplexPipe? Application { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } public override System.Threading.CancellationToken ConnectionClosed { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } - public override string ConnectionId { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public override string? ConnectionId { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } public override Microsoft.AspNetCore.Http.Features.IFeatureCollection Features { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } - public override System.Collections.Generic.IDictionary Items { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } - public override System.Net.EndPoint LocalEndPoint { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } - public override System.Net.EndPoint RemoteEndPoint { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } - public override System.IO.Pipelines.IDuplexPipe Transport { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } - public System.Security.Claims.ClaimsPrincipal User { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public override System.Collections.Generic.IDictionary? Items { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public override System.Net.EndPoint? LocalEndPoint { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public override System.Net.EndPoint? RemoteEndPoint { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public override System.IO.Pipelines.IDuplexPipe? Transport { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public System.Security.Claims.ClaimsPrincipal? User { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } public override void Abort(Microsoft.AspNetCore.Connections.ConnectionAbortedException abortReason) { } public override System.Threading.Tasks.ValueTask DisposeAsync() { throw null; } } @@ -137,17 +137,17 @@ namespace Microsoft.AspNetCore.Connections } public partial interface IMultiplexedConnectionFactory { - System.Threading.Tasks.ValueTask ConnectAsync(System.Net.EndPoint endpoint, Microsoft.AspNetCore.Http.Features.IFeatureCollection features = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.ValueTask ConnectAsync(System.Net.EndPoint endpoint, Microsoft.AspNetCore.Http.Features.IFeatureCollection? features = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); } public partial interface IMultiplexedConnectionListener : System.IAsyncDisposable { System.Net.EndPoint EndPoint { get; } - System.Threading.Tasks.ValueTask AcceptAsync(Microsoft.AspNetCore.Http.Features.IFeatureCollection features = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.ValueTask AcceptAsync(Microsoft.AspNetCore.Http.Features.IFeatureCollection? features = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); System.Threading.Tasks.ValueTask UnbindAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); } public partial interface IMultiplexedConnectionListenerFactory { - System.Threading.Tasks.ValueTask BindAsync(System.Net.EndPoint endpoint, Microsoft.AspNetCore.Http.Features.IFeatureCollection features = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.ValueTask BindAsync(System.Net.EndPoint endpoint, Microsoft.AspNetCore.Http.Features.IFeatureCollection? features = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); } public partial class MultiplexedConnectionBuilder : Microsoft.AspNetCore.Connections.IMultiplexedConnectionBuilder { @@ -160,7 +160,7 @@ namespace Microsoft.AspNetCore.Connections { protected MultiplexedConnectionContext() { } public abstract System.Threading.Tasks.ValueTask AcceptAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); - public abstract System.Threading.Tasks.ValueTask ConnectAsync(Microsoft.AspNetCore.Http.Features.IFeatureCollection features = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + public abstract System.Threading.Tasks.ValueTask ConnectAsync(Microsoft.AspNetCore.Http.Features.IFeatureCollection? features = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); } public delegate System.Threading.Tasks.Task MultiplexedConnectionDelegate(Microsoft.AspNetCore.Connections.MultiplexedConnectionContext connection); [System.FlagsAttribute] @@ -184,8 +184,8 @@ namespace Microsoft.AspNetCore.Connections.Features } public partial interface IConnectionEndPointFeature { - System.Net.EndPoint LocalEndPoint { get; set; } - System.Net.EndPoint RemoteEndPoint { get; set; } + System.Net.EndPoint? LocalEndPoint { get; set; } + System.Net.EndPoint? RemoteEndPoint { get; set; } } public partial interface IConnectionHeartbeatFeature { @@ -193,7 +193,7 @@ namespace Microsoft.AspNetCore.Connections.Features } public partial interface IConnectionIdFeature { - string ConnectionId { get; set; } + string? ConnectionId { get; set; } } public partial interface IConnectionInherentKeepAliveFeature { @@ -201,7 +201,7 @@ namespace Microsoft.AspNetCore.Connections.Features } public partial interface IConnectionItemsFeature { - System.Collections.Generic.IDictionary Items { get; set; } + System.Collections.Generic.IDictionary? Items { get; set; } } public partial interface IConnectionLifetimeFeature { @@ -215,11 +215,11 @@ namespace Microsoft.AspNetCore.Connections.Features } public partial interface IConnectionTransportFeature { - System.IO.Pipelines.IDuplexPipe Transport { get; set; } + System.IO.Pipelines.IDuplexPipe? Transport { get; set; } } public partial interface IConnectionUserFeature { - System.Security.Claims.ClaimsPrincipal User { get; set; } + System.Security.Claims.ClaimsPrincipal? User { get; set; } } public partial interface IMemoryPoolFeature { diff --git a/src/Servers/Connections.Abstractions/src/BaseConnectionContext.cs b/src/Servers/Connections.Abstractions/src/BaseConnectionContext.cs index 662b8c902e..dcaf110cde 100644 --- a/src/Servers/Connections.Abstractions/src/BaseConnectionContext.cs +++ b/src/Servers/Connections.Abstractions/src/BaseConnectionContext.cs @@ -15,7 +15,7 @@ namespace Microsoft.AspNetCore.Connections /// /// Gets or sets a unique identifier to represent this connection in trace logs. /// - public abstract string ConnectionId { get; set; } + public abstract string? ConnectionId { get; set; } /// /// Gets the collection of features provided by the server and middleware available on this connection. @@ -25,7 +25,7 @@ namespace Microsoft.AspNetCore.Connections /// /// Gets or sets a key/value collection that can be used to share data within the scope of this connection. /// - public abstract IDictionary Items { get; set; } + public abstract IDictionary? Items { get; set; } /// /// Triggered when the client connection is closed. @@ -35,12 +35,12 @@ namespace Microsoft.AspNetCore.Connections /// /// Gets or sets the local endpoint for this connection. /// - public virtual EndPoint LocalEndPoint { get; set; } + public virtual EndPoint? LocalEndPoint { get; set; } /// /// Gets or sets the remote endpoint for this connection. /// - public virtual EndPoint RemoteEndPoint { get; set; } + public virtual EndPoint? RemoteEndPoint { get; set; } /// /// Aborts the underlying connection. diff --git a/src/Servers/Connections.Abstractions/src/ConnectionContext.cs b/src/Servers/Connections.Abstractions/src/ConnectionContext.cs index 02b291c2c8..ffd4136ef8 100644 --- a/src/Servers/Connections.Abstractions/src/ConnectionContext.cs +++ b/src/Servers/Connections.Abstractions/src/ConnectionContext.cs @@ -15,7 +15,7 @@ namespace Microsoft.AspNetCore.Connections /// /// Gets or sets the that can be used to read or write data on this connection. /// - public abstract IDuplexPipe Transport { get; set; } + public abstract IDuplexPipe? Transport { get; set; } /// /// Aborts the underlying connection. diff --git a/src/Servers/Connections.Abstractions/src/ConnectionItems.cs b/src/Servers/Connections.Abstractions/src/ConnectionItems.cs index f5c7dd0352..5d9ef2cdb8 100644 --- a/src/Servers/Connections.Abstractions/src/ConnectionItems.cs +++ b/src/Servers/Connections.Abstractions/src/ConnectionItems.cs @@ -6,22 +6,22 @@ using System.Collections.Generic; namespace Microsoft.AspNetCore.Connections { - public class ConnectionItems : IDictionary + public class ConnectionItems : IDictionary { public ConnectionItems() - : this(new Dictionary()) + : this(new Dictionary()) { } - public ConnectionItems(IDictionary items) + public ConnectionItems(IDictionary items) { Items = items; } - public IDictionary Items { get; } + public IDictionary Items { get; } // Replace the indexer with one that returns null for missing values - object IDictionary.this[object key] + object? IDictionary.this[object key] { get { @@ -34,67 +34,67 @@ namespace Microsoft.AspNetCore.Connections set { Items[key] = value; } } - void IDictionary.Add(object key, object value) + void IDictionary.Add(object key, object? value) { Items.Add(key, value); } - bool IDictionary.ContainsKey(object key) + bool IDictionary.ContainsKey(object key) { return Items.ContainsKey(key); } - ICollection IDictionary.Keys + ICollection IDictionary.Keys { get { return Items.Keys; } } - bool IDictionary.Remove(object key) + bool IDictionary.Remove(object key) { return Items.Remove(key); } - bool IDictionary.TryGetValue(object key, out object value) + bool IDictionary.TryGetValue(object key, out object? value) { return Items.TryGetValue(key, out value); } - ICollection IDictionary.Values + ICollection IDictionary.Values { get { return Items.Values; } } - void ICollection>.Add(KeyValuePair item) + void ICollection>.Add(KeyValuePair item) { Items.Add(item); } - void ICollection>.Clear() + void ICollection>.Clear() { Items.Clear(); } - bool ICollection>.Contains(KeyValuePair item) + bool ICollection>.Contains(KeyValuePair item) { return Items.Contains(item); } - void ICollection>.CopyTo(KeyValuePair[] array, int arrayIndex) + void ICollection>.CopyTo(KeyValuePair[] array, int arrayIndex) { Items.CopyTo(array, arrayIndex); } - int ICollection>.Count + int ICollection>.Count { get { return Items.Count; } } - bool ICollection>.IsReadOnly + bool ICollection>.IsReadOnly { get { return Items.IsReadOnly; } } - bool ICollection>.Remove(KeyValuePair item) + bool ICollection>.Remove(KeyValuePair item) { if (Items.TryGetValue(item.Key, out var value) && Equals(item.Value, value)) { @@ -103,7 +103,7 @@ namespace Microsoft.AspNetCore.Connections return false; } - IEnumerator> IEnumerable>.GetEnumerator() + IEnumerator> IEnumerable>.GetEnumerator() { return Items.GetEnumerator(); } diff --git a/src/Servers/Connections.Abstractions/src/DefaultConnectionContext.cs b/src/Servers/Connections.Abstractions/src/DefaultConnectionContext.cs index 870fc4548f..ce3d115e2a 100644 --- a/src/Servers/Connections.Abstractions/src/DefaultConnectionContext.cs +++ b/src/Servers/Connections.Abstractions/src/DefaultConnectionContext.cs @@ -54,25 +54,25 @@ namespace Microsoft.AspNetCore.Connections Application = application; } - public override string ConnectionId { get; set; } + public override string? ConnectionId { get; set; } public override IFeatureCollection Features { get; } - public ClaimsPrincipal User { get; set; } + public ClaimsPrincipal? User { get; set; } - public override IDictionary Items { get; set; } = new ConnectionItems(); + public override IDictionary? Items { get; set; } = new ConnectionItems(); - public IDuplexPipe Application { get; set; } + public IDuplexPipe? Application { get; set; } - public override IDuplexPipe Transport { get; set; } + public override IDuplexPipe? Transport { get; set; } public override CancellationToken ConnectionClosed { get; set; } - public override EndPoint LocalEndPoint { get; set; } - public override EndPoint RemoteEndPoint { get; set; } + public override EndPoint? LocalEndPoint { get; set; } + public override EndPoint? RemoteEndPoint { get; set; } public override void Abort(ConnectionAbortedException abortReason) { - ThreadPool.UnsafeQueueUserWorkItem(cts => ((CancellationTokenSource)cts).Cancel(), _connectionClosedTokenSource); + ThreadPool.UnsafeQueueUserWorkItem(cts => ((CancellationTokenSource)cts!).Cancel(), _connectionClosedTokenSource); } public override ValueTask DisposeAsync() diff --git a/src/Servers/Connections.Abstractions/src/Features/IConnectionEndpointFeature.cs b/src/Servers/Connections.Abstractions/src/Features/IConnectionEndpointFeature.cs index 7c44146ede..6b51aa3a39 100644 --- a/src/Servers/Connections.Abstractions/src/Features/IConnectionEndpointFeature.cs +++ b/src/Servers/Connections.Abstractions/src/Features/IConnectionEndpointFeature.cs @@ -7,7 +7,7 @@ namespace Microsoft.AspNetCore.Connections.Features { public interface IConnectionEndPointFeature { - EndPoint LocalEndPoint { get; set; } - EndPoint RemoteEndPoint { get; set; } + EndPoint? LocalEndPoint { get; set; } + EndPoint? RemoteEndPoint { get; set; } } } diff --git a/src/Servers/Connections.Abstractions/src/Features/IConnectionIdFeature.cs b/src/Servers/Connections.Abstractions/src/Features/IConnectionIdFeature.cs index 2fa7ebbadf..8068e0cd6c 100644 --- a/src/Servers/Connections.Abstractions/src/Features/IConnectionIdFeature.cs +++ b/src/Servers/Connections.Abstractions/src/Features/IConnectionIdFeature.cs @@ -1,10 +1,10 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// 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. namespace Microsoft.AspNetCore.Connections.Features { public interface IConnectionIdFeature { - string ConnectionId { get; set; } + string? ConnectionId { get; set; } } } diff --git a/src/Servers/Connections.Abstractions/src/Features/IConnectionItemsFeature.cs b/src/Servers/Connections.Abstractions/src/Features/IConnectionItemsFeature.cs index 3d40d5498f..e0e8e43703 100644 --- a/src/Servers/Connections.Abstractions/src/Features/IConnectionItemsFeature.cs +++ b/src/Servers/Connections.Abstractions/src/Features/IConnectionItemsFeature.cs @@ -7,6 +7,6 @@ namespace Microsoft.AspNetCore.Connections.Features { public interface IConnectionItemsFeature { - IDictionary Items { get; set; } + IDictionary? Items { get; set; } } -} \ No newline at end of file +} diff --git a/src/Servers/Connections.Abstractions/src/Features/IConnectionTransportFeature.cs b/src/Servers/Connections.Abstractions/src/Features/IConnectionTransportFeature.cs index 0b218972d7..7f4fd4f9d6 100644 --- a/src/Servers/Connections.Abstractions/src/Features/IConnectionTransportFeature.cs +++ b/src/Servers/Connections.Abstractions/src/Features/IConnectionTransportFeature.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// 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.IO.Pipelines; @@ -7,6 +7,6 @@ namespace Microsoft.AspNetCore.Connections.Features { public interface IConnectionTransportFeature { - IDuplexPipe Transport { get; set; } + IDuplexPipe? Transport { get; set; } } } diff --git a/src/Servers/Connections.Abstractions/src/Features/IConnectionUserFeature.cs b/src/Servers/Connections.Abstractions/src/Features/IConnectionUserFeature.cs index 7698693a54..8e082af24a 100644 --- a/src/Servers/Connections.Abstractions/src/Features/IConnectionUserFeature.cs +++ b/src/Servers/Connections.Abstractions/src/Features/IConnectionUserFeature.cs @@ -7,6 +7,6 @@ namespace Microsoft.AspNetCore.Connections.Features { public interface IConnectionUserFeature { - ClaimsPrincipal User { get; set; } + ClaimsPrincipal? User { get; set; } } } diff --git a/src/Servers/Connections.Abstractions/src/IMulitplexedConnectionListener.cs b/src/Servers/Connections.Abstractions/src/IMulitplexedConnectionListener.cs index d867fe0938..9173dc4e5a 100644 --- a/src/Servers/Connections.Abstractions/src/IMulitplexedConnectionListener.cs +++ b/src/Servers/Connections.Abstractions/src/IMulitplexedConnectionListener.cs @@ -32,6 +32,6 @@ namespace Microsoft.AspNetCore.Connections /// A feature collection to pass options when accepting a connection. /// The token to monitor for cancellation requests. /// A that completes when a connection is accepted, yielding the representing the connection. - ValueTask AcceptAsync(IFeatureCollection features = null, CancellationToken cancellationToken = default); + ValueTask AcceptAsync(IFeatureCollection? features = null, CancellationToken cancellationToken = default); } } diff --git a/src/Servers/Connections.Abstractions/src/IMultiplexedConnectionFactory.cs b/src/Servers/Connections.Abstractions/src/IMultiplexedConnectionFactory.cs index a3f69f7a68..1b11aa57ad 100644 --- a/src/Servers/Connections.Abstractions/src/IMultiplexedConnectionFactory.cs +++ b/src/Servers/Connections.Abstractions/src/IMultiplexedConnectionFactory.cs @@ -22,6 +22,6 @@ namespace Microsoft.AspNetCore.Connections /// /// A that represents the asynchronous connect, yielding the for the new connection when completed. /// - ValueTask ConnectAsync(EndPoint endpoint, IFeatureCollection features = null, CancellationToken cancellationToken = default); + ValueTask ConnectAsync(EndPoint endpoint, IFeatureCollection? features = null, CancellationToken cancellationToken = default); } } diff --git a/src/Servers/Connections.Abstractions/src/IMultiplexedConnectionListenerFactory.cs b/src/Servers/Connections.Abstractions/src/IMultiplexedConnectionListenerFactory.cs index 3b5010beda..ee3e593b9d 100644 --- a/src/Servers/Connections.Abstractions/src/IMultiplexedConnectionListenerFactory.cs +++ b/src/Servers/Connections.Abstractions/src/IMultiplexedConnectionListenerFactory.cs @@ -20,6 +20,6 @@ namespace Microsoft.AspNetCore.Connections /// A feature collection to pass options when binding. /// The token to monitor for cancellation requests. /// A that completes when the listener has been bound, yielding a representing the new listener. - ValueTask BindAsync(EndPoint endpoint, IFeatureCollection features = null, CancellationToken cancellationToken = default); + ValueTask BindAsync(EndPoint endpoint, IFeatureCollection? features = null, CancellationToken cancellationToken = default); } } diff --git a/src/Servers/Connections.Abstractions/src/Microsoft.AspNetCore.Connections.Abstractions.csproj b/src/Servers/Connections.Abstractions/src/Microsoft.AspNetCore.Connections.Abstractions.csproj index ddefc4f62c..fcea395964 100644 --- a/src/Servers/Connections.Abstractions/src/Microsoft.AspNetCore.Connections.Abstractions.csproj +++ b/src/Servers/Connections.Abstractions/src/Microsoft.AspNetCore.Connections.Abstractions.csproj @@ -1,4 +1,4 @@ - + Core components of ASP.NET Core networking protocol stack. @@ -8,6 +8,7 @@ true aspnetcore CS1591;$(NoWarn) + enable diff --git a/src/Servers/Connections.Abstractions/src/MultiplexedConnectionContext.cs b/src/Servers/Connections.Abstractions/src/MultiplexedConnectionContext.cs index ce0850d281..27ca5444de 100644 --- a/src/Servers/Connections.Abstractions/src/MultiplexedConnectionContext.cs +++ b/src/Servers/Connections.Abstractions/src/MultiplexedConnectionContext.cs @@ -26,6 +26,6 @@ namespace Microsoft.AspNetCore.Connections /// /// /// - public abstract ValueTask ConnectAsync(IFeatureCollection features = null, CancellationToken cancellationToken = default); + public abstract ValueTask ConnectAsync(IFeatureCollection? features = null, CancellationToken cancellationToken = default); } } diff --git a/src/Shared/ActivatorUtilities/ActivatorUtilities.cs b/src/Shared/ActivatorUtilities/ActivatorUtilities.cs index 4d05ebf589..26eb81f432 100644 --- a/src/Shared/ActivatorUtilities/ActivatorUtilities.cs +++ b/src/Shared/ActivatorUtilities/ActivatorUtilities.cs @@ -1,6 +1,8 @@ // 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 disable warnings +#nullable enable annotations using System; using System.Linq; using System.Linq.Expressions; @@ -158,7 +160,7 @@ namespace Microsoft.Extensions.Internal return mc.Method; } - private static object GetService(IServiceProvider sp, Type type, Type requiredBy, bool isDefaultParameterRequired) + private static object? GetService(IServiceProvider sp, Type type, Type requiredBy, bool isDefaultParameterRequired) { var service = sp.GetService(type); if (service == null && !isDefaultParameterRequired) @@ -217,11 +219,11 @@ namespace Microsoft.Extensions.Internal out ConstructorInfo matchingConstructor, out int?[] parameterMap) { - matchingConstructor = null; - parameterMap = null; + matchingConstructor = null!; + parameterMap = null!; - if (!TryFindPreferredConstructor(instanceType, argumentTypes, ref matchingConstructor, ref parameterMap) && - !TryFindMatchingConstructor(instanceType, argumentTypes, ref matchingConstructor, ref parameterMap)) + if (!TryFindPreferredConstructor(instanceType, argumentTypes, ref matchingConstructor!, ref parameterMap!) && + !TryFindMatchingConstructor(instanceType, argumentTypes, ref matchingConstructor!, ref parameterMap!)) { var message = $"A suitable constructor for type '{instanceType}' could not be located. Ensure the type is concrete and services are registered for all parameters of a public constructor."; throw new InvalidOperationException(message); diff --git a/src/Shared/ParameterDefaultValue/ParameterDefaultValue.cs b/src/Shared/ParameterDefaultValue/ParameterDefaultValue.cs index dc635bb789..ae0710d3fc 100644 --- a/src/Shared/ParameterDefaultValue/ParameterDefaultValue.cs +++ b/src/Shared/ParameterDefaultValue/ParameterDefaultValue.cs @@ -1,6 +1,8 @@ // 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.Reflection; @@ -10,7 +12,7 @@ namespace Microsoft.Extensions.Internal { private static readonly Type _nullable = typeof(Nullable<>); - public static bool TryGetDefaultValue(ParameterInfo parameter, out object defaultValue) + public static bool TryGetDefaultValue(ParameterInfo parameter, out object? defaultValue) { bool hasDefaultValue; var tryToGetDefaultValue = true; diff --git a/src/Shared/PropertyHelper/PropertyHelper.cs b/src/Shared/PropertyHelper/PropertyHelper.cs index 3349833264..5a2d787ad7 100644 --- a/src/Shared/PropertyHelper/PropertyHelper.cs +++ b/src/Shared/PropertyHelper/PropertyHelper.cs @@ -1,6 +1,8 @@ // 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.Collections.Concurrent; using System.Collections.Generic; @@ -16,19 +18,19 @@ namespace Microsoft.Extensions.Internal private delegate TValue ByRefFunc(ref TDeclaringType arg); private static readonly MethodInfo CallPropertyGetterOpenGenericMethod = - typeof(PropertyHelper).GetTypeInfo().GetDeclaredMethod(nameof(CallPropertyGetter)); + typeof(PropertyHelper).GetTypeInfo().GetDeclaredMethod(nameof(CallPropertyGetter))!; private static readonly MethodInfo CallPropertyGetterByReferenceOpenGenericMethod = - typeof(PropertyHelper).GetTypeInfo().GetDeclaredMethod(nameof(CallPropertyGetterByReference)); + typeof(PropertyHelper).GetTypeInfo().GetDeclaredMethod(nameof(CallPropertyGetterByReference))!; private static readonly MethodInfo CallNullSafePropertyGetterOpenGenericMethod = - typeof(PropertyHelper).GetTypeInfo().GetDeclaredMethod(nameof(CallNullSafePropertyGetter)); + typeof(PropertyHelper).GetTypeInfo().GetDeclaredMethod(nameof(CallNullSafePropertyGetter))!; private static readonly MethodInfo CallNullSafePropertyGetterByReferenceOpenGenericMethod = - typeof(PropertyHelper).GetTypeInfo().GetDeclaredMethod(nameof(CallNullSafePropertyGetterByReference)); + typeof(PropertyHelper).GetTypeInfo().GetDeclaredMethod(nameof(CallNullSafePropertyGetterByReference))!; private static readonly MethodInfo CallPropertySetterOpenGenericMethod = - typeof(PropertyHelper).GetTypeInfo().GetDeclaredMethod(nameof(CallPropertySetter)); + typeof(PropertyHelper).GetTypeInfo().GetDeclaredMethod(nameof(CallPropertySetter))!; // Using an array rather than IEnumerable, as target will be called on the hot path numerous times. private static readonly ConcurrentDictionary PropertiesCache = @@ -41,18 +43,18 @@ namespace Microsoft.Extensions.Internal // for platforms where the attribute is not defined, like net46. So we can fetch the attribute // by late binding. If the attribute isn't defined, then we assume we won't encounter any // 'ref struct' types. - private static readonly Type IsByRefLikeAttribute = Type.GetType("System.Runtime.CompilerServices.IsByRefLikeAttribute", throwOnError: false); + private static readonly Type? IsByRefLikeAttribute = Type.GetType("System.Runtime.CompilerServices.IsByRefLikeAttribute", throwOnError: false); - private Action _valueSetter; - private Func _valueGetter; + private Action? _valueSetter; + private Func? _valueGetter; /// /// Initializes a fast . /// This constructor does not cache the helper. For caching, use . /// public PropertyHelper(PropertyInfo property) - { - Property = property ?? throw new ArgumentNullException(nameof(property)); + { + Property = property ?? throw new ArgumentNullException(nameof(property)); Name = property.Name; } @@ -243,7 +245,7 @@ namespace Microsoft.Extensions.Internal // Instance methods in the CLR can be turned into static methods where the first parameter // is open over "target". This parameter is always passed by reference, so we have a code // path for value types and a code path for reference types. - if (getMethod.DeclaringType.GetTypeInfo().IsValueType) + if (getMethod.DeclaringType!.GetTypeInfo().IsValueType) { // Create a delegate (ref TDeclaringType) -> TValue return MakeFastPropertyGetter( @@ -266,7 +268,7 @@ namespace Microsoft.Extensions.Internal MethodInfo propertyGetMethod, MethodInfo openGenericWrapperMethod) { - var typeInput = propertyGetMethod.DeclaringType; + var typeInput = propertyGetMethod.DeclaringType!; var typeOutput = propertyGetMethod.ReturnType; var delegateType = openGenericDelegateType.MakeGenericType(typeInput, typeOutput); @@ -292,7 +294,7 @@ namespace Microsoft.Extensions.Internal public static Action MakeFastPropertySetter(PropertyInfo propertyInfo) { Debug.Assert(propertyInfo != null); - Debug.Assert(!propertyInfo.DeclaringType.GetTypeInfo().IsValueType); + Debug.Assert(!propertyInfo.DeclaringType!.GetTypeInfo().IsValueType); var setMethod = propertyInfo.SetMethod; Debug.Assert(setMethod != null); @@ -304,7 +306,7 @@ namespace Microsoft.Extensions.Internal // Instance methods in the CLR can be turned into static methods where the first parameter // is open over "target". This parameter is always passed by reference, so we have a code // path for value types and a code path for reference types. - var typeInput = setMethod.DeclaringType; + var typeInput = setMethod.DeclaringType!; var parameterType = parameters[0].ParameterType; // Create a delegate TDeclaringType -> { TDeclaringType.Property = TValue; } @@ -357,7 +359,7 @@ namespace Microsoft.Extensions.Internal } // Called via reflection - private static object CallPropertyGetter( + private static object? CallPropertyGetter( Func getter, object target) { @@ -365,7 +367,7 @@ namespace Microsoft.Extensions.Internal } // Called via reflection - private static object CallPropertyGetterByReference( + private static object? CallPropertyGetterByReference( ByRefFunc getter, object target) { @@ -374,7 +376,7 @@ namespace Microsoft.Extensions.Internal } // Called via reflection - private static object CallNullSafePropertyGetter( + private static object? CallNullSafePropertyGetter( Func getter, object target) { @@ -387,7 +389,7 @@ namespace Microsoft.Extensions.Internal } // Called via reflection - private static object CallNullSafePropertyGetterByReference( + private static object? CallNullSafePropertyGetterByReference( ByRefFunc getter, object target) { @@ -455,8 +457,8 @@ namespace Microsoft.Extensions.Internal // Walk up the hierarchy until we find the type that actually declares this // PropertyInfo. - var currentTypeInfo = type.GetTypeInfo(); - var declaringTypeInfo = declaringType.GetTypeInfo(); + TypeInfo? currentTypeInfo = type.GetTypeInfo(); + var declaringTypeInfo = declaringType?.GetTypeInfo(); while (currentTypeInfo != null && currentTypeInfo != declaringTypeInfo) { // We've found a 'more proximal' public definition @@ -527,7 +529,7 @@ namespace Microsoft.Extensions.Internal property.GetMethod.GetParameters().Length == 0; } - // PropertyHelper can't really interact with ref-struct properties since they can't be + // PropertyHelper can't really interact with ref-struct properties since they can't be // boxed and can't be used as generic types. We just ignore them. // // see: https://github.com/aspnet/Mvc/issues/8545 diff --git a/src/Shared/test/Shared.Tests/Microsoft.AspNetCore.Shared.Tests.csproj b/src/Shared/test/Shared.Tests/Microsoft.AspNetCore.Shared.Tests.csproj index c1db74970e..b80599128b 100644 --- a/src/Shared/test/Shared.Tests/Microsoft.AspNetCore.Shared.Tests.csproj +++ b/src/Shared/test/Shared.Tests/Microsoft.AspNetCore.Shared.Tests.csproj @@ -5,6 +5,7 @@ portable true CS0649;CS0436 + annotations