Skip to content

Commit

Permalink
Improve DialogResult extension with TryGet for data
Browse files Browse the repository at this point in the history
Add result.Data
  • Loading branch information
b-straub committed Jul 1, 2024
1 parent 6b6849d commit c60b41a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
12 changes: 12 additions & 0 deletions RxMudBlazorLight/Extensions/RxMudBlazorLightExtensionsExtern.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,17 @@ public static bool OK([NotNullWhen(true)] this DialogResult? result)
{
return result is not null && !result.Canceled;
}

public static bool TryGet<T>(this DialogResult? result, [NotNullWhen(true)] out T? data)
{
data = default;

if (result is not null && !result.Canceled)
{
data = (T?)result.Data;
}

return data is not null;
}
}
}
8 changes: 2 additions & 6 deletions RxMudBlazorLightTestBase/CRUD/CRUDItemAddOrUpdate.razor
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,9 @@ else
var dialog = await DialogService.ShowAsync<CRUDItemDialog>(AddMode ? "Add ToDo" : "Edit ToDo", parameters);
var result = await dialog.Result;

if (result.OK())
if (result.TryGet<CrudService.CrudItemInput>(out var scope))
{
var scope = (CrudService.CrudItemInput?)result.Data;
if (scope is not null)
{
await scope.SubmitAsync();
}
await scope.SubmitAsync();
}
}
}

0 comments on commit c60b41a

Please sign in to comment.