Skip to content

Commit 8efcca4

Browse files
authored
Annotate Microsoft.AspNetCore.Http with nullable attributes (#22928)
* Annotate Microsoft.AspNetCore.Http with nullable attributes * Annotate Hosting with nullable
1 parent c93b611 commit 8efcca4

File tree

63 files changed

+306
-295
lines changed

Some content is hidden

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

63 files changed

+306
-295
lines changed

src/Hosting/Abstractions/ref/Microsoft.AspNetCore.Hosting.Abstractions.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<Project Sdk="Microsoft.NET.Sdk">
33
<PropertyGroup>
44
<TargetFrameworks>$(DefaultNetCoreTargetFramework)</TargetFrameworks>
5+
<Nullable>annotations</Nullable>
56
</PropertyGroup>
67
<ItemGroup Condition="'$(TargetFramework)' == '$(DefaultNetCoreTargetFramework)'">
78
<Compile Include="Microsoft.AspNetCore.Hosting.Abstractions.netcoreapp.cs" />

src/Hosting/Abstractions/ref/Microsoft.AspNetCore.Hosting.Abstractions.netcoreapp.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ public partial interface IWebHostBuilder
9393
Microsoft.AspNetCore.Hosting.IWebHostBuilder ConfigureAppConfiguration(System.Action<Microsoft.AspNetCore.Hosting.WebHostBuilderContext, Microsoft.Extensions.Configuration.IConfigurationBuilder> configureDelegate);
9494
Microsoft.AspNetCore.Hosting.IWebHostBuilder ConfigureServices(System.Action<Microsoft.AspNetCore.Hosting.WebHostBuilderContext, Microsoft.Extensions.DependencyInjection.IServiceCollection> configureServices);
9595
Microsoft.AspNetCore.Hosting.IWebHostBuilder ConfigureServices(System.Action<Microsoft.Extensions.DependencyInjection.IServiceCollection> configureServices);
96-
string GetSetting(string key);
97-
Microsoft.AspNetCore.Hosting.IWebHostBuilder UseSetting(string key, string value);
96+
string? GetSetting(string key);
97+
Microsoft.AspNetCore.Hosting.IWebHostBuilder UseSetting(string key, string? value);
9898
}
9999
public partial interface IWebHostEnvironment : Microsoft.Extensions.Hosting.IHostEnvironment
100100
{

src/Hosting/Abstractions/src/IWebHostBuilder.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ public interface IWebHostBuilder
5050
/// </summary>
5151
/// <param name="key">The key of the setting to look up.</param>
5252
/// <returns>The value the setting currently contains.</returns>
53-
string GetSetting(string key);
53+
string? GetSetting(string key);
5454

5555
/// <summary>
5656
/// Add or replace a setting in the configuration.
5757
/// </summary>
5858
/// <param name="key">The key of the setting to add or replace.</param>
5959
/// <param name="value">The value of the setting to add or replace.</param>
6060
/// <returns>The <see cref="IWebHostBuilder"/>.</returns>
61-
IWebHostBuilder UseSetting(string key, string value);
61+
IWebHostBuilder UseSetting(string key, string? value);
6262
}
63-
}
63+
}

src/Hosting/Abstractions/src/Microsoft.AspNetCore.Hosting.Abstractions.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<GenerateDocumentationFile>true</GenerateDocumentationFile>
99
<PackageTags>aspnetcore;hosting</PackageTags>
1010
<IsPackable>false</IsPackable>
11+
<Nullable>enable</Nullable>
1112
</PropertyGroup>
1213

1314
<ItemGroup>

src/Hosting/Abstractions/src/WebHostBuilderContext.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ public class WebHostBuilderContext
1313
/// <summary>
1414
/// The <see cref="IWebHostEnvironment" /> initialized by the <see cref="IWebHost" />.
1515
/// </summary>
16-
public IWebHostEnvironment HostingEnvironment { get; set; }
16+
public IWebHostEnvironment HostingEnvironment { get; set; } = default!;
1717

1818
/// <summary>
1919
/// The <see cref="IConfiguration" /> containing the merged configuration of the application and the <see cref="IWebHost" />.
2020
/// </summary>
21-
public IConfiguration Configuration { get; set; }
21+
public IConfiguration Configuration { get; set; } = default!;
2222
}
2323
}

