Skip to content

Commit

Permalink
Improve nullable type display
Browse files Browse the repository at this point in the history
Resolves #11
  • Loading branch information
jacobjmarks committed May 4, 2024
1 parent c0affc3 commit 5a289be
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
11 changes: 8 additions & 3 deletions Client/Pages/Home.razor
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,14 @@
</TitleContent>
<ChildContent>
<MudStack>
<MudSwitch @bind-Value="@includeNullableTypes" Color="Color.Primary">
Include nullable types
</MudSwitch>
<MudSelect Label="Show nullable types" @bind-Value="showNullableTypes" Variant="Variant.Outlined">
<MudSelectItem Value="@("Always")" />
<MudSelectItem Value="@("When Discrepant")" />
<MudSelectItem Value="@("Never")" />
</MudSelect>

<MudDivider />

<MudSwitch @bind-Value="@showErroneous" Color="Color.Primary">
Show erroneous bindings
<MudText Typo="Typo.caption" Class="d-block mud-text-secondary">
Expand Down
20 changes: 15 additions & 5 deletions Client/Pages/Home.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public sealed partial class Home : IDisposable

private IEnumerable<BindingResults> bindingResults = [];

private bool includeNullableTypes = false;
private string showNullableTypes = "When Discrepant";
private bool showErroneous = false;
private bool showDetailedErrorMessages = false;

Expand Down Expand Up @@ -99,13 +99,23 @@ private async Task GetBindingResultsAsync(string inputValue)
bindingResults = results.OrderBy(r => r.AllErroneous);
}

private bool ResultTableFilter(BindingResults r)
private bool ResultTableFilter(BindingResults results)
{
if (!includeNullableTypes && r.Type.EndsWith('?'))
if (!showErroneous && results.AllErroneous)
return false;

if (!showErroneous && r.AllErroneous)
return false;
if (results.Type.EndsWith('?') && showNullableTypes != "Always")
{
if (showNullableTypes == "Never")
return false;

if (showNullableTypes == "When Discrepant")
{
var nonNullableResults = bindingResults.First(r => r.Type == results.Type[..^1]);
if (nonNullableResults.AreEquivalentTo(results))
return false;
}
}

return true;
}
Expand Down
11 changes: 11 additions & 0 deletions Shared/BindingResults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,15 @@ public record BindingResults(

[JsonIgnore]
public bool AllErroneous { get => Results.All(r => r.Value.IsErroneous); }

public bool AreEquivalentTo(BindingResults other)
{
if (Results.Count != other.Results.Count) return false;
foreach (var entry in Results)
{
if (!other.Results.TryGetValue(entry.Key, out var otherValue) || otherValue != entry.Value)
return false;
}
return true;
}
};

0 comments on commit 5a289be

Please sign in to comment.