This commit is contained in:
@@ -42,7 +42,17 @@ public abstract class StatefullPage : Page
|
||||
/// </summary>
|
||||
protected async Task SaveState(PageContext ctx, CancellationToken ct)
|
||||
{
|
||||
foreach (var prop in GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance))
|
||||
var t = GetType();
|
||||
foreach (var prop in t.GetProperties(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public))
|
||||
{
|
||||
var attr = prop.GetCustomAttribute<StatefullAttribute>();
|
||||
if (attr is null) continue;
|
||||
|
||||
var value = prop.GetValue(this);
|
||||
await ctx.StateStorage.SetAsync(ctx.SessionKey, attr.Key, value, ct);
|
||||
}
|
||||
|
||||
foreach (var prop in t.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public))
|
||||
{
|
||||
var attr = prop.GetCustomAttribute<StatefullAttribute>();
|
||||
if (attr is null) continue;
|
||||
|
||||
@@ -19,6 +19,10 @@ public sealed class InMemoryStateStorage : IStateStorage
|
||||
/// <inheritdoc />
|
||||
public Task SetAsync<T>(CompositeSessionKey session, string key, T state, CancellationToken ct)
|
||||
{
|
||||
if (!_store.ContainsKey(session))
|
||||
{
|
||||
_store[session] = new();
|
||||
}
|
||||
_store[session][key] = state!;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user