Skip to content

Commit f1ca557

Browse files
committed
Enabled nullable for most projects
1 parent 020b60b commit f1ca557

157 files changed

Lines changed: 598 additions & 439 deletions

File tree

Some content is hidden

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

‎SpotifyAPI.Web.Auth/AuthException.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ protected AuthException(
1414
System.Runtime.Serialization.SerializationInfo info,
1515
System.Runtime.Serialization.StreamingContext context) : base(info, context) { }
1616

17-
public string Error { get; set; }
18-
public string State { get; set; }
17+
public string? Error { get; set; }
18+
public string? State { get; set; }
1919
}
2020
}

‎SpotifyAPI.Web.Auth/EmbedIOAuthServer.cs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ namespace SpotifyAPI.Web.Auth
1212
{
1313
public class EmbedIOAuthServer : IAuthServer
1414
{
15-
public event Func<object, AuthorizationCodeResponse, Task> AuthorizationCodeReceived;
16-
public event Func<object, ImplictGrantResponse, Task> ImplictGrantReceived;
15+
public event Func<object, AuthorizationCodeResponse, Task>? AuthorizationCodeReceived;
16+
public event Func<object, ImplictGrantResponse, Task>? ImplictGrantReceived;
1717

1818
private const string AssetsResourcePath = "SpotifyAPI.Web.Auth.Resources.auth_assets";
1919
private const string DefaultResourcePath = "SpotifyAPI.Web.Auth.Resources.default_site";
2020

21-
private CancellationTokenSource _cancelTokenSource;
21+
private CancellationTokenSource? _cancelTokenSource;
2222
private readonly WebServer _webServer;
2323

2424
public EmbedIOAuthServer(Uri baseUri, int port)
@@ -76,7 +76,7 @@ public Task Start()
7676

7777
public Task Stop()
7878
{
79-
_cancelTokenSource.Cancel();
79+
_cancelTokenSource?.Cancel();
8080
return Task.CompletedTask;
8181
}
8282

‎SpotifyAPI.Web.Auth/Models/Response/AuthorizationCodeResponse.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public AuthorizationCodeResponse(string code)
99
Code = code;
1010
}
1111

12-
public string Code { get; set; }
13-
public string State { get; set; }
12+
public string Code { get; set; } = default!;
13+
public string State { get; set; } = default!;
1414
}
1515
}

‎SpotifyAPI.Web.Auth/Models/Response/ImplicitGrantResponse.cs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ public ImplictGrantResponse(string accessToken, string tokenType, int expiresIn)
1414
ExpiresIn = expiresIn;
1515
}
1616

17-
public string AccessToken { get; set; }
18-
public string TokenType { get; set; }
17+
public string AccessToken { get; set; } = default!;
18+
public string TokenType { get; set; } = default!;
1919
public int ExpiresIn { get; set; }
20-
public string State { get; set; }
20+
public string State { get; set; } = default!;
2121

2222
/// <summary>
2323
/// Auto-Initalized to UTC Now

‎SpotifyAPI.Web.Auth/SpotifyAPI.Web.Auth.csproj‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<TargetFrameworks>netstandard2.1;netstandard2.0</TargetFrameworks>
4+
<LangVersion>8.0</LangVersion>
5+
<Nullable>enable</Nullable>
46
<PackageId>SpotifyAPI.Web.Auth</PackageId>
57
<Title>SpotifyAPI.Web.Auth</Title>
68
<Authors>Jonas Dellinger</Authors>

‎SpotifyAPI.Web.Examples/Example.CLI.PersistentConfig/Example.CLI.PersistentConfig.csproj‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
55
<TargetFramework>netcoreapp3.1</TargetFramework>
6+
<LangVersion>8.0</LangVersion>
7+
<Nullable>enable</Nullable>
68
</PropertyGroup>
79

810
<ItemGroup>

