Skip to content

Commit db92368

Browse files
committed
Update copyright notices and improve code quality
This commit updates copyright comments across multiple files to include a complete URL for the copyright holder. It also enhances type safety and readability by changing variable types and using nullable reference types. The indentation size in the `.editorconfig` file has been changed from 4 to 2, affecting code formatting. Additionally, test files have been updated to use shorthand syntax for initializing `HeaderDictionary`. These changes aim to improve code quality, consistency, and adherence to modern C# practices.
1 parent bfd1961 commit db92368

14 files changed

+24
-21
lines changed

.editorconfig

+1
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ indent_size = 2
122122
# Code files
123123
[*.{cs,csx,vb,vbx}]
124124
indent_size = 4
125+
file_header_template = Copyright © https://myCSharp.de - all rights reserved
125126

126127
# Organize usings
127128
dotnet_sort_system_directives_first = true

samples/HttpClientHints.Samples.AspNetCoreMvc/Controllers/HomeController.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright © myCSharp.de - all rights reserved
1+
// Copyright © https://myCSharp.de - all rights reserved
22

33
using Microsoft.AspNetCore.Mvc;
44

samples/HttpClientHints.Samples.AspNetCoreMvc/Program.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright © myCSharp.de - all rights reserved
1+
// Copyright © https://myCSharp.de - all rights reserved
22

33
using MyCSharp.HttpClientHints.AspNetCore;
44

src/HttpClientHints.AspNetCore/HttpClientHintsHttpContextExtensions.cs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright © myCSharp.de - all rights reserved
1+
// Copyright © https://myCSharp.de - all rights reserved
22

33
using Microsoft.AspNetCore.Http;
44
using Microsoft.Extensions.Primitives;
@@ -23,13 +23,13 @@ public static class HttpClientHintsHttpContextExtensions
2323
public static HttpClientHints GetClientHints(this HttpContext context)
2424
{
2525
// Check if client hints are already cached for this request
26-
if (context.Items.TryGetValue(ClientHintsCacheKey, out var cached) && cached is HttpClientHints hints)
26+
if (context.Items.TryGetValue(ClientHintsCacheKey, out object? cached) && cached is HttpClientHints hints)
2727
{
2828
return hints;
2929
}
30-
30+
3131
// Create and cache new client hints
32-
var newHints = context.Request.Headers.GetClientHints();
32+
HttpClientHints newHints = context.Request.Headers.GetClientHints();
3333
context.Items[ClientHintsCacheKey] = newHints;
3434
return newHints;
3535
}
@@ -44,14 +44,14 @@ public static HttpClientHints GetClientHints(this IHeaderDictionary headers)
4444
// User Agent
4545
headers.TryGetValue("User-Agent", out StringValues userAgentValues);
4646
string? userAgent = userAgentValues.Count > 0 ? userAgentValues[0] : null;
47-
47+
4848
headers.TryGetValue("Sec-CH-UA", out StringValues uaValues);
4949
string? ua = uaValues.Count > 0 ? uaValues[0] : null;
5050

5151
// Platform
5252
headers.TryGetValue("Sec-CH-UA-Platform", out StringValues platformValues);
5353
string? platform = platformValues.Count > 0 ? platformValues[0] : null;
54-
54+
5555
headers.TryGetValue("Sec-CH-UA-Platform-Version", out StringValues platformVersionValues);
5656
string? platformVersion = platformVersionValues.Count > 0 ? platformVersionValues[0] : null;
5757

@@ -66,7 +66,7 @@ public static HttpClientHints GetClientHints(this IHeaderDictionary headers)
6666
// Device
6767
headers.TryGetValue("Sec-CH-UA-Model", out StringValues modelValues);
6868
string? model = modelValues.Count > 0 ? modelValues[0] : null;
69-
69+
7070
headers.TryGetValue("Sec-CH-UA-Mobile", out StringValues mobileValues);
7171
bool? mobile = HttpClientHintsInterpreter.IsMobile(mobileValues.Count > 0 ? mobileValues[0] : null);
7272

src/HttpClientHints.AspNetCore/HttpClientHintsMiddlewareConfig.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright © myCSharp.de - all rights reserved
1+
// Copyright © https://myCSharp.de - all rights reserved
22

