diff --git a/Client/Pages/Home.razor b/Client/Pages/Home.razor index 9f8924c..02f5f2a 100644 --- a/Client/Pages/Home.razor +++ b/Client/Pages/Home.razor @@ -36,9 +36,14 @@ - - Include nullable types - + + + + + + + + Show erroneous bindings diff --git a/Client/Pages/Home.razor.cs b/Client/Pages/Home.razor.cs index 48525b7..ff48193 100644 --- a/Client/Pages/Home.razor.cs +++ b/Client/Pages/Home.razor.cs @@ -30,7 +30,7 @@ public sealed partial class Home : IDisposable private IEnumerable bindingResults = []; - private bool includeNullableTypes = false; + private string showNullableTypes = "When Discrepant"; private bool showErroneous = false; private bool showDetailedErrorMessages = false; @@ -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; } diff --git a/Shared/BindingResults.cs b/Shared/BindingResults.cs index ab4b5eb..0a7d6e2 100644 --- a/Shared/BindingResults.cs +++ b/Shared/BindingResults.cs @@ -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; + } };