src/Http/Http.Abstractions/ref/Microsoft.AspNetCore.Http.Abstractions.netcoreapp.cs

+7-7
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ protected EndpointBuilder() { }
1414
public partial interface IApplicationBuilder
1515
{
1616
System.IServiceProvider ApplicationServices { get; set; }
17-
System.Collections.Generic.IDictionary<string, object> Properties { get; }
17+
System.Collections.Generic.IDictionary<string, object?> Properties { get; }
1818
Microsoft.AspNetCore.Http.Features.IFeatureCollection ServerFeatures { get; }
1919
Microsoft.AspNetCore.Http.RequestDelegate Build();
2020
Microsoft.AspNetCore.Builder.IApplicationBuilder New();
@@ -108,13 +108,13 @@ public BadHttpRequestException(string message, int statusCode, System.Exception
108108
public abstract partial class ConnectionInfo
109109
{
110110
protected ConnectionInfo() { }
111-
public abstract System.Security.Cryptography.X509Certificates.X509Certificate2 ClientCertificate { get; set; }
111+
public abstract System.Security.Cryptography.X509Certificates.X509Certificate2? ClientCertificate { get; set; }
112112
public abstract string Id { get; set; }
113-
public abstract System.Net.IPAddress LocalIpAddress { get; set; }
113+
public abstract System.Net.IPAddress? LocalIpAddress { get; set; }
114114
public abstract int LocalPort { get; set; }
115-
public abstract System.Net.IPAddress RemoteIpAddress { get; set; }
115+
public abstract System.Net.IPAddress? RemoteIpAddress { get; set; }
116116
public abstract int RemotePort { get; set; }
117-
public abstract System.Threading.Tasks.Task<System.Security.Cryptography.X509Certificates.X509Certificate2> GetClientCertificateAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken));
117+
public abstract System.Threading.Tasks.Task<System.Security.Cryptography.X509Certificates.X509Certificate2?> GetClientCertificateAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken));
118118
}
119119
public partial class CookieBuilder
120120
{
@@ -231,7 +231,7 @@ protected HttpContext() { }
231231
public abstract System.Threading.CancellationToken RequestAborted { get; set; }
232232
public abstract System.IServiceProvider RequestServices { get; set; }
233233
public abstract Microsoft.AspNetCore.Http.HttpResponse Response { get; }
234-
public abstract Microsoft.AspNetCore.Http.ISession? Session { get; set; }
234+
public abstract Microsoft.AspNetCore.Http.ISession Session { get; set; }
235235
public abstract string TraceIdentifier { get; set; }
236236
public abstract System.Security.Claims.ClaimsPrincipal User { get; set; }
237237
public abstract Microsoft.AspNetCore.Http.WebSocketManager WebSockets { get; }
@@ -326,7 +326,7 @@ public static partial class HttpResponseWritingExtensions
326326
}
327327
public partial interface IHttpContextAccessor
328328
{
329-
Microsoft.AspNetCore.Http.HttpContext HttpContext { get; set; }
329+
Microsoft.AspNetCore.Http.HttpContext? HttpContext { get; set; }
330330
}
331331
public partial interface IHttpContextFactory
332332
{

src/Http/Http.Abstractions/src/ConnectionInfo.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ public abstract class ConnectionInfo
1515
/// </summary>
1616
public abstract string Id { get; set; }
1717

18-
public abstract IPAddress RemoteIpAddress { get; set; }
18+
public abstract IPAddress? RemoteIpAddress { get; set; }
1919

2020
public abstract int RemotePort { get; set; }
2121

22-
public abstract IPAddress LocalIpAddress { get; set; }
22+
public abstract IPAddress? LocalIpAddress { get; set; }
2323

2424
public abstract int LocalPort { get; set; }
2525

26-
public abstract X509Certificate2 ClientCertificate { get; set; }
26+
public abstract X509Certificate2? ClientCertificate { get; set; }
2727

28-
public abstract Task<X509Certificate2> GetClientCertificateAsync(CancellationToken cancellationToken = new CancellationToken());
28+
public abstract Task<X509Certificate2?> GetClientCertificateAsync(CancellationToken cancellationToken = new CancellationToken());
2929
}
3030
}

