From ff2f78df10338d6b957e56ee57f06ad6cef03918 Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Thu, 2 Jan 2020 00:53:38 -0800 Subject: [PATCH 1/3] Add nullable annotations to Http.Abstractions, Http.Features, Connections.Abstractions --- .../ref/Microsoft.Net.Http.Headers.csproj | 1 + .../Microsoft.Net.Http.Headers.netcoreapp.cs | 94 ++--- src/Http/Headers/src/BaseHeaderParser.cs | 7 +- .../Headers/src/CacheControlHeaderValue.cs | 28 +- .../src/ContentDispositionHeaderValue.cs | 33 +- .../Headers/src/ContentRangeHeaderValue.cs | 13 +- src/Http/Headers/src/CookieHeaderParser.cs | 6 +- src/Http/Headers/src/CookieHeaderValue.cs | 15 +- src/Http/Headers/src/EntityTagHeaderValue.cs | 25 +- src/Http/Headers/src/GenericHeaderParser.cs | 5 +- src/Http/Headers/src/HeaderUtilities.cs | 13 +- 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 | 36 +- 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 | 23 +- .../src/StringWithQualityHeaderValue.cs | 19 +- .../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, 1037 insertions(+), 1022 deletions(-) diff --git a/src/Http/Headers/ref/Microsoft.Net.Http.Headers.csproj b/src/Http/Headers/ref/Microsoft.Net.Http.Headers.csproj index 5d53f319730f..ab3ef8ff5022 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 74bfe68f38e0..ea797363e3f5 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 @@ public CacheControlHeaderValue() { } 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, out Microsoft.Net.Http.Headers.CacheControlHeaderValue? parsedValue) { throw null; } } public partial class ContentDispositionHeaderValue { @@ -52,13 +52,13 @@ public ContentDispositionHeaderValue(Microsoft.Extensions.Primitives.StringSegme 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,7 +76,7 @@ public ContentRangeHeaderValue(long from, long to, long length) { } 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; } @@ -88,15 +88,15 @@ public CookieHeaderValue(Microsoft.Extensions.Primitives.StringSegment name) { } 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 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 @@ public EntityTagHeaderValue(Microsoft.Extensions.Primitives.StringSegment tag, b 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 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 @@ public MediaTypeHeaderValue(Microsoft.Extensions.Primitives.StringSegment mediaT 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 @@ public MediaTypeHeaderValue(Microsoft.Extensions.Primitives.StringSegment mediaT 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,8 +269,8 @@ public NameValueHeaderValue(Microsoft.Extensions.Primitives.StringSegment name, 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; } @@ -278,22 +278,22 @@ public NameValueHeaderValue(Microsoft.Extensions.Primitives.StringSegment name, 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 @@ public RangeHeaderValue() { } 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 @@ public SetCookieHeaderValue(Microsoft.Extensions.Primitives.StringSegment name, 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 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 @@ public StringWithQualityHeaderValue(Microsoft.Extensions.Primitives.StringSegmen 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 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 f3caaafb706c..4e8078787880 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 @@ protected BaseHeaderParser(bool supportsMultipleValues) { } - 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 cee7f8b8c1ce..16dab420fda1 100644 --- a/src/Http/Headers/src/CacheControlHeaderValue.cs +++ b/src/Http/Headers/src/CacheControlHeaderValue.cs @@ -31,12 +31,12 @@ public class CacheControlHeaderValue // 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 +47,10 @@ private static readonly HttpHeaderParser Parser 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 +240,7 @@ public override string ToString() return sb.ToString(); } - public override bool Equals(object obj) + public override bool Equals(object? obj) { var other = obj as CacheControlHeaderValue; @@ -335,7 +335,7 @@ public static CacheControlHeaderValue Parse(StringSegment input) return result; } - public static bool TryParse(StringSegment input, out CacheControlHeaderValue parsedValue) + public static bool TryParse(StringSegment input, out CacheControlHeaderValue? parsedValue) { int 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. @@ -347,7 +347,7 @@ public static bool TryParse(StringSegment input, out CacheControlHeaderValue par 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 +361,18 @@ private static int GetCacheControlLength(StringSegment input, int startIndex, ou // 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 +541,8 @@ private static bool TrySetTokenOnlyValue(NameValueHeaderValue nameValue, ref boo 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 +603,6 @@ private static bool TrySetOptionalTokenList( 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 cb868ce8973d..be5027e693c0 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 @@ public class ContentDispositionHeaderValue 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() @@ -128,7 +129,7 @@ public long? Size // Remove parameter if (sizeParameter != null) { - _parameters.Remove(sizeParameter); + _parameters!.Remove(sizeParameter); } } else if (value < 0) @@ -142,7 +143,7 @@ public long? Size else { string sizeString = value.GetValueOrDefault().ToString(CultureInfo.InvariantCulture); - _parameters.Add(new NameValueHeaderValue(SizeString, sizeString)); + _parameters!.Add(new NameValueHeaderValue(SizeString, sizeString)); } } } @@ -180,7 +181,7 @@ public override string ToString() 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 +203,16 @@ public override int GetHashCode() 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 +254,7 @@ private static int GetDispositionTypeLength(StringSegment input, int startIndex, 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 +319,7 @@ private void SetDate(string parameter, DateTimeOffset? date) // Remove parameter if (dateParameter != null) { - _parameters.Remove(dateParameter); + _parameters!.Remove(dateParameter); } } else @@ -343,7 +344,7 @@ private StringSegment GetName(string parameter) 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 +376,7 @@ private void SetName(StringSegment parameter, StringSegment value) // Remove parameter if (nameParameter != null) { - _parameters.Remove(nameParameter); + _parameters!.Remove(nameParameter); } } else @@ -497,7 +498,7 @@ private unsafe string EncodeMime(StringSegment input) } // 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 +583,7 @@ private static void HexEscape(StringBuilder builder, char c) // 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 +594,7 @@ private bool TryDecode5987(StringSegment input, out string output) } 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 99723864f390..4226ea9f837e 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 @@ public long? Length 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 @@ public override string ToString() 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) { 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 @@ private static bool TryCreateContentRange( 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 7201ae21a18d..9f7e59e89348 100644 --- a/src/Http/Headers/src/CookieHeaderParser.cs +++ b/src/Http/Headers/src/CookieHeaderParser.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 System.Diagnostics.Contracts; using Microsoft.Extensions.Primitives; @@ -13,7 +14,7 @@ internal CookieHeaderParser(bool supportsMultipleValues) { } - public override bool TryParseValue(StringSegment value, ref int index, out CookieHeaderValue parsedValue) + public override bool TryParseValue(StringSegment value, ref int index, [MaybeNull] out CookieHeaderValue? parsedValue) { parsedValue = null; @@ -43,7 +44,7 @@ public override bool TryParseValue(StringSegment value, ref int index, out Cooki return SupportsMultipleValues; } - CookieHeaderValue result = null; + CookieHeaderValue? result = null; if (!CookieHeaderValue.TryGetCookieLength(value, ref current, out result)) { return false; @@ -64,7 +65,6 @@ public override bool TryParseValue(StringSegment value, ref int index, out Cooki 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 54753d2830b4..e7c306b61d1d 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,13 +84,13 @@ public override string ToString() 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) @@ -102,18 +103,18 @@ 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); @@ -256,7 +257,7 @@ internal static void CheckValueFormat(StringSegment value, string parameterName) } } - 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 9b3a37136b49..7e44c79a44f5 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 @@ public class EntityTagHeaderValue // 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 @@ public override string ToString() /// 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 @@ public override int GetHashCode() /// 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 @@ public bool Compare(EntityTagHeaderValue other, bool useStrongComparison) 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) { 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 a2fbf720f9f7..53a577744835 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 @@ internal GenericHeaderParser(bool supportsMultipleValues, GetParsedValueLengthDe _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 ac193c0c3820..735592844815 100644 --- a/src/Http/Headers/src/HeaderUtilities.cs +++ b/src/Http/Headers/src/HeaderUtilities.cs @@ -19,8 +19,6 @@ public static class HeaderUtilities 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 @@ internal static void SetQuality(IList parameters, double? } else { - parameters.Add(new NameValueHeaderValue(QualityName, qualityString)); + parameters!.Add(new NameValueHeaderValue(QualityName, qualityString)); } } else @@ -49,15 +47,13 @@ internal static void SetQuality(IList parameters, double? // Remove quality parameter if (qualityParameter != null) { - parameters.Remove(qualityParameter); + parameters!.Remove(qualityParameter); } } } internal static double? GetQuality(IList parameters) { - Contract.Requires(parameters != null); - var qualityParameter = NameValueHeaderValue.Find(parameters, QualityName); if (qualityParameter != null) { @@ -85,12 +81,12 @@ internal static void CheckValidToken(StringSegment value, string parameterName) } } - 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 @@ internal static int GetNextNonEmptyOrWhitespaceIndex( 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 027a9de43840..addb5479f8f7 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 @@ public bool SupportsMultipleValues // 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 @@ public T ParseValue(StringSegment value, ref int index) 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 @@ protected virtual bool TryParseValues(IList values, bool strict, out ILi 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 @@ protected virtual bool TryParseValues(IList values, bool strict, out ILi 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 @@ protected virtual IList ParseValues(IList values, bool strict) // 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 05f4a4576fec..a3563e3fe6e8 100644 --- a/src/Http/Headers/src/HttpRuleParser.cs +++ b/src/Http/Headers/src/HttpRuleParser.cs @@ -93,7 +93,6 @@ internal static bool IsTokenChar(char character) [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 @@ internal static int GetTokenLength(StringSegment input, int startIndex) 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 @@ internal static int GetWhitespaceLength(StringSegment input, int startIndex) 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 @@ internal static HttpParseResult GetQuotedStringLength(StringSegment input, int s // 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 a7a39c904e5b..1162440e004b 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 @@ public class MediaTypeHeaderValue 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 @@ public StringSegment Charset /// 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 @@ public IList Parameters /// public double? Quality { - get { return HeaderUtilities.GetQuality(_parameters); } + get { return HeaderUtilities.GetQuality(Parameters); } set { HeaderUtilities.ThrowIfReadOnly(IsReadOnly); @@ -444,7 +445,7 @@ public override string ToString() return builder.ToString(); } - public override bool Equals(object obj) + public override bool Equals(object? obj) { var other = obj as MediaTypeHeaderValue; @@ -471,7 +472,7 @@ public override int GetHashCode() 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 @@ public static MediaTypeHeaderValue Parse(StringSegment input) /// 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 @@ public static bool TryParse(StringSegment input, out MediaTypeHeaderValue parsed /// /// 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 @@ public static IList ParseList(IList inputs) /// /// 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 @@ public static IList ParseStrictList(IList inputs) /// 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 @@ public static bool TryParseList(IList inputs, out IListA 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 @@ private static int GetMediaTypeLength(StringSegment input, int startIndex, out M 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 @@ private static int GetMediaTypeLength(StringSegment input, int startIndex, out M 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 cc34640988b5..f442f6441f60 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 @@ public static MediaTypeHeaderValueComparer QualityComparer /// 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 d0c27e7ed75d..afde882724f6 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 58d337d55af6..bcb57684c47d 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 @@ public override int GetHashCode() return nameHashCode; } - public override bool Equals(object obj) + public override bool Equals(object? obj) { var other = obj as NameValueHeaderValue; @@ -168,13 +169,13 @@ public void SetAndEscapeValue(StringSegment value) 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) @@ -187,12 +188,12 @@ 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 @@ public override string ToString() } internal static void ToString( - IList values, + IList? values, char separator, bool leadingSeparator, StringBuilder destination) @@ -235,7 +236,7 @@ internal static void ToString( } } - 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 @@ internal static string ToString(IList values, char separat 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 @@ internal static int GetHashCode(IList values) 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 @@ internal static int GetNameValueListLength( char delimiter, IList nameValueCollection) { - Contract.Requires(nameValueCollection != null); Contract.Requires(startIndex >= 0); if ((StringSegment.IsNullOrEmpty(input)) || (startIndex >= input.Length)) @@ -334,8 +333,7 @@ internal static int GetNameValueListLength( 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 @@ internal static int GetNameValueListLength( return current - startIndex; } - nameValueCollection.Add(parameter); + nameValueCollection!.Add(parameter!); current = current + nameValueLength; current = current + HttpRuleParser.GetWhitespaceLength(input, current); @@ -359,9 +357,9 @@ internal static int GetNameValueListLength( } } - 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)) { diff --git a/src/Http/Headers/src/ObjectCollection.cs b/src/Http/Headers/src/ObjectCollection.cs index f46b2dd743b0..c322802440cf 100644 --- a/src/Http/Headers/src/ObjectCollection.cs +++ b/src/Http/Headers/src/ObjectCollection.cs @@ -21,7 +21,7 @@ internal static readonly ObjectCollection EmptyReadOnlyCollection // 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 @@ private static void CheckNotNull(T item) } } } -} \ No newline at end of file +} diff --git a/src/Http/Headers/src/RangeConditionHeaderValue.cs b/src/Http/Headers/src/RangeConditionHeaderValue.cs index b1d6513e2ee8..ebe21f59b80c 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 @@ public RangeConditionHeaderValue(DateTimeOffset lastModified) _lastModified = lastModified; } - public RangeConditionHeaderValue(EntityTagHeaderValue entityTag) + public RangeConditionHeaderValue(EntityTagHeaderValue? entityTag) { if (entityTag == null) { @@ -35,7 +36,7 @@ public RangeConditionHeaderValue(EntityTagHeaderValue entityTag) _entityTag = entityTag; } - public RangeConditionHeaderValue(string entityTag) + public RangeConditionHeaderValue(string? entityTag) : this(new EntityTagHeaderValue(entityTag)) { } @@ -45,7 +46,7 @@ public DateTimeOffset? LastModified get { return _lastModified; } } - public EntityTagHeaderValue EntityTag + public EntityTagHeaderValue? EntityTag { get { return _entityTag; } } @@ -59,7 +60,7 @@ public override string ToString() return _entityTag.ToString(); } - public override bool Equals(object obj) + public override bool Equals(object? obj) { var other = obj as RangeConditionHeaderValue; @@ -89,16 +90,16 @@ public override int GetHashCode() 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 @@ private static int GetRangeConditionLength(StringSegment input, int startIndex, // 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 @@ private static int GetRangeConditionLength(StringSegment input, int startIndex, 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 67d671267b60..8247c3ff60e6 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 @@ public override string ToString() return sb.ToString(); } - public override bool Equals(object obj) + public override bool Equals(object? obj) { var other = obj as RangeHeaderValue; @@ -105,16 +106,16 @@ public override int GetHashCode() 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 010f2da1e0ae..edc4d4b2e0f2 100644 --- a/src/Http/Headers/src/RangeItemHeaderValue.cs +++ b/src/Http/Headers/src/RangeItemHeaderValue.cs @@ -61,7 +61,7 @@ public override string ToString() _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 @@ internal static int GetRangeItemListLength( 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 @@ internal static int GetRangeItemListLength( return 0; } - RangeItemHeaderValue range = null; + RangeItemHeaderValue? range = null; while (true) { var rangeLength = GetRangeItemLength(input, current, out range); @@ -121,7 +120,7 @@ internal static int GetRangeItemListLength( return 0; } - rangeCollection.Add(range); + rangeCollection!.Add(range!); current = current + rangeLength; current = HeaderUtilities.GetNextNonEmptyOrWhitespaceIndex(input, current, true, out separatorFound); @@ -140,7 +139,7 @@ internal static int GetRangeItemListLength( } } - 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 cdf12381aa44..092c4bc43db7 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 @@ public class SetCookieHeaderValue 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 @@ public override string ToString() { var length = _name.Length + EqualsToken.Length + _value.Length; - string maxAge = null; - string sameSite = null; + string? maxAge = null; + string? sameSite = null; if (Expires.HasValue) { @@ -296,13 +297,13 @@ private static void AppendSegment(StringBuilder builder, StringSegment name, Str 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) @@ -315,18 +316,18 @@ 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 @@ private static StringSegment ReadToSemicolonOrEnd(StringSegment input, ref int o 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 153643b36156..66ce2a1eefab 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 @@ public override string ToString() return _value.ToString(); } - public override bool Equals(object obj) + public override bool Equals(object? obj) { var other = obj as StringWithQualityHeaderValue; @@ -106,13 +107,13 @@ public override int GetHashCode() 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) @@ -125,17 +126,17 @@ public static IList ParseStrictList(IList 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 961cc078417b..9655414a05cd 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 @@ public static StringWithQualityHeaderValueComparer QualityComparer /// 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 51e8ce5f5805..8bca38b903f3 100644 --- a/src/Http/Headers/test/CacheControlHeaderValueTest.cs +++ b/src/Http/Headers/test/CacheControlHeaderValueTest.cs @@ -62,7 +62,7 @@ public void Properties_SetAndGetAllProperties_SetValueReturnedInGetter() // 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 @@ public void Equals_CompareCollectionFieldsSet_MatchExpectation() 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 @@ private void CompareValues(CacheControlHeaderValue x, CacheControlHeaderValue y, 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 6076b2cc1564..4d0b1b7cf78f 100644 --- a/src/Http/Headers/test/ContentDispositionHeaderValueTest.cs +++ b/src/Http/Headers/test/ContentDispositionHeaderValueTest.cs @@ -58,7 +58,7 @@ public void Ctor_ContentDispositionValidFormat_SuccessfullyCreated() 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 @@ public void Equals_UseContentDispositionWithAndWithoutParameters_EqualOrNotEqual 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 @@ public ContentDispositionValue(string value, string description, bool valid) 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 d8abdbdbf6b9..061cabd4a64f 100644 --- a/src/Http/Headers/test/ContentRangeHeaderValueTest.cs +++ b/src/Http/Headers/test/ContentRangeHeaderValueTest.cs @@ -132,7 +132,7 @@ public void Equals_UseSameAndDifferentRanges_EqualOrNotEqualNoExceptions() 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 @@ public void Parse_SetOfValidValueStrings_ParsedCorrectly() [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 @@ public void TryParse_SetOfValidValueStrings_ParsedCorrectly() // 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 @@ public void TryParse_SetOfValidValueStrings_ParsedCorrectly() [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 edd55bb7ab67..4d13310fe719 100644 --- a/src/Http/Headers/test/CookieHeaderValueTest.cs +++ b/src/Http/Headers/test/CookieHeaderValueTest.cs @@ -80,11 +80,11 @@ public static TheoryData InvalidCookieValues } } - 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 @@ public static TheoryData, string[]> ListOfCookieHeaderD 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 @@ public static TheoryData, string[]> ListOfCookieHeaderD } } - 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 @@ public void CookieHeaderValue_TryParse_AcceptsValidValues(CookieHeaderValue cook 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 5c211c436844..9801a5f5017d 100644 --- a/src/Http/Headers/test/DateParserTest.cs +++ b/src/Http/Headers/test/DateParserTest.cs @@ -35,9 +35,9 @@ public void TryParse_SetOfInvalidValueStrings_ReturnsFalse(string input) 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 b4ae186fb455..7320b09128a9 100644 --- a/src/Http/Headers/test/EntityTagHeaderValueTest.cs +++ b/src/Http/Headers/test/EntityTagHeaderValueTest.cs @@ -92,7 +92,7 @@ public void Equals_UseSameAndDifferentETags_EqualOrNotEqualNoExceptions() 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 @@ public void ParseList_NullOrEmptyArray_ReturnsEmptyList() [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 @@ public void TryParseList_SetOfValidValueStrings_ParsedCorrectly() "\"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 @@ public void TryParseStrictList_SetOfValidValueStrings_ParsedCorrectly() "\"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 @@ public void TryParseList_WithSomeInvalidValues_ExcludesInvalidValues() "\"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 @@ public void TryParseStrictList_WithSomeInvalidValues_ReturnsFalse() "\"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 63b2fa391b3d..025dcab4b1a7 100644 --- a/src/Http/Headers/test/MediaTypeHeaderValueTest.cs +++ b/src/Http/Headers/test/MediaTypeHeaderValueTest.cs @@ -40,8 +40,8 @@ public void Ctor_MediaTypeInvalidFormat_ThrowFormatException() 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 @@ public void Ctor_AddNameAndQuality_QualityParameterAdded() 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 @@ public void Equals_UseMediaTypeWithAndWithoutParameters_EqualOrNotEqualNoExcepti 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 @@ public void ParseList_NullOrEmptyArray_ReturnsEmptyList() [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 @@ public void ParseStrictList_SetOfValidValueStrings_ReturnsValues() 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 @@ public void TryParseList_SetOfValidValueStrings_ReturnsTrue() 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 @@ public void TryParseList_WithSomeInvalidValues_IgnoresInvalidValues() "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 @@ public void TryParseStrictList_WithSomeInvalidValues_ReturnsFalse() "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 @@ public void Facets_TestPositiveCases(string input, List expected) 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 40c26c701bec..083c177f737d 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 4833b6898a7d..99f276ab6201 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 @@ public void TryParseList_SetOfValidValueStrings_ParsedCorrectly() "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 @@ public void TryParseStrictList_SetOfValidValueStrings_ParsedCorrectly() "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 @@ public void TryParseList_WithSomeInvalidValues_ExcludesInvalidValues() "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 @@ public void TryParseStrictList_WithSomeInvalidValues_ReturnsFalse() "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 @@ public void OverescapingValuesDoNotRoundTrip(string input) #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 dab3f670a4b3..58ddda041dc8 100644 --- a/src/Http/Headers/test/RangeConditionHeaderValueTest.cs +++ b/src/Http/Headers/test/RangeConditionHeaderValueTest.cs @@ -15,7 +15,7 @@ public void Ctor_EntityTagOverload_MatchExpectation() 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 @@ public void Ctor_EntityTagStringOverload_MatchExpectation() 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 @@ public void Equals_UseSameAndDifferentRanges_EqualOrNotEqualNoExceptions() 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 @@ public void TryParse_SetOfValidValueStrings_ParsedCorrectly() [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 @@ private void CheckValidParse(string input, RangeConditionHeaderValue expectedRes 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 92a1d72521fc..48b4b4214668 100644 --- a/src/Http/Headers/test/RangeHeaderValueTest.cs +++ b/src/Http/Headers/test/RangeHeaderValueTest.cs @@ -82,7 +82,7 @@ public void Equals_UseSameAndDifferentRanges_EqualOrNotEqualNoExceptions() 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 @@ public void TryParse_SetOfInvalidValueStrings_ReturnsFalse() #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 95598f0a46f4..300b0ced5667 100644 --- a/src/Http/Headers/test/RangeItemHeaderValueTest.cs +++ b/src/Http/Headers/test/RangeItemHeaderValueTest.cs @@ -83,7 +83,7 @@ public void Equals_UseSameAndDifferentRanges_EqualOrNotEqualNoExceptions() 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 4f33c54599b6..da754659268c 100644 --- a/src/Http/Headers/test/SetCookieHeaderValueTest.cs +++ b/src/Http/Headers/test/SetCookieHeaderValueTest.cs @@ -111,11 +111,11 @@ public static TheoryData InvalidCookieValues } } - 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 @@ public static TheoryData, string[]> ListOfSetCookieH } } - 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 @@ public void SetCookieHeaderValue_TryParse_AcceptsValidValues(SetCookieHeaderValu 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 @@ public void SetCookieHeaderValue_TryParse_SkipExtensionValues() { 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 971ad1028f25..f124b0bfd0bc 100644 --- a/src/Http/Headers/test/StringWithQualityHeaderValueTest.cs +++ b/src/Http/Headers/test/StringWithQualityHeaderValueTest.cs @@ -94,7 +94,7 @@ public void Equals_UseSameAndDifferentRanges_EqualOrNotEqualNoExceptions() 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 @@ public void TryParseList_SetOfValidValueStrings_ParsedCorrectly() "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 @@ public void TryParseStrictList_SetOfValidValueStrings_ParsedCorrectly() "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 @@ public void TryParseList_WithSomeInvalidValues_IgnoresInvalidValues() "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 @@ public void TryParseStrictList_WithSomeInvalidValues_ReturnsFalse() "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 169218db016b..de86fb18872c 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 cf0367cbda24..df35a394696e 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 @@ public MapMiddleware(Microsoft.AspNetCore.Http.RequestDelegate next, Microsoft.A 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 @@ public MapWhenMiddleware(Microsoft.AspNetCore.Http.RequestDelegate next, Microso 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 @@ protected ConnectionInfo() { } 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 @@ public Endpoint(Microsoft.AspNetCore.Http.RequestDelegate requestDelegate, Micro 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 @@ public EndpointMetadataCollection(params object[] items) { } 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 @@ public void Reset() { } 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 @@ public static void SetCommaSeparatedValues(this Microsoft.AspNetCore.Http.IHeade 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 @@ public abstract partial class HttpContext 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 @@ public partial interface IMiddleware } 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 @@ public partial interface IMiddlewareFactory 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 @@ public partial interface IMiddlewareFactory 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 @@ public partial interface IMiddlewareFactory 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 @@ protected WebSocketManager() { } 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 @@ public partial interface IRouteValuesFeature } 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 429de53cf32a..456bc05e99d1 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 @@ public virtual string Name /// /// 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 @@ public virtual string Name /// /// 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 2db104bb45e2..470bb5031f84 100644 --- a/src/Http/Http.Abstractions/src/Extensions/EndpointBuilder.cs +++ b/src/Http/Http.Abstractions/src/Extensions/EndpointBuilder.cs @@ -14,12 +14,12 @@ public abstract class EndpointBuilder /// /// 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 fc33e8fe8aa1..a74a883b20be 100644 --- a/src/Http/Http.Abstractions/src/Extensions/MapExtensions.cs +++ b/src/Http/Http.Abstractions/src/Extensions/MapExtensions.cs @@ -46,7 +46,7 @@ public static IApplicationBuilder Map(this IApplicationBuilder app, PathString p 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 0ba76507c8ad..cf9e617bd8cb 100644 --- a/src/Http/Http.Abstractions/src/Extensions/MapMiddleware.cs +++ b/src/Http/Http.Abstractions/src/Extensions/MapMiddleware.cs @@ -32,6 +32,11 @@ public MapMiddleware(RequestDelegate next, MapOptions options) 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 @@ public async Task Invoke(HttpContext context) 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 d914aa4210ff..61c1e8d9a4fd 100644 --- a/src/Http/Http.Abstractions/src/Extensions/MapOptions.cs +++ b/src/Http/Http.Abstractions/src/Extensions/MapOptions.cs @@ -18,7 +18,7 @@ public class MapOptions /// /// 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 1441da4d9920..4c384104e61e 100644 --- a/src/Http/Http.Abstractions/src/Extensions/MapWhenMiddleware.cs +++ b/src/Http/Http.Abstractions/src/Extensions/MapWhenMiddleware.cs @@ -32,6 +32,16 @@ public MapWhenMiddleware(RequestDelegate next, MapWhenOptions options) 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 @@ public async Task Invoke(HttpContext context) 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 @@ public async Task Invoke(HttpContext context) } } } -} \ 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 d18eb7f257a1..3696306962de 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 @@ public Func Predicate /// /// 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 3342b4e08d72..f33707e67167 100644 --- a/src/Http/Http.Abstractions/src/Extensions/UseMiddlewareExtensions.cs +++ b/src/Http/Http.Abstractions/src/Extensions/UseMiddlewareExtensions.cs @@ -20,7 +20,7 @@ public static class UseMiddlewareExtensions 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 @@ private static IApplicationBuilder UseMiddlewareInterface(IApplicationBuilder ap { 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 @@ private static Func Compile(MethodInf } 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 fbe936ce899d..6233d7f2a10a 100644 --- a/src/Http/Http.Abstractions/src/FragmentString.cs +++ b/src/Http/Http.Abstractions/src/FragmentString.cs @@ -114,7 +114,7 @@ public bool Equals(FragmentString other) 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 c15d59bf569e..f9ba89d2f1ef 100644 --- a/src/Http/Http.Abstractions/src/HostString.cs +++ b/src/Http/Http.Abstractions/src/HostString.cs @@ -297,7 +297,7 @@ public bool Equals(HostString other) /// /// 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 115e8a810ded..a39b208e18e7 100644 --- a/src/Http/Http.Abstractions/src/HttpContext.cs +++ b/src/Http/Http.Abstractions/src/HttpContext.cs @@ -47,7 +47,7 @@ public abstract class HttpContext /// /// 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 @@ public abstract class HttpContext /// /// 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 373b82588ab2..33f8a9ed8f9d 100644 --- a/src/Http/Http.Abstractions/src/HttpRequest.cs +++ b/src/Http/Http.Abstractions/src/HttpRequest.cs @@ -131,6 +131,6 @@ public abstract class HttpRequest /// 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 5d9fda8a751a..91a8a5a3d1f0 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 @@ public interface IMiddlewareFactory /// /// 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 f86ea7db073f..00bf3e8cf295 100644 --- a/src/Http/Http.Abstractions/src/Internal/HeaderSegment.cs +++ b/src/Http/Http.Abstractions/src/Internal/HeaderSegment.cs @@ -35,7 +35,7 @@ public bool Equals(HeaderSegment other) 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 70d6b4510907..b83bf4eeeaea 100644 --- a/src/Http/Http.Abstractions/src/Internal/HeaderSegmentCollection.cs +++ b/src/Http/Http.Abstractions/src/Internal/HeaderSegmentCollection.cs @@ -22,7 +22,7 @@ public bool Equals(HeaderSegmentCollection other) 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 ede671fb9934..dfc0ee474018 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 40fe610a82dc..79f82ddd1a4e 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 @@ public PathString(string value) /// /// The unescaped path value /// - public string Value + public string? Value { get { return _value; } } @@ -72,7 +72,7 @@ public string ToUriComponent() return string.Empty; } - var value = _value; + var value = _value!; var i = 0; for (; i < value.Length; i++) { @@ -92,7 +92,7 @@ public string ToUriComponent() private static string ToEscapedUriComponent(string value, int i) { - StringBuilder buffer = null; + StringBuilder? buffer = null; var start = 0; var count = i; @@ -174,7 +174,7 @@ private static string ToEscapedUriComponent(string value, int i) } } - return buffer.ToString(); + return buffer?.ToString() ?? string.Empty; } } @@ -318,11 +318,11 @@ public PathString Add(PathString other) { 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 @@ public bool Equals(PathString other, StringComparison comparisonType) /// /// 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 @@ public override bool Equals(object obj) /// 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 @@ public override int GetHashCode() /// 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 @@ public static implicit operator PathString(string s) 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 @@ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo c 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 64296e6beeb2..f9babe788928 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 @@ public override string ToString() 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 @@ public static QueryString Create(string name, string value) /// /// /// 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 @@ public static QueryString Create(IEnumerable> param 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 @@ public static QueryString Create(IEnumerable> 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 @@ public QueryString Add(string name, string value) 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 @@ public bool Equals(QueryString other) { 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 @@ public override bool Equals(object obj) 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 @@ public override int GetHashCode() 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 dbca2944e03c..4733177674ba 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 @@ public Endpoint( /// 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 d766e8336a8a..3eea0541f4b9 100644 --- a/src/Http/Http.Abstractions/src/Routing/EndpointHttpContextExtensions.cs +++ b/src/Http/Http.Abstractions/src/Routing/EndpointHttpContextExtensions.cs @@ -16,7 +16,7 @@ public static class EndpointHttpContextExtensions /// /// The context. /// The . - public static Endpoint GetEndpoint(this HttpContext context) + public static Endpoint? GetEndpoint(this HttpContext context) { if (context == null) { @@ -31,7 +31,7 @@ public static Endpoint GetEndpoint(this HttpContext context) /// /// 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 @@ public static void SetEndpoint(this HttpContext context, Endpoint endpoint) 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 47f9d6e1e57e..6051068e527c 100644 --- a/src/Http/Http.Abstractions/src/Routing/EndpointMetadataCollection.cs +++ b/src/Http/Http.Abstractions/src/Routing/EndpointMetadataCollection.cs @@ -72,7 +72,7 @@ public EndpointMetadataCollection(params object[] items) /// 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 @@ public T GetMetadata() where T : class 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 @@ public IReadOnlyList GetOrderedMetadata() where T : class 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 @@ private T[] GetOrderedMetadataSlow() where T : class /// /// 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 @@ internal Enumerator(EndpointMetadataCollection collection) /// /// 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 ff0762bb2050..d8c1f1e7dba2 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 @@ public interface IEndpointFeature /// 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 13c433b38747..815a5d6f107c 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.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 @@ public class RouteValueDictionary : IDictionary, IReadOnlyDictio /// /// The items array. /// A new . - public static RouteValueDictionary FromArray(KeyValuePair[] items) + public static RouteValueDictionary FromArray(KeyValuePair[] items) { if (items == null) { @@ -70,7 +71,7 @@ public static RouteValueDictionary FromArray(KeyValuePair[] item return new RouteValueDictionary() { - _arrayStorage = items, + _arrayStorage = items!, _count = start, }; } @@ -80,7 +81,7 @@ public static RouteValueDictionary FromArray(KeyValuePair[] item /// public RouteValueDictionary() { - _arrayStorage = Array.Empty>(); + _arrayStorage = Array.Empty>(); } /// @@ -96,7 +97,7 @@ public RouteValueDictionary() /// 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 @@ public RouteValueDictionary(object values) // PropertyStorage is immutable so we can just copy it. _propertyStorage = dictionary._propertyStorage; _count = dictionary._count; + _arrayStorage = Array.Empty>(); return; } @@ -112,14 +114,14 @@ public RouteValueDictionary(object values) 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 @@ public RouteValueDictionary(object values) if (values is IEnumerable> keyValueEnumerable) { - _arrayStorage = Array.Empty>(); + _arrayStorage = Array.Empty>(); foreach (var kvp in keyValueEnumerable) { @@ -139,7 +141,7 @@ public RouteValueDictionary(object values) if (values is IEnumerable> stringValueEnumerable) { - _arrayStorage = Array.Empty>(); + _arrayStorage = Array.Empty>(); foreach (var kvp in stringValueEnumerable) { @@ -154,15 +156,16 @@ public RouteValueDictionary(object values) 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 @@ public object this[string key] ThrowArgumentNullExceptionForKey(); } - object value; - TryGetValue(key, out value); + TryGetValue(key, out var value); return value; } @@ -192,11 +194,11 @@ public object this[string key] 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 @@ public object this[string key] public int Count => _count; /// - bool ICollection>.IsReadOnly => false; + bool ICollection>.IsReadOnly => false; /// public ICollection Keys @@ -233,17 +235,17 @@ public ICollection Keys } } - 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 @@ public ICollection Values } } - 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 @@ public void Add(string key, object value) throw new ArgumentException(message, nameof(key)); } - _arrayStorage[_count] = new KeyValuePair(key, value); + _arrayStorage[_count] = new KeyValuePair(key, value); _count++; } @@ -291,7 +293,7 @@ public void Clear() if (_propertyStorage != null) { - _arrayStorage = Array.Empty>(); + _arrayStorage = Array.Empty>(); _propertyStorage = null; _count = 0; return; @@ -302,7 +304,7 @@ public void Clear() } /// - 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 @@ private bool ContainsKeyCore(string key) } /// - void ICollection>.CopyTo( - KeyValuePair[] array, + void ICollection>.CopyTo( + KeyValuePair[] array, int arrayIndex) { if (array == null) @@ -362,7 +364,7 @@ public Enumerator GetEnumerator() } /// - IEnumerator> IEnumerable>.GetEnumerator() + IEnumerator> IEnumerable>.GetEnumerator() { return GetEnumerator(); } @@ -374,13 +376,15 @@ IEnumerator IEnumerable.GetEnumerator() } /// - 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 @@ public bool Remove(string key) /// /// 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 @@ public bool TryAdd(string key, object value) } 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 @@ public bool TryGetValue(string key, out object value) 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 @@ private bool TryGetValueSlow(string key, out object value) return false; } + [DoesNotReturn] private static void ThrowArgumentNullExceptionForKey() { throw new ArgumentNullException("key"); @@ -546,16 +551,16 @@ private void EnsureCapacitySlow(int capacity) 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 @@ private void EnsureCapacitySlow(int capacity) 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 @@ private int FindIndex(string key) } [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 @@ private bool ContainsKeyArray(string key) [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 @@ private bool ContainsKeyProperties(string key) return false; } - public struct Enumerator : IEnumerator> + public struct Enumerator : IEnumerator> { private readonly RouteValueDictionary _dictionary; private int _index; @@ -672,7 +679,7 @@ public Enumerator(RouteValueDictionary dictionary) _index = 0; } - public KeyValuePair Current { get; private set; } + public KeyValuePair Current { get; private set; } object IEnumerator.Current => Current; @@ -699,12 +706,12 @@ public bool MoveNext() 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 @@ public PropertyStorage(object value) // 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 @@ private static void ValidatePropertyNames(Type type, PropertyHelper[] properties } } } -} \ 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 79afefa5c0d4..1fe47d59587d 100644 --- a/src/Http/Http.Abstractions/src/WebSocketManager.cs +++ b/src/Http/Http.Abstractions/src/WebSocketManager.cs @@ -36,6 +36,6 @@ public virtual Task AcceptWebSocketAsync() /// /// 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 a011145becd9..4b5120a5af8b 100644 --- a/src/Http/Http.Abstractions/test/EndpointHttpContextExtensionsTests.cs +++ b/src/Http/Http.Abstractions/test/EndpointHttpContextExtensionsTests.cs @@ -149,7 +149,7 @@ public void SetAndGetEndpoint_Roundtrip_EndpointIsRoundtrip() 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 f9d935b086ef..7131f28bc265 100644 --- a/src/Http/Http.Abstractions/test/MapPathMiddlewareTests.cs +++ b/src/Http/Http.Abstractions/test/MapPathMiddlewareTests.cs @@ -18,7 +18,7 @@ private static Task Success(HttpContext context) 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 @@ public void NullArguments_ArgumentNullException() 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 @@ public async Task PathMatchAction_BranchTaken(string matchPath, string basePath, 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 @@ public async Task PathMatchAction_BranchTaken_WithPreserveMatchedPathSegment(str 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 048d522579c9..1765859e02b3 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 @@ public class MapPredicateMiddlewareTests 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 @@ public void NullArguments_ArgumentNullException() 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 b8bfa1c1c8da..34d82b750157 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 a78a853a1c4c..d4bb0d77d688 100644 --- a/src/Http/Http.Abstractions/test/QueryStringTests.cs +++ b/src/Http/Http.Abstractions/test/QueryStringTests.cs @@ -70,11 +70,11 @@ public void CreateFromList_Success() { 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 ab5925e219e2..8d861b6dff11 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 @@ public void CreateFromRouteValueDictionary_WithArrayStorage_CopiesStorage() 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 @@ public void CreateFromRouteValueDictionary_WithPropertyStorage_CopiesStorage() // Assert Assert.Equal(other, dict); - Assert.Null(dict._arrayStorage); + AssertEmptyArrayStorage(dict); var storage = dict._propertyStorage; var otherStorage = other._propertyStorage; @@ -83,9 +83,9 @@ public static IEnumerable IEnumerableKeyValuePairData { 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 @@ public void CreateFromIEnumerableKeyValuePair_CopiesValues(object values) 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 @@ public void CreateFromIEnumerableStringValuePair_CopiesValues(object values) 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 @@ public void CreateFromIEnumerableStringValuePair_CopiesValues(object values) 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 @@ public void CreateFromObject_CopiesPropertiesFromRegularType_IgnoresStatic() // Assert Assert.NotNull(dict._propertyStorage); - Assert.Null(dict._arrayStorage); + AssertEmptyArrayStorage(dict); Assert.Empty(dict); } @@ -277,7 +277,7 @@ public void CreateFromObject_CopiesPropertiesFromRegularType_IgnoresSetOnly() // Assert Assert.NotNull(dict._propertyStorage); - Assert.Null(dict._arrayStorage); + AssertEmptyArrayStorage(dict); Assert.Empty(dict); } @@ -292,7 +292,7 @@ public void CreateFromObject_CopiesPropertiesFromRegularType_IncludesInherited() // Assert Assert.NotNull(dict._propertyStorage); - Assert.Null(dict._arrayStorage); + AssertEmptyArrayStorage(dict); Assert.Collection( dict.OrderBy(kvp => kvp.Key), kvp => @@ -320,7 +320,7 @@ public void CreateFromObject_CopiesPropertiesFromRegularType_WithHiddenProperty( // 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 @@ public void CreateFromObject_CopiesPropertiesFromRegularType_WithIndexerProperty // Assert Assert.NotNull(dict._propertyStorage); - Assert.Null(dict._arrayStorage); + AssertEmptyArrayStorage(dict); Assert.Empty(dict); } @@ -382,7 +382,7 @@ public void IsReadOnly_False() var dict = new RouteValueDictionary(); // Act - var result = ((ICollection>)dict).IsReadOnly; + var result = ((ICollection>)dict).IsReadOnly; // Assert Assert.False(result); @@ -470,7 +470,7 @@ public void IndexGet_ArrayStorage_NoMatch_ReturnsNull() // Assert Assert.Null(value); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -487,7 +487,7 @@ public void IndexGet_ListStorage_Match_ReturnsValue() // Assert Assert.Equal("value", value); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -504,7 +504,7 @@ public void IndexGet_ListStorage_MatchIgnoreCase_ReturnsValue() // Assert Assert.Equal("value", value); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -531,7 +531,7 @@ public void IndexSet_EmptyStorage_UpgradesToList() // 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 @@ public void IndexSet_PropertyStorage_NoMatch_AddsValue() 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 @@ public void IndexSet_PropertyStorage_Match_SetsValue() // 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 @@ public void IndexSet_PropertyStorage_MatchIgnoreCase_SetsValue() // 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 @@ public void IndexSet_ListStorage_NoMatch_AddsValue() 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 @@ public void IndexSet_ListStorage_Match_SetsValue() // 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 @@ public void IndexSet_ListStorage_MatchIgnoreCase_SetsValue() // 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 @@ public void Count_ListStorage() // Assert Assert.Equal(1, count); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -688,7 +688,7 @@ public void Keys_EmptyStorage() // Assert Assert.Empty(keys); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -702,7 +702,7 @@ public void Keys_PropertyStorage() // Assert Assert.Equal(new[] { "key" }, keys); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -719,7 +719,7 @@ public void Keys_ListStorage() // Assert Assert.Equal(new[] { "key" }, keys); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -733,7 +733,7 @@ public void Values_EmptyStorage() // Assert Assert.Empty(values); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -747,7 +747,7 @@ public void Values_PropertyStorage() // Assert Assert.Equal(new object[] { "value" }, values); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -764,7 +764,7 @@ public void Values_ListStorage() // Assert Assert.Equal(new object[] { "value" }, values); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -778,7 +778,7 @@ public void Add_EmptyStorage() // 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 @@ public void Add_PropertyStorage() 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 @@ public void Add_ListStorage() 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 @@ public void Add_DuplicateKey() 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 @@ public void Add_DuplicateKey_CaseInsensitive() 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 @@ public void Add_KeyValuePair() }; // 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 @@ public void Clear_PropertyStorage_AlreadyEmpty() // Assert Assert.Empty(dict); Assert.NotNull(dict._propertyStorage); - Assert.Null(dict._arrayStorage); + AssertEmptyArrayStorage(dict); } [Fact] @@ -958,7 +958,7 @@ public void Clear_ListStorage() // Assert Assert.Empty(dict); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); Assert.Null(dict._propertyStorage); } @@ -971,14 +971,14 @@ public void Contains_ListStorage_KeyValuePair_True() { "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 @@ public void Contains_ListStory_KeyValuePair_True_CaseInsensitive() { "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 @@ public void Contains_ListStorage_KeyValuePair_False() { "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 @@ public void Contains_ListStorage_KeyValuePair_False_ValueComparisonIsDefault() { "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 @@ public void Contains_PropertyStorage_KeyValuePair_True() // 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 @@ public void Contains_PropertyStory_KeyValuePair_True_CaseInsensitive() // 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 @@ public void Contains_PropertyStorage_KeyValuePair_False() // 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 @@ public void Contains_PropertyStorage_KeyValuePair_False_ValueComparisonIsDefault // 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 @@ public void ContainsKey_PropertyStorage_False() // Assert Assert.False(result); Assert.NotNull(dict._propertyStorage); - Assert.Null(dict._arrayStorage); + AssertEmptyArrayStorage(dict); } [Fact] @@ -1173,7 +1173,7 @@ public void ContainsKey_PropertyStorage_True() // Assert Assert.True(result); Assert.NotNull(dict._propertyStorage); - Assert.Null(dict._arrayStorage); + AssertEmptyArrayStorage(dict); } [Fact] @@ -1188,7 +1188,7 @@ public void ContainsKey_PropertyStorage_True_CaseInsensitive() // Assert Assert.True(result); Assert.NotNull(dict._propertyStorage); - Assert.Null(dict._arrayStorage); + AssertEmptyArrayStorage(dict); } [Fact] @@ -1205,7 +1205,7 @@ public void ContainsKey_ListStorage_False() // Assert Assert.False(result); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -1222,7 +1222,7 @@ public void ContainsKey_ListStorage_True() // Assert Assert.True(result); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -1239,7 +1239,7 @@ public void ContainsKey_ListStorage_True_CaseInsensitive() // Assert Assert.True(result); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -1251,20 +1251,20 @@ public void CopyTo() { "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 @@ public void Remove_KeyValuePair_True() { "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 @@ public void Remove_KeyValuePair_True_CaseInsensitive() { "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 @@ public void Remove_KeyValuePair_False() { "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 @@ public void Remove_KeyValuePair_False_ValueComparisonIsDefault() { "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 @@ public void Remove_PropertyStorage_False() // 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 @@ public void Remove_PropertyStorage_True() // Assert Assert.True(result); Assert.Empty(dict); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -1431,7 +1431,7 @@ public void Remove_PropertyStorage_True_CaseInsensitive() // Assert Assert.True(result); Assert.Empty(dict); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -1449,7 +1449,7 @@ public void Remove_ListStorage_False() // 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 @@ public void Remove_ListStorage_True() // Assert Assert.True(result); Assert.Empty(dict); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -1485,7 +1485,7 @@ public void Remove_ListStorage_True_CaseInsensitive() // Assert Assert.True(result); Assert.Empty(dict); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } @@ -1546,7 +1546,7 @@ public void Remove_KeyAndOutValue_PropertyStorage_False() 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 @@ public void Remove_KeyAndOutValue_PropertyStorage_True() Assert.True(result); Assert.Same(value, removedValue); Assert.Empty(dict); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -1580,7 +1580,7 @@ public void Remove_KeyAndOutValue_PropertyStorage_True_CaseInsensitive() Assert.True(result); Assert.Same(value, removedValue); Assert.Empty(dict); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -1599,7 +1599,7 @@ public void Remove_KeyAndOutValue_ListStorage_False() 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 @@ public void Remove_KeyAndOutValue_ListStorage_True() Assert.True(result); Assert.Same(value, removedValue); Assert.Empty(dict); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -1639,7 +1639,7 @@ public void Remove_KeyAndOutValue_ListStorage_True_CaseInsensitive() Assert.True(result); Assert.Same(value, removedValue); Assert.Empty(dict); - Assert.IsType[]>(dict._arrayStorage); + Assert.IsType[]>(dict._arrayStorage); } [Fact] @@ -1664,7 +1664,7 @@ public void Remove_KeyAndOutValue_ListStorage_KeyExists_First() 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 @@ public void Remove_KeyAndOutValue_ListStorage_KeyExists_Middle() 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 @@ public void Remove_KeyAndOutValue_ListStorage_KeyExists_Last() 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 @@ public void TryAdd_PropertyStorage_KeyDoesNotExist_ConvertsPropertyStorageToArra 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 @@ public void TryAdd_PropertyStory_KeyExist_DoesNotConvertPropertyStorageToArraySt // 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 @@ public void TryAdd_EmptyStorage_CanAdd() 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 @@ public void TryAdd_ArrayStorage_CanAdd() 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 @@ public void TryAdd_ArrayStorage_CanAddWithResize() 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 @@ public void TryAdd_ArrayStorage_DoesNotAddWhenKeyIsPresent() 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 @@ public void TryGetValue_EmptyStorage() 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 @@ public void TryGetValue_PropertyStorage_False() 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 @@ public void TryGetValue_PropertyStorage_True() 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 @@ public void TryGetValue_PropertyStorage_True_CaseInsensitive() 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 @@ public void TryGetValue_ListStorage_False() }; // 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 @@ public void TryGetValue_ListStorage_True() }; // 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 @@ public void TryGetValue_ListStorage_True_CaseInsensitive() }; // 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 @@ public void ListStorage_DynamicallyAdjustsCapacity() 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 @@ public void ListStorage_DynamicallyAdjustsCapacity() 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 @@ public void ListStorage_RemoveAt_RearrangesInnerArray() 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 @@ public void ListStorage_RemoveAt_RearrangesInnerArray() 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 @@ public void FromArray_TakesOwnershipOfArray() public void FromArray_EmptyArray() { // Arrange - var array = Array.Empty>(); + var array = Array.Empty>(); // Act var dictionary = RouteValueDictionary.FromArray(array); @@ -2081,16 +2074,16 @@ public void FromArray_EmptyArray() 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 @@ public void FromArray_RemovesGapsInArray() // 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 @@ private class RegularType private class Visibility { - private string PrivateYo { get; set; } + private string? PrivateYo { get; set; } internal int ItsInternalDealWithIt { get; set; } @@ -2167,9 +2165,9 @@ public bool this[string key] 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 749309319f47..71fd2324d945 100644 --- a/src/Http/Http.Abstractions/test/UseMiddlewareTest.cs +++ b/src/Http/Http.Abstractions/test/UseMiddlewareTest.cs @@ -244,10 +244,10 @@ public async Task InvokeAsync(HttpContext context, RequestDelegate next) 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 @@ public void Release(IMiddleware middleware) 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 @@ private class DummyServiceProvider : IServiceProvider 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 @@ public class MiddlewareInjectWithOutAndRefParams { 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 e5f7903bc5d0..f67d23487ff7 100644 --- a/src/Http/Http.Abstractions/test/UsePathBaseExtensionsTests.cs +++ b/src/Http/Http.Abstractions/test/UsePathBaseExtensionsTests.cs @@ -145,8 +145,9 @@ private static async Task TestPathBase(string registeredPathBase, string pathBas 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 901454b62e2f..2173df91384f 100644 --- a/src/Http/Http.Abstractions/test/UseWhenExtensionsTests.cs +++ b/src/Http/Http.Abstractions/test/UseWhenExtensionsTests.cs @@ -18,8 +18,8 @@ public void NullArguments_ArgumentNullException() 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 @@ private static Func, Task> Increment(string key, bool te } } - 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 3009140234cd..af5a85a96018 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 45f7f9d1357a..76eaa034473c 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 @@ public enum SameSiteMode 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 @@ public partial class FeatureCollection : Microsoft.AspNetCore.Http.Features.IFea 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 @@ public partial struct FeatureReferences { 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 @@ public partial struct FeatureReference 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 @@ public enum HttpsCompressionMode 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 45f7f9d1357a..802000e099aa 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 @@ public enum SameSiteMode 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 @@ public partial class FeatureCollection : Microsoft.AspNetCore.Http.Features.IFea 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 @@ public enum HttpsCompressionMode 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 833eeedea2e6..74512d23609a 100644 --- a/src/Http/Http.Features/src/CookieOptions.cs +++ b/src/Http/Http.Features/src/CookieOptions.cs @@ -22,13 +22,13 @@ public CookieOptions() /// 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 e79ecfee224a..b5f70b7c4e8f 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 @@ public virtual int Revision public bool IsReadOnly { get { return false; } } - public object this[Type key] + public object? this[Type key] { get { @@ -40,7 +41,7 @@ public object this[Type key] 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 @@ public IEnumerator> GetEnumerator() } } + [return: MaybeNull] public TFeature Get() { return (TFeature)this[typeof(TFeature)]; @@ -116,4 +118,4 @@ public int GetHashCode(KeyValuePair obj) } } } -} \ 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 501660212310..516fb70e909e 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 @@ private FeatureReference(T feature, int revision) _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 @@ public T Update(IFeatureCollection features, T feature) 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 f19938bfe98a..fa32c413471e 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 @@ public void Initalize(IFeatureCollection collection, int revision) // 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 @@ public void Initalize(IFeatureCollection collection, int revision) // 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 @@ public TFeature Fetch( 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 @@ private TFeature UpdateCached(ref TFeature cached, TState stat 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 f7b23ed16f25..6d087df337d7 100644 --- a/src/Http/Http.Features/src/IFeatureCollection.cs +++ b/src/Http/Http.Features/src/IFeatureCollection.cs @@ -26,7 +26,7 @@ public interface IFeatureCollection : IEnumerable> /// /// /// 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 85f9fdc84731..0b7b768ca73b 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 5e3659d64784..beb7e0a59d67 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 36ad77f67857..a09ad7cedfb4 100644 --- a/src/Http/Http.Features/test/FeatureCollectionTests.cs +++ b/src/Http/Http.Features/test/FeatureCollectionTests.cs @@ -15,7 +15,7 @@ public void AddedInterfaceIsReturned() interfaces[typeof(IThing)] = thing; - object thing2 = interfaces[typeof(IThing)]; + var thing2 = interfaces[typeof(IThing)]; Assert.Equal(thing2, thing); } @@ -41,7 +41,7 @@ public void SetNullValueRemoves() 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 1a041d50b7b8..44552938d5c7 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 ed6962230f56..4cadeb67894d 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 @@ public FormCollection(System.Collections.Generic.Dictionary 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 @@ public HeaderDictionary(int capacity) { } 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 @@ public void CopyTo(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 @@ public QueryCollection(int capacity) { } 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 e2595c4f40e9..8c2474ef3d98 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 75a5dfb139e0..76bdd78a7c2b 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 effddb3203aa..97888d8eecf2 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 @@ public partial interface IAllowAnonymous } 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 effddb3203aa..97888d8eecf2 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 @@ public partial interface IAllowAnonymous } 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 1196db82d4f4..3aa738bf0009 100644 --- a/src/Http/Metadata/src/IAuthorizeData.cs +++ b/src/Http/Metadata/src/IAuthorizeData.cs @@ -11,16 +11,16 @@ public interface IAuthorizeData /// /// 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 7869ec0eb52b..0a760c3f291b 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 f4cfdfddb891..92bfe8bb84c8 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 6aea07474a9f..12862c2b4d91 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 @@ public partial interface IRoutingFeature 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 @@ public LinkOptions() { } 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 @@ public enum RouteDirection 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 add5eaf1192c..90a28ea96650 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 @@ public abstract string GetPathByAddress( 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 @@ public abstract string GetPathByAddress( 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 @@ public abstract string GetUriByAddress( 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 @@ public abstract string GetUriByAddress( 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 c500cb5ba7d6..01a9d0738243 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 7162446e7d67..21b8d7e0c2ba 100644 --- a/src/Http/Routing.Abstractions/src/RouteContext.cs +++ b/src/Http/Routing.Abstractions/src/RouteContext.cs @@ -19,7 +19,7 @@ public class RouteContext /// 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 @@ public RouteContext(HttpContext httpContext) /// 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 a13571bdb875..89fcf0ad2d66 100644 --- a/src/Http/Routing.Abstractions/src/RoutingHttpContextExtensions.cs +++ b/src/Http/Routing.Abstractions/src/RoutingHttpContextExtensions.cs @@ -35,7 +35,7 @@ public static RouteData GetRouteData(this HttpContext httpContext) /// 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 88f899e925c9..a1483d1b9b34 100644 --- a/src/Http/Routing.Abstractions/src/VirtualPathContext.cs +++ b/src/Http/Routing.Abstractions/src/VirtualPathContext.cs @@ -35,7 +35,7 @@ public VirtualPathContext( HttpContext httpContext, RouteValueDictionary ambientValues, RouteValueDictionary values, - string routeName) + string? routeName) { HttpContext = httpContext; AmbientValues = ambientValues; @@ -56,7 +56,7 @@ public VirtualPathContext( /// /// 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 750e814c6933..de1041504eda 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 52fd97828ad1..7652fc21d2a2 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 262c012733c2..ef53667e23ef 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 75ed809b6d97..5e5e0a6ec142 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 @@ public abstract partial class BaseConnectionContext : System.IAsyncDisposable { 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 @@ public static partial class ConnectionBuilderExtensions 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 @@ public abstract partial class ConnectionHandler 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 @@ public partial class DefaultConnectionContext : 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 @@ public partial interface IMultiplexedConnectionBuilder } 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 @@ public abstract partial class MultiplexedConnectionContext : Microsoft.AspNetCor { 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 @@ public partial interface IConnectionCompleteFeature } 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 @@ public partial interface IConnectionHeartbeatFeature } public partial interface IConnectionIdFeature { - string ConnectionId { get; set; } + string? ConnectionId { get; set; } } public partial interface IConnectionInherentKeepAliveFeature { @@ -201,7 +201,7 @@ public partial interface IConnectionInherentKeepAliveFeature } 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 @@ public partial interface IConnectionLifetimeNotificationFeature } 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 75ed809b6d97..5e5e0a6ec142 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 @@ public abstract partial class BaseConnectionContext : System.IAsyncDisposable { 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 @@ public static partial class ConnectionBuilderExtensions 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 @@ public abstract partial class ConnectionHandler 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 @@ public partial class DefaultConnectionContext : 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 @@ public partial interface IMultiplexedConnectionBuilder } 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 @@ public abstract partial class MultiplexedConnectionContext : Microsoft.AspNetCor { 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 @@ public partial interface IConnectionCompleteFeature } 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 @@ public partial interface IConnectionHeartbeatFeature } public partial interface IConnectionIdFeature { - string ConnectionId { get; set; } + string? ConnectionId { get; set; } } public partial interface IConnectionInherentKeepAliveFeature { @@ -201,7 +201,7 @@ public partial interface IConnectionInherentKeepAliveFeature } 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 @@ public partial interface IConnectionLifetimeNotificationFeature } 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 75ed809b6d97..5e5e0a6ec142 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 @@ public abstract partial class BaseConnectionContext : System.IAsyncDisposable { 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 @@ public static partial class ConnectionBuilderExtensions 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 @@ public abstract partial class ConnectionHandler 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 @@ public partial class DefaultConnectionContext : 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 @@ public partial interface IMultiplexedConnectionBuilder } 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 @@ public abstract partial class MultiplexedConnectionContext : Microsoft.AspNetCor { 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 @@ public partial interface IConnectionCompleteFeature } 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 @@ public partial interface IConnectionHeartbeatFeature } public partial interface IConnectionIdFeature { - string ConnectionId { get; set; } + string? ConnectionId { get; set; } } public partial interface IConnectionInherentKeepAliveFeature { @@ -201,7 +201,7 @@ public partial interface IConnectionInherentKeepAliveFeature } 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 @@ public partial interface IConnectionLifetimeNotificationFeature } 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 662b8c902e9b..dcaf110cdeca 100644 --- a/src/Servers/Connections.Abstractions/src/BaseConnectionContext.cs +++ b/src/Servers/Connections.Abstractions/src/BaseConnectionContext.cs @@ -15,7 +15,7 @@ public abstract class BaseConnectionContext : IAsyncDisposable /// /// 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 @@ public abstract class BaseConnectionContext : IAsyncDisposable /// /// 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 @@ public abstract class BaseConnectionContext : IAsyncDisposable /// /// 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 02b291c2c816..ffd4136ef894 100644 --- a/src/Servers/Connections.Abstractions/src/ConnectionContext.cs +++ b/src/Servers/Connections.Abstractions/src/ConnectionContext.cs @@ -15,7 +15,7 @@ public abstract class ConnectionContext : BaseConnectionContext, IAsyncDisposabl /// /// 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 f5c7dd0352d4..5d9ef2cdb89f 100644 --- a/src/Servers/Connections.Abstractions/src/ConnectionItems.cs +++ b/src/Servers/Connections.Abstractions/src/ConnectionItems.cs @@ -6,22 +6,22 @@ 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 @@ object IDictionary.this[object key] 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 @@ bool ICollection>.Remove(KeyValuePair> 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 870fc4548f6e..ce3d115e2a95 100644 --- a/src/Servers/Connections.Abstractions/src/DefaultConnectionContext.cs +++ b/src/Servers/Connections.Abstractions/src/DefaultConnectionContext.cs @@ -54,25 +54,25 @@ public DefaultConnectionContext(string id, IDuplexPipe transport, IDuplexPipe ap 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 7c44146ede79..6b51aa3a390d 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 2fa7ebbadf81..8068e0cd6c4d 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 3d40d5498f53..e0e8e4370338 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 0b218972d70c..7f4fd4f9d623 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 7698693a54e0..8e082af24a8a 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 d867fe0938de..9173dc4e5a0e 100644 --- a/src/Servers/Connections.Abstractions/src/IMulitplexedConnectionListener.cs +++ b/src/Servers/Connections.Abstractions/src/IMulitplexedConnectionListener.cs @@ -32,6 +32,6 @@ public interface IMultiplexedConnectionListener : IAsyncDisposable /// 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 a3f69f7a6854..1b11aa57ad5c 100644 --- a/src/Servers/Connections.Abstractions/src/IMultiplexedConnectionFactory.cs +++ b/src/Servers/Connections.Abstractions/src/IMultiplexedConnectionFactory.cs @@ -22,6 +22,6 @@ public interface IMultiplexedConnectionFactory /// /// 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 3b5010beda33..ee3e593b9d67 100644 --- a/src/Servers/Connections.Abstractions/src/IMultiplexedConnectionListenerFactory.cs +++ b/src/Servers/Connections.Abstractions/src/IMultiplexedConnectionListenerFactory.cs @@ -20,6 +20,6 @@ public interface IMultiplexedConnectionListenerFactory /// 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 ddefc4f62c57..fcea39596454 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 ce0850d2816f..27ca5444de82 100644 --- a/src/Servers/Connections.Abstractions/src/MultiplexedConnectionContext.cs +++ b/src/Servers/Connections.Abstractions/src/MultiplexedConnectionContext.cs @@ -26,6 +26,6 @@ public abstract class MultiplexedConnectionContext : BaseConnectionContext, IAsy /// /// /// - 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 4d05ebf58967..26eb81f4325a 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 @@ private static MethodInfo GetMethodInfo(Expression expr) 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 @@ private static void FindApplicableConstructor( 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 dc635bb78997..ae0710d3fc1d 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 @@ internal class ParameterDefaultValue { 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 334983326438..5a2d787ad7ea 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 @@ internal class PropertyHelper 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 @@ internal class PropertyHelper // 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 @@ private static Func MakeFastPropertyGetter( // 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 @@ private static Func MakeFastPropertyGetter( 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 @@ private static Func MakeFastPropertyGetter( 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 @@ public static Action MakeFastPropertySetter(PropertyInfo propert // 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 @@ private static PropertyHelper CreateInstance(PropertyInfo property) } // Called via reflection - private static object CallPropertyGetter( + private static object? CallPropertyGetter( Func getter, object target) { @@ -365,7 +367,7 @@ private static object CallPropertyGetter( } // Called via reflection - private static object CallPropertyGetterByReference( + private static object? CallPropertyGetterByReference( ByRefFunc getter, object target) { @@ -374,7 +376,7 @@ private static object CallPropertyGetterByReference( } // Called via reflection - private static object CallNullSafePropertyGetter( + private static object? CallNullSafePropertyGetter( Func getter, object target) { @@ -387,7 +389,7 @@ private static object CallNullSafePropertyGetter( } // Called via reflection - private static object CallNullSafePropertyGetterByReference( + private static object? CallNullSafePropertyGetterByReference( ByRefFunc getter, object target) { @@ -455,8 +457,8 @@ protected static PropertyHelper[] GetVisibleProperties( // 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 @@ private static bool IsInterestingProperty(PropertyInfo property) 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 c1db74970e9c..b80599128b5b 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 From eddd483a9bbbf331d8a2c459a7062f95f47d51bb Mon Sep 17 00:00:00 2001 From: Pranav K Date: Wed, 3 Jun 2020 15:59:12 -0700 Subject: [PATCH 2/3] More nullables --- .../Microsoft.Net.Http.Headers.netcoreapp.cs | 36 +++++++++---------- .../Headers/src/CacheControlHeaderValue.cs | 7 ++-- src/Http/Headers/src/CookieHeaderValue.cs | 13 ++++--- src/Http/Headers/src/MediaTypeHeaderValue.cs | 2 +- src/Http/Headers/src/NameValueHeaderValue.cs | 10 +++--- src/Http/Headers/src/SetCookieHeaderValue.cs | 8 ++--- .../src/StringWithQualityHeaderValue.cs | 8 ++--- 7 files changed, 41 insertions(+), 43 deletions(-) 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 ea797363e3f5..784b8179bae0 100644 --- a/src/Http/Headers/ref/Microsoft.Net.Http.Headers.netcoreapp.cs +++ b/src/Http/Headers/ref/Microsoft.Net.Http.Headers.netcoreapp.cs @@ -38,7 +38,7 @@ public CacheControlHeaderValue() { } 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 { @@ -91,12 +91,12 @@ public CookieHeaderValue(Microsoft.Extensions.Primitives.StringSegment name, Mic 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, [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 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 { @@ -252,7 +252,7 @@ public MediaTypeHeaderValue(Microsoft.Extensions.Primitives.StringSegment mediaT public override string ToString() { 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 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 { @@ -274,13 +274,13 @@ public NameValueHeaderValue(Microsoft.Extensions.Primitives.StringSegment name, 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, [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 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 { @@ -340,12 +340,12 @@ public void AppendToStringBuilder(System.Text.StringBuilder builder) { } 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, [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 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 { @@ -356,12 +356,12 @@ public StringWithQualityHeaderValue(Microsoft.Extensions.Primitives.StringSegmen 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, [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 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 { diff --git a/src/Http/Headers/src/CacheControlHeaderValue.cs b/src/Http/Headers/src/CacheControlHeaderValue.cs index 16dab420fda1..14a59b242200 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; @@ -325,7 +326,7 @@ public override int GetHashCode() 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 @@ public static CacheControlHeaderValue Parse(StringSegment input) 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) { diff --git a/src/Http/Headers/src/CookieHeaderValue.cs b/src/Http/Headers/src/CookieHeaderValue.cs index e7c306b61d1d..d92fcc6f8339 100644 --- a/src/Http/Headers/src/CookieHeaderValue.cs +++ b/src/Http/Headers/src/CookieHeaderValue.cs @@ -87,34 +87,34 @@ public static CookieHeaderValue Parse(StringSegment input) return SingleValueParser.ParseValue(input, ref index)!; } - public static bool TryParse(StringSegment input, [NotNullWhen(true)]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!); } - 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, [NotNullWhen(true)]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, [NotNullWhen(true)]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, [NotNullWhen(true)]out CookieHeaderValue? parsedValue) + internal static bool TryGetCookieLength(StringSegment input, ref int offset, [NotNullWhen(true)] out CookieHeaderValue? parsedValue) { Contract.Requires(offset >= 0); @@ -159,7 +159,6 @@ internal static bool TryGetCookieLength(StringSegment input, ref int offset, [No // ; 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))); diff --git a/src/Http/Headers/src/MediaTypeHeaderValue.cs b/src/Http/Headers/src/MediaTypeHeaderValue.cs index 1162440e004b..0f6cf46287fa 100644 --- a/src/Http/Headers/src/MediaTypeHeaderValue.cs +++ b/src/Http/Headers/src/MediaTypeHeaderValue.cs @@ -525,7 +525,7 @@ public static bool TryParseList(IList? inputs, [NotNullWhen(true)] out I /// A list of media types /// The parsed . /// True if the value was successfully parsed. - public static bool TryParseStrictList(IList inputs, [NotNullWhen(true)] out IList? parsedValues) + public static bool TryParseStrictList(IList? inputs, [NotNullWhen(true)] out IList? parsedValues) { return MultipleValueParser.TryParseStrictValues(inputs, out parsedValues); } diff --git a/src/Http/Headers/src/NameValueHeaderValue.cs b/src/Http/Headers/src/NameValueHeaderValue.cs index bcb57684c47d..9ef6283cd9b0 100644 --- a/src/Http/Headers/src/NameValueHeaderValue.cs +++ b/src/Http/Headers/src/NameValueHeaderValue.cs @@ -178,22 +178,22 @@ public static bool TryParse(StringSegment input, [NotNullWhen(true)] out NameVal 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, [NotNullWhen(true)] 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, [NotNullWhen(true)] out IList? parsedValues) + public static bool TryParseStrictList(IList? input, [NotNullWhen(true)] out IList? parsedValues) { return MultipleValueParser.TryParseStrictValues(input, out parsedValues); } @@ -379,8 +379,6 @@ internal static int GetNameValueListLength( 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/SetCookieHeaderValue.cs b/src/Http/Headers/src/SetCookieHeaderValue.cs index 092c4bc43db7..5e7c28564e79 100644 --- a/src/Http/Headers/src/SetCookieHeaderValue.cs +++ b/src/Http/Headers/src/SetCookieHeaderValue.cs @@ -306,22 +306,22 @@ public static bool TryParse(StringSegment input, [NotNullWhen(true)] out SetCook 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, [NotNullWhen(true)] 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, [NotNullWhen(true)] out IList? parsedValues) + public static bool TryParseStrictList(IList? inputs, [NotNullWhen(true)] out IList? parsedValues) { return MultipleValueParser.TryParseStrictValues(inputs, out parsedValues); } diff --git a/src/Http/Headers/src/StringWithQualityHeaderValue.cs b/src/Http/Headers/src/StringWithQualityHeaderValue.cs index 66ce2a1eefab..18fe33975c16 100644 --- a/src/Http/Headers/src/StringWithQualityHeaderValue.cs +++ b/src/Http/Headers/src/StringWithQualityHeaderValue.cs @@ -116,22 +116,22 @@ public static bool TryParse(StringSegment input, [NotNullWhen(true)] out StringW 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, [NotNullWhen(true)] 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, [NotNullWhen(true)] out IList? parsedValues) + public static bool TryParseStrictList(IList? input, [NotNullWhen(true)] out IList? parsedValues) { return MultipleValueParser.TryParseStrictValues(input, out parsedValues); } From 33a727fbab04ad936024310342c5fd0c63424dbd Mon Sep 17 00:00:00 2001 From: Pranav K Date: Thu, 4 Jun 2020 06:42:11 -0700 Subject: [PATCH 3/3] Fixups --- .../Headers/ref/Microsoft.Net.Http.Headers.netcoreapp.cs | 6 +++--- src/Http/Headers/src/ContentDispositionHeaderValue.cs | 7 +++---- src/Http/Headers/src/ContentRangeHeaderValue.cs | 2 +- src/Http/Headers/src/CookieHeaderParser.cs | 6 ++---- src/Http/Headers/src/EntityTagHeaderValue.cs | 2 +- src/Http/Headers/src/HeaderUtilities.cs | 2 +- src/Http/Headers/src/MediaTypeHeaderValue.cs | 2 +- 7 files changed, 12 insertions(+), 15 deletions(-) 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 784b8179bae0..ff176b7f4ea4 100644 --- a/src/Http/Headers/ref/Microsoft.Net.Http.Headers.netcoreapp.cs +++ b/src/Http/Headers/ref/Microsoft.Net.Http.Headers.netcoreapp.cs @@ -80,7 +80,7 @@ public ContentRangeHeaderValue(long from, long to, long length) { } 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 { @@ -112,7 +112,7 @@ public EntityTagHeaderValue(Microsoft.Extensions.Primitives.StringSegment tag, b 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 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; } } @@ -250,7 +250,7 @@ public MediaTypeHeaderValue(Microsoft.Extensions.Primitives.StringSegment mediaT 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, [System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] out Microsoft.Net.Http.Headers.MediaTypeHeaderValue parsedValue) { 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; } } diff --git a/src/Http/Headers/src/ContentDispositionHeaderValue.cs b/src/Http/Headers/src/ContentDispositionHeaderValue.cs index be5027e693c0..3e629d10cbf1 100644 --- a/src/Http/Headers/src/ContentDispositionHeaderValue.cs +++ b/src/Http/Headers/src/ContentDispositionHeaderValue.cs @@ -110,11 +110,10 @@ public long? Size 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; } @@ -142,8 +141,8 @@ public long? Size } 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)); } } } diff --git a/src/Http/Headers/src/ContentRangeHeaderValue.cs b/src/Http/Headers/src/ContentRangeHeaderValue.cs index 4226ea9f837e..1c9a7a55b755 100644 --- a/src/Http/Headers/src/ContentRangeHeaderValue.cs +++ b/src/Http/Headers/src/ContentRangeHeaderValue.cs @@ -180,7 +180,7 @@ public static ContentRangeHeaderValue Parse(StringSegment input) 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!); diff --git a/src/Http/Headers/src/CookieHeaderParser.cs b/src/Http/Headers/src/CookieHeaderParser.cs index 9f7e59e89348..b77263bc18f7 100644 --- a/src/Http/Headers/src/CookieHeaderParser.cs +++ b/src/Http/Headers/src/CookieHeaderParser.cs @@ -1,7 +1,6 @@ // 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 System.Diagnostics.Contracts; using Microsoft.Extensions.Primitives; @@ -14,7 +13,7 @@ internal CookieHeaderParser(bool supportsMultipleValues) { } - public override bool TryParseValue(StringSegment value, ref int index, [MaybeNull] out CookieHeaderValue? parsedValue) + public override bool TryParseValue(StringSegment value, ref int index, out CookieHeaderValue? parsedValue) { parsedValue = null; @@ -44,8 +43,7 @@ public override bool TryParseValue(StringSegment value, ref int index, [MaybeNul return SupportsMultipleValues; } - CookieHeaderValue? result = null; - if (!CookieHeaderValue.TryGetCookieLength(value, ref current, out result)) + if (!CookieHeaderValue.TryGetCookieLength(value, ref current, out var result)) { return false; } diff --git a/src/Http/Headers/src/EntityTagHeaderValue.cs b/src/Http/Headers/src/EntityTagHeaderValue.cs index 7e44c79a44f5..a468eeb5dcff 100644 --- a/src/Http/Headers/src/EntityTagHeaderValue.cs +++ b/src/Http/Headers/src/EntityTagHeaderValue.cs @@ -155,7 +155,7 @@ public static EntityTagHeaderValue Parse(StringSegment input) 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!); diff --git a/src/Http/Headers/src/HeaderUtilities.cs b/src/Http/Headers/src/HeaderUtilities.cs index 735592844815..75be781c1609 100644 --- a/src/Http/Headers/src/HeaderUtilities.cs +++ b/src/Http/Headers/src/HeaderUtilities.cs @@ -47,7 +47,7 @@ internal static void SetQuality(IList parameters, double? // Remove quality parameter if (qualityParameter != null) { - parameters!.Remove(qualityParameter); + parameters.Remove(qualityParameter); } } } diff --git a/src/Http/Headers/src/MediaTypeHeaderValue.cs b/src/Http/Headers/src/MediaTypeHeaderValue.cs index 0f6cf46287fa..df3d96c0cf2c 100644 --- a/src/Http/Headers/src/MediaTypeHeaderValue.cs +++ b/src/Http/Headers/src/MediaTypeHeaderValue.cs @@ -481,7 +481,7 @@ public static MediaTypeHeaderValue Parse(StringSegment input) /// 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, [NotNullWhen(true)] 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!);