Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
chrissainty authored Sep 18, 2024
2 parents a5c7dbe + 8f60bf3 commit bc70d25
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
20 changes: 10 additions & 10 deletions src/Blazored.LocalStorage/LocalStorageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public async ValueTask SetItemAsync<T>(string key, T data, CancellationToken can
if (string.IsNullOrWhiteSpace(key))
throw new ArgumentNullException(nameof(key));

var e = await RaiseOnChangingAsync(key, data).ConfigureAwait(false);
var e = await RaiseOnChangingAsync<T>(key, data).ConfigureAwait(false);

if (e.Cancel)
return;
Expand All @@ -42,7 +42,7 @@ public async ValueTask SetItemAsStringAsync(string key, string data, Cancellatio
if (data is null)
throw new ArgumentNullException(nameof(data));

var e = await RaiseOnChangingAsync(key, data).ConfigureAwait(false);
var e = await RaiseOnChangingAsync<string>(key, data).ConfigureAwait(false);

if (e.Cancel)
return;
Expand Down Expand Up @@ -118,7 +118,7 @@ public void SetItem<T>(string key, T data)
if (string.IsNullOrWhiteSpace(key))
throw new ArgumentNullException(nameof(key));

var e = RaiseOnChangingSync(key, data);
var e = RaiseOnChangingSync<T>(key, data);

if (e.Cancel)
return;
Expand All @@ -136,7 +136,7 @@ public void SetItemAsString(string key, string data)

ArgumentNullException.ThrowIfNull(data);

var e = RaiseOnChangingSync(key, data);
var e = RaiseOnChangingSync<string>(key, data);

if (e.Cancel)
return;
Expand Down Expand Up @@ -208,12 +208,12 @@ public bool ContainKey(string key)
=> _storageProvider.ContainKey(key);

public event EventHandler<ChangingEventArgs>? Changing;
private async Task<ChangingEventArgs> RaiseOnChangingAsync(string key, object? data)
private async Task<ChangingEventArgs> RaiseOnChangingAsync<T>(string key, object? data)
{
var e = new ChangingEventArgs
{
Key = key,
OldValue = await GetItemInternalAsync<object>(key).ConfigureAwait(false),
OldValue = await GetItemInternalAsync<T>(key).ConfigureAwait(false),
NewValue = data
};

Expand All @@ -222,12 +222,12 @@ private async Task<ChangingEventArgs> RaiseOnChangingAsync(string key, object? d
return e;
}

private ChangingEventArgs RaiseOnChangingSync(string key, object? data)
private ChangingEventArgs RaiseOnChangingSync<T>(string key, object? data)
{
var e = new ChangingEventArgs
{
Key = key,
OldValue = GetItemInternal(key),
OldValue = GetItemInternal<T>(key),
NewValue = data
};

Expand Down Expand Up @@ -255,7 +255,7 @@ private ChangingEventArgs RaiseOnChangingSync(string key, object? data)
}
}

private object? GetItemInternal(string key)
private object? GetItemInternal<T>(string key)
{
if (string.IsNullOrEmpty(key))
throw new ArgumentNullException(nameof(key));
Expand All @@ -267,7 +267,7 @@ private ChangingEventArgs RaiseOnChangingSync(string key, object? data)

try
{
return _serializer.Deserialize<object>(serialisedData);
return _serializer.Deserialize<T>(serialisedData);
}
catch (JsonException)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<PackageReference Include="FluentAssertions" Version="6.8.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0" />
<PackageReference Include="Moq" Version="4.18.2" />
<PackageReference Include="System.Text.Json" Version="8.0.0" />
<PackageReference Include="System.Text.Json" Version="8.0.4" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
Expand Down

0 comments on commit bc70d25

Please sign in to comment.