src/Http/Http.Abstractions/src/HttpContext.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public abstract class HttpContext
6868
/// <summary>
6969
/// Gets or sets the object used to manage user session data for this request.
7070
/// </summary>
71-
public abstract ISession? Session { get; set; }
71+
public abstract ISession Session { get; set; }
7272

7373
/// <summary>
7474
/// Aborts the connection underlying this request.

src/Http/Http.Abstractions/src/IApplicationBuilder.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public interface IApplicationBuilder
2626
/// <summary>
2727
/// Gets a key/value collection that can be used to share data between middleware.
2828
/// </summary>
29-
IDictionary<string, object> Properties { get; }
29+
IDictionary<string, object?> Properties { get; }
3030

3131
/// <summary>
3232
/// Adds a middleware delegate to the application's request pipeline.

src/Http/Http.Abstractions/src/IHttpContextAccessor.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ public interface IHttpContextAccessor
1515
/// <summary>
1616
/// Gets or sets the current <see cref="HttpContext"/>. Returns <see langword="null" /> if there is no active <see cref="HttpContext" />.
1717
/// </summary>
18-
HttpContext HttpContext { get; set; }
18+
HttpContext? HttpContext { get; set; }
1919
}
2020
}

src/Http/Http.Features/ref/Microsoft.AspNetCore.Http.Features.netcoreapp.cs