‎SpotifyAPI.Web.Examples/Example.CLI.PersistentConfig/Program.cs‎

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System.Diagnostics;
21
using System.IO;
32
using System.Threading.Tasks;
43
using System;
@@ -18,12 +17,19 @@ namespace Example.CLI.PersistentConfig
1817
public class Program
1918
{
2019
private const string CredentialsPath = "credentials.json";
21-
private static readonly string clientId = Environment.GetEnvironmentVariable("SPOTIFY_CLIENT_ID");
22-
private static readonly string clientSecret = Environment.GetEnvironmentVariable("SPOTIFY_CLIENT_SECRET");
23-
private static EmbedIOAuthServer _server;
20+
private static readonly string? clientId = Environment.GetEnvironmentVariable("SPOTIFY_CLIENT_ID");
21+
private static readonly string? clientSecret = Environment.GetEnvironmentVariable("SPOTIFY_CLIENT_SECRET");
22+
private static readonly EmbedIOAuthServer _server = new EmbedIOAuthServer(new Uri("http://localhost:5000/callback"), 5000);
2423

2524
public static async Task<int> Main()
2625
{
26+
if (string.IsNullOrEmpty(clientId) || string.IsNullOrEmpty(clientSecret))
27+
{
28+
throw new NullReferenceException(
29+
"Please set SPOTIFY_CLIENT_ID and SPOTIFY_CLIENT_SECRET via environment variables before starting the program"
30+
);
31+
}
32+
2733
if (File.Exists(CredentialsPath))
2834
{
2935
await Start();
@@ -42,7 +48,7 @@ private static async Task Start()
4248
var json = await File.ReadAllTextAsync(CredentialsPath);
4349
var token = JsonConvert.DeserializeObject<AuthorizationCodeTokenResponse>(json);
4450

45-
var authenticator = new AuthorizationCodeAuthenticator(clientId, clientSecret, token);
51+
var authenticator = new AuthorizationCodeAuthenticator(clientId!, clientSecret!, token);
4652
authenticator.TokenRefreshed += (sender, token) => File.WriteAllText(CredentialsPath, JsonConvert.SerializeObject(token));
4753

4854
var config = SpotifyClientConfig.CreateDefault()
@@ -61,11 +67,10 @@ private static async Task Start()
6167

6268
private static async Task StartAuthentication()
6369
{
64-
_server = new EmbedIOAuthServer(new Uri("http://localhost:5000/callback"), 5000);
6570
await _server.Start();
6671
_server.AuthorizationCodeReceived += OnAuthorizationCodeReceived;
6772

68-
var request = new LoginRequest(_server.BaseUri, clientId, LoginRequest.ResponseType.Code)
73+
var request = new LoginRequest(_server.BaseUri, clientId!, LoginRequest.ResponseType.Code)
6974
{
7075
Scope = new List<string> { UserReadEmail, UserReadPrivate, PlaylistReadPrivate }
7176
};
@@ -85,7 +90,7 @@ private static async Task OnAuthorizationCodeReceived(object sender, Authorizati
8590
{
8691
await _server.Stop();
8792
AuthorizationCodeTokenResponse token = await new OAuthClient().RequestToken(
88-
new AuthorizationCodeTokenRequest(clientId, clientSecret, response.Code, _server.BaseUri)
93+
new AuthorizationCodeTokenRequest(clientId!, clientSecret!, response.Code, _server.BaseUri)
8994
);
9095

9196
await File.WriteAllTextAsync(CredentialsPath, JsonConvert.SerializeObject(token));

‎SpotifyAPI.Web.Tests/Clients/UserProfileClientTest.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public async Task Get()
2828

2929
await client.Get(userId);
3030

31-
api.Verify(a => a.Get<PublicUser>(SpotifyUrls.User("userId")), Times.Once);
31+
api.Verify(a => a.Get<PublicUser>(SpotifyUrls.User(userId)), Times.Once);
3232
}
3333
}
3434
}

‎SpotifyAPI.Web/Clients/OAuthClient.cs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ private static Dictionary<string, string> BuildAuthHeader(string clientId, strin
101101
private static APIConnector ValidateConfig(SpotifyClientConfig config)
102102
{
103103
Ensure.ArgumentNotNull(config, nameof(config));
104+
104105
return new APIConnector(
105106
config.BaseAddress,
106107
config.Authenticator,

‎SpotifyAPI.Web/Clients/SpotifyClientConfig.cs‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ namespace SpotifyAPI.Web
77
public class SpotifyClientConfig
88
{
99
public Uri BaseAddress { get; private set; }
10-
public IAuthenticator Authenticator { get; private set; }
10+
public IAuthenticator? Authenticator { get; private set; }
1111
public IJSONSerializer JSONSerializer { get; private set; }
1212
public IHTTPClient HTTPClient { get; private set; }
13-
public IHTTPLogger HTTPLogger { get; private set; }
14-
public IRetryHandler RetryHandler { get; private set; }
13+
public IHTTPLogger? HTTPLogger { get; private set; }
14+
public IRetryHandler? RetryHandler { get; private set; }
1515
public IPaginator DefaultPaginator { get; private set; }
1616

1717
/// <summary>
@@ -26,11 +26,11 @@ public class SpotifyClientConfig
2626
/// <param name="defaultPaginator"></param>
2727
public SpotifyClientConfig(
2828
Uri baseAddress,
29-
IAuthenticator authenticator,
29+
IAuthenticator? authenticator,
3030
IJSONSerializer jsonSerializer,
3131
IHTTPClient httpClient,
32-
IRetryHandler retryHandler,
33-
IHTTPLogger httpLogger,
32+
IRetryHandler? retryHandler,
33+
IHTTPLogger? httpLogger,
3434
IPaginator defaultPaginator
3535
)
3636
{

0 commit comments

Comments
 (0)