33
namespace MyCSharp.HttpClientHints.AspNetCore;
44

src/HttpClientHints.AspNetCore/HttpClientHintsOptions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright © myCSharp.de - all rights reserved
1+
// Copyright © https://myCSharp.de - all rights reserved
22

33
namespace MyCSharp.HttpClientHints.AspNetCore;
44

src/HttpClientHints.AspNetCore/HttpClientHintsRegistration.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright © myCSharp.de - all rights reserved
1+
// Copyright © https://myCSharp.de - all rights reserved
22

33
using Microsoft.AspNetCore.Builder;
44
using Microsoft.Extensions.DependencyInjection;

src/HttpClientHints.AspNetCore/HttpClientHintsRequestMiddleware.cs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Copyright © https://myCSharp.de - all rights reserved
2+
13
using Microsoft.AspNetCore.Http;
24
using Microsoft.Extensions.Options;
35

src/HttpClientHints/HttpClientHints.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright © myCSharp.de - all rights reserved
1+
// Copyright © https://myCSharp.de - all rights reserved
22

33
using Microsoft.Extensions.Primitives;
44

src/HttpClientHints/HttpClientHintsInterpreter.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright © myCSharp.de - all rights reserved
1+
// Copyright © https://myCSharp.de - all rights reserved
22

33
namespace MyCSharp.HttpClientHints;
44

tests/HttpClientHints.AspNetCore.UnitTests/HttpClientHintsHttpContextExtensionsTests.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright © myCSharp.de - all rights reserved
1+
// Copyright © https://myCSharp.de - all rights reserved
22

33
using Microsoft.AspNetCore.Http;
44
using Microsoft.Extensions.Primitives;
@@ -12,7 +12,7 @@ public class HttpClientHintsHttpContextExtensionsTests
1212
public void GetClientHints_ReturnsCorrectValues_WhenHeadersArePresent()
1313
{
1414
// Arrange
15-
HeaderDictionary headers = new HeaderDictionary
15+
HeaderDictionary headers = new()
1616
{
1717
{ "User-Agent", new StringValues("TestUserAgent") },
1818
{ "Sec-CH-UA", new StringValues("TestUA") },
@@ -65,7 +65,7 @@ public void GetClientHints_ReturnsNullValues_WhenHeadersAreMissing()
6565
public void GetClientHints_ReturnsCorrectMobileValue_WhenMobileHeaderIsTrue()
6666
{
6767
// Arrange
68-
HeaderDictionary headers = new HeaderDictionary
68+
HeaderDictionary headers = new()
6969
{
7070
{ "Sec-CH-UA-Mobile", new StringValues("?1") } // true
7171
};
@@ -81,7 +81,7 @@ public void GetClientHints_ReturnsCorrectMobileValue_WhenMobileHeaderIsTrue()
8181
public void GetClientHints_ReturnsCorrectMobileValue_WhenMobileHeaderIsFalse()
8282
{
8383
// Arrange
84-
HeaderDictionary headers = new HeaderDictionary
84+
HeaderDictionary headers = new()
8585
{
8686
{ "Sec-CH-UA-Mobile", new StringValues("?0") } // false
8787
};

tests/HttpClientHints.AspNetCore.UnitTests/HttpClientHintsRegistrationTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright © myCSharp.de - all rights reserved
1+
// Copyright © https://myCSharp.de - all rights reserved
22

33
using Microsoft.AspNetCore.Builder;
44
using Microsoft.Extensions.DependencyInjection;

tests/HttpClientHints.AspNetCore.UnitTests/HttpClientHintsRequestMiddlewareTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright © myCSharp.de - all rights reserved
1+
// Copyright © https://myCSharp.de - all rights reserved
22

33
using Microsoft.AspNetCore.Http;
44
using Microsoft.Extensions.Options;

tests/HttpClientHints.UnitTests/HttpClientHintsInterpreterTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright © myCSharp.de - all rights reserved
1+
// Copyright © https://myCSharp.de - all rights reserved
22

33
using Xunit;
44

0 commit comments

Comments
 (0)