Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed nullability in IInternalSettings interface #563

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions Softeq.XToolkit.Common/Extensions/InternalSettingsExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Developed by Softeq Development Corporation
// http://www.softeq.com

using System.Diagnostics.CodeAnalysis;
using Softeq.XToolkit.Common.Interfaces;

namespace Softeq.XToolkit.Common.Extensions
Expand All @@ -12,7 +11,7 @@ public static void AddOrUpdateJsonValue<T>(
this IInternalSettings internalSettings,
IJsonSerializer jsonSerializer,
string key,
T value)
T? value)
{
if (value == null)
{
Expand All @@ -24,14 +23,13 @@ public static void AddOrUpdateJsonValue<T>(
internalSettings.AddOrUpdateValue(key, json);
}

[return: MaybeNull]
public static T GetJsonValueOrDefault<T>(
public static T? GetJsonValueOrDefault<T>(
this IInternalSettings internalSettings,
IJsonSerializer jsonSerializer,
string key,
[MaybeNull] T defaultValue = default!)
T? defaultValue = default)
{
var json = internalSettings.GetValueOrDefault(key, default(string)!);
var json = internalSettings.GetValueOrDefault(key, default(string));
return string.IsNullOrEmpty(json)
? defaultValue
: jsonSerializer.Deserialize<T>(json);
Expand Down
4 changes: 2 additions & 2 deletions Softeq.XToolkit.Common/Interfaces/IInternalSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public interface IInternalSettings
/// </summary>
/// <param name="key">key to update.</param>
/// <param name="value">value to set.</param>
void AddOrUpdateValue(string key, string value);
void AddOrUpdateValue(string key, string? value);

/// <summary>
/// Adds or updates a value.
Expand Down Expand Up @@ -103,7 +103,7 @@ public interface IInternalSettings
/// <param name="key">Key for settings.</param>
/// <param name="defaultValue">default value if not set.</param>
/// <returns>Value or default.</returns>
string GetValueOrDefault(string key, string? defaultValue = default);
string? GetValueOrDefault(string key, string? defaultValue = default);

/// <summary>
/// Gets the current value or the default that you specify.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ public interface IPushTokenStorageService
/// <summary>
/// Gets or sets push token in custom storage.
/// </summary>
string PushToken { get; set; }
string? PushToken { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public PushTokenStorageService(IInternalSettings internalSettings)
}

/// <inheritdoc />
public string PushToken
public string? PushToken
{
get => _internalSettings.GetValueOrDefault(_pushTokenKey, default(string));
set => _internalSettings.AddOrUpdateValue(_pushTokenKey, value);
Expand Down
4 changes: 2 additions & 2 deletions Softeq.XToolkit.PushNotifications/PushTokenSynchronizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public Task SynchronizeTokenIfNeededAsync()

if (IsTokenRegisteredInSystem && !IsTokenSavedOnServer)
{
return DoSendTokenToServer(_pushTokenStorageService.PushToken);
return DoSendTokenToServer(_pushTokenStorageService.PushToken!);
}

return Task.CompletedTask;
Expand All @@ -90,7 +90,7 @@ public async Task UnregisterFromRemotePushNotificationsAsync()
}

var tokenRemovedFromServer = await _remotePushNotificationsService
.RemovePushNotificationsToken(_pushTokenStorageService.PushToken)
.RemovePushNotificationsToken(_pushTokenStorageService.PushToken!)
.ConfigureAwait(false);
if (tokenRemovedFromServer)
{
Expand Down
4 changes: 2 additions & 2 deletions Softeq.XToolkit.WhiteLabel/Services/InternalSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void AddOrUpdateValue(string key, long value)
Preferences.Set(key, value);
}

public void AddOrUpdateValue(string key, string value)
public void AddOrUpdateValue(string key, string? value)
{
Preferences.Set(key, value);
}
Expand Down Expand Up @@ -69,7 +69,7 @@ public long GetValueOrDefault(string key, long defaultValue = default)
return Preferences.Get(key, defaultValue);
}

public string GetValueOrDefault(string key, string? defaultValue = default)
public string? GetValueOrDefault(string key, string? defaultValue = default)
{
return Preferences.Get(key, defaultValue);
}
Expand Down
Loading