+14-14
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ public partial interface IFormFile
3838
}
3939
public partial interface IFormFileCollection : System.Collections.Generic.IEnumerable<Microsoft.AspNetCore.Http.IFormFile>, System.Collections.Generic.IReadOnlyCollection<Microsoft.AspNetCore.Http.IFormFile>, System.Collections.Generic.IReadOnlyList<Microsoft.AspNetCore.Http.IFormFile>, System.Collections.IEnumerable
4040
{
41-
Microsoft.AspNetCore.Http.IFormFile this[string name] { get; }
42-
Microsoft.AspNetCore.Http.IFormFile GetFile(string name);
41+
Microsoft.AspNetCore.Http.IFormFile? this[string name] { get; }
42+
Microsoft.AspNetCore.Http.IFormFile? GetFile(string name);
4343
System.Collections.Generic.IReadOnlyList<Microsoft.AspNetCore.Http.IFormFile> GetFiles(string name);
4444
}
4545
public partial interface IHeaderDictionary : System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<string, Microsoft.Extensions.Primitives.StringValues>>, System.Collections.Generic.IDictionary<string, Microsoft.Extensions.Primitives.StringValues>, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, Microsoft.Extensions.Primitives.StringValues>>, System.Collections.IEnumerable
@@ -58,10 +58,10 @@ public partial interface IQueryCollection : System.Collections.Generic.IEnumerab
5858
public partial interface IRequestCookieCollection : System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, string>>, System.Collections.IEnumerable
5959
{
6060
int Count { get; }
61-
string this[string key] { get; }
61+
string? this[string key] { get; }
6262
System.Collections.Generic.ICollection<string> Keys { get; }
6363
bool ContainsKey(string key);
64-
bool TryGetValue(string key, out string value);
64+
bool TryGetValue(string key, [System.Diagnostics.CodeAnalysis.MaybeNullWhenAttribute(false)] out string? value);
6565
}
6666
public partial interface IResponseCookies
6767
{
@@ -121,8 +121,8 @@ public partial struct FeatureReferences<TCache>
121121
public FeatureReferences(Microsoft.AspNetCore.Http.Features.IFeatureCollection collection) { throw null; }
122122
public Microsoft.AspNetCore.Http.Features.IFeatureCollection Collection { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } }
123123
public int Revision { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } }
124-
public TFeature Fetch<TFeature>([System.Diagnostics.CodeAnalysis.AllowNullAttribute, System.Diagnostics.CodeAnalysis.MaybeNullAttribute] ref TFeature cached, System.Func<Microsoft.AspNetCore.Http.Features.IFeatureCollection, TFeature> factory) where TFeature : class { throw null; }
125-
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]public TFeature Fetch<TFeature, TState>([System.Diagnostics.CodeAnalysis.AllowNullAttribute, System.Diagnostics.CodeAnalysis.MaybeNullAttribute] ref TFeature cached, TState state, System.Func<TState, TFeature> factory) where TFeature : class { throw null; }
124+
public TFeature Fetch<TFeature>([System.Diagnostics.CodeAnalysis.AllowNullAttribute, System.Diagnostics.CodeAnalysis.MaybeNullAttribute] ref TFeature cached, System.Func<Microsoft.AspNetCore.Http.Features.IFeatureCollection, TFeature> factory) where TFeature : class? { throw null; }
125+
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]public TFeature Fetch<TFeature, TState>([System.Diagnostics.CodeAnalysis.AllowNullAttribute, System.Diagnostics.CodeAnalysis.MaybeNullAttribute] ref TFeature cached, TState state, System.Func<TState, TFeature> factory) where TFeature : class? { throw null; }
126126
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]public void Initalize(Microsoft.AspNetCore.Http.Features.IFeatureCollection collection) { }
127127
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]public void Initalize(Microsoft.AspNetCore.Http.Features.IFeatureCollection collection, int revision) { }
128128
}
@@ -152,7 +152,7 @@ public partial interface IFeatureCollection : System.Collections.Generic.IEnumer
152152
}
153153
public partial interface IFormFeature
154154
{
155-
Microsoft.AspNetCore.Http.IFormCollection Form { get; set; }
155+
Microsoft.AspNetCore.Http.IFormCollection? Form { get; set; }
156156
bool HasFormContentType { get; }
157157
Microsoft.AspNetCore.Http.IFormCollection ReadForm();
158158
System.Threading.Tasks.Task<Microsoft.AspNetCore.Http.IFormCollection> ReadFormAsync(System.Threading.CancellationToken cancellationToken);
@@ -170,9 +170,9 @@ public partial interface IHttpBufferingFeature
170170
public partial interface IHttpConnectionFeature
171171
{
172172
string ConnectionId { get; set; }
173-
System.Net.IPAddress LocalIpAddress { get; set; }
173+
System.Net.IPAddress? LocalIpAddress { get; set; }
174174
int LocalPort { get; set; }
175-
System.Net.IPAddress RemoteIpAddress { get; set; }
175+
System.Net.IPAddress? RemoteIpAddress { get; set; }
176176
int RemotePort { get; set; }
177177
}
178178
public partial interface IHttpMaxRequestBodySizeFeature
@@ -225,7 +225,7 @@ public partial interface IHttpResponseFeature
225225
System.IO.Stream Body { get; set; }
226226
bool HasStarted { get; }
227227
Microsoft.AspNetCore.Http.IHeaderDictionary Headers { get; set; }
228-
string ReasonPhrase { get; set; }
228+
string? ReasonPhrase { get; set; }
229229
int StatusCode { get; set; }
230230
void OnCompleted(System.Func<object, System.Threading.Tasks.Task> callback, object state);
231231
void OnStarting(System.Func<object, System.Threading.Tasks.Task> callback, object state);
@@ -255,7 +255,7 @@ public partial interface IHttpWebSocketFeature
255255
}
256256
public partial interface IItemsFeature
257257
{
258-
System.Collections.Generic.IDictionary<object, object> Items { get; set; }
258+
System.Collections.Generic.IDictionary<object, object?> Items { get; set; }
259259
}
260260
public partial interface IQueryFeature
261261
{
@@ -287,8 +287,8 @@ public partial interface ISessionFeature
287287
}
288288
public partial interface ITlsConnectionFeature
289289
{
290-
System.Security.Cryptography.X509Certificates.X509Certificate2 ClientCertificate { get; set; }
291-
System.Threading.Tasks.Task<System.Security.Cryptography.X509Certificates.X509Certificate2> GetClientCertificateAsync(System.Threading.CancellationToken cancellationToken);
290+
System.Security.Cryptography.X509Certificates.X509Certificate2? ClientCertificate { get; set; }
291+
System.Threading.Tasks.Task<System.Security.Cryptography.X509Certificates.X509Certificate2?> GetClientCertificateAsync(System.Threading.CancellationToken cancellationToken);
292292
}
293293
public partial interface ITlsTokenBindingFeature
294294
{
@@ -309,6 +309,6 @@ namespace Microsoft.AspNetCore.Http.Features.Authentication
309309
{
310310
public partial interface IHttpAuthenticationFeature
311311
{
312-
System.Security.Claims.ClaimsPrincipal User { get; set; }
312+
System.Security.Claims.ClaimsPrincipal? User { get; set; }
313313
}
314314
}

0 commit comments

Comments
 (0)