Skip to content
This repository was archived by the owner on Dec 26, 2025. It is now read-only.
Closed
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
7 changes: 7 additions & 0 deletions src/Blazored.SessionStorage/ISessionStorageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ public interface ISessionStorageService

Task<string> KeyAsync(int index);

/// <summary>
/// Checks if the key exists in Session Storage but does not check the value.
/// </summary>
/// <param name="key">name of the key</param>
/// <returns>True if the key exist, false otherwise</returns>
Task<bool> ContainKeyAsync(string key);

Task<int> LengthAsync();

Task RemoveItemAsync(string key);
Expand Down
7 changes: 7 additions & 0 deletions src/Blazored.SessionStorage/ISyncSessionStorageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ public interface ISyncSessionStorageService

string Key(int index);

/// <summary>
/// Checks if the key exists in Session Storage but does not check the value.
/// </summary>
/// <param name="key">name of the key</param>
/// <returns>True if the key exist, false otherwise</returns>
bool ContainKey(string key);

int Length();

void RemoveItem(string key);
Expand Down
13 changes: 11 additions & 2 deletions src/Blazored.SessionStorage/SessionStorageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ public async Task RemoveItemAsync(string key)

public async Task<int> LengthAsync() => await _jSRuntime.InvokeAsync<int>("eval", "sessionStorage.length");

public async Task<string> KeyAsync(int index) => await _jSRuntime.InvokeAsync<string>("sessionStorage.key", index);
public async Task<string> KeyAsync(int index) => await _jSRuntime.InvokeAsync<string>("sessionStorage.key", index);
public async Task<bool> ContainKeyAsync(string key) => await _jSRuntime.InvokeAsync<bool>("sessionStorage.hasOwnProperty", key);


public void SetItem<T>(string key, T data)
{
Expand Down Expand Up @@ -136,7 +138,14 @@ public string Key(int index)
throw new InvalidOperationException("IJSInProcessRuntime not available");

return _jSInProcessRuntime.Invoke<string>("sessionStorage.key", index);
}
}
public bool ContainKey(string key)
{
if (_jSInProcessRuntime == null)
throw new InvalidOperationException("IJSInProcessRuntime not available");

return _jSInProcessRuntime.Invoke<bool>("sessionStorage.hasOwnProperty", key);
}

private async Task<ChangingEventArgs> RaiseOnChangingAsync(string key, object data)
{
Expand Down