From b3c7ae771f77a8661db996a3e2b8e91e3242b281 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Sat, 16 Sep 2023 02:15:01 +0200 Subject: [PATCH] Nullable Examples.AspNet (#1353) --- .../AspNet/Controllers/WeatherForecastController.cs | 12 +++++------- examples/AspNet/Examples.AspNet.csproj | 1 - examples/AspNet/Global.asax.cs | 4 ++-- examples/AspNet/Models/WeatherForecast.cs | 13 +++++++++---- .../AspNet/SuppressInstrumentationHttpModule.cs | 2 +- 5 files changed, 17 insertions(+), 15 deletions(-) diff --git a/examples/AspNet/Controllers/WeatherForecastController.cs b/examples/AspNet/Controllers/WeatherForecastController.cs index 1aa7e0870b..5ef863576d 100644 --- a/examples/AspNet/Controllers/WeatherForecastController.cs +++ b/examples/AspNet/Controllers/WeatherForecastController.cs @@ -127,12 +127,10 @@ public async Task PostData() private static IEnumerable GetWeatherForecast() { var rng = new Random(); - return Enumerable.Range(1, 5).Select(index => new WeatherForecast - { - Date = DateTime.Now.AddDays(index), - TemperatureC = rng.Next(-20, 55), - Summary = Summaries[rng.Next(Summaries.Length)], - }) + return Enumerable.Range(1, 5).Select(index => new WeatherForecast( + date: DateTime.Now.AddDays(index), + temperatureC: rng.Next(-20, 55), + summary: Summaries[rng.Next(Summaries.Length)])) .ToArray(); } @@ -218,7 +216,7 @@ private async Task RequestValidThatSpawnsSubSpansViaHttpClient() response.EnsureSuccessStatusCode(); } - private Uri GenerateContentRequestUri(string path, Func transform = null) + private Uri GenerateContentRequestUri(string path, Func? transform = null) { var rawUri = this.Url.Content(path); diff --git a/examples/AspNet/Examples.AspNet.csproj b/examples/AspNet/Examples.AspNet.csproj index 124834cd10..9443447544 100644 --- a/examples/AspNet/Examples.AspNet.csproj +++ b/examples/AspNet/Examples.AspNet.csproj @@ -8,7 +8,6 @@ false web.config false - disable diff --git a/examples/AspNet/Global.asax.cs b/examples/AspNet/Global.asax.cs index 3724b36df0..e8318035b9 100644 --- a/examples/AspNet/Global.asax.cs +++ b/examples/AspNet/Global.asax.cs @@ -31,8 +31,8 @@ namespace Examples.AspNet; public class WebApiApplication : HttpApplication #pragma warning restore SA1649 // File name should match first type name { - private IDisposable tracerProvider; - private IDisposable meterProvider; + private IDisposable? tracerProvider; + private IDisposable? meterProvider; protected void Application_Start() { diff --git a/examples/AspNet/Models/WeatherForecast.cs b/examples/AspNet/Models/WeatherForecast.cs index d4585e88ff..4e4384bbef 100644 --- a/examples/AspNet/Models/WeatherForecast.cs +++ b/examples/AspNet/Models/WeatherForecast.cs @@ -20,11 +20,16 @@ namespace Examples.AspNet.Models; public class WeatherForecast { - public DateTime Date { get; set; } + public WeatherForecast(DateTime date, int temperatureC, string summary) + { + this.Date = date; + this.TemperatureC = temperatureC; + this.Summary = summary; + } - public int TemperatureC { get; set; } + public DateTime Date { get; } - public int TemperatureF => 32 + (int)(this.TemperatureC / 0.5556); + public int TemperatureC { get; } - public string Summary { get; set; } + public string Summary { get; } } diff --git a/examples/AspNet/SuppressInstrumentationHttpModule.cs b/examples/AspNet/SuppressInstrumentationHttpModule.cs index ce0d0ae246..bd31841d77 100644 --- a/examples/AspNet/SuppressInstrumentationHttpModule.cs +++ b/examples/AspNet/SuppressInstrumentationHttpModule.cs @@ -28,7 +28,7 @@ namespace Examples.AspNet; /// public class SuppressInstrumentationHttpModule : IHttpModule { - private IDisposable suppressionScope; + private IDisposable? suppressionScope; public void Init(HttpApplication context) {