From d2558309df97f2e921b4034cfd6e45b717e8cef5 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Sun, 7 Apr 2024 19:59:02 +1000 Subject: [PATCH] Remove redundant containskey (#156) * remove redundant containskey * . --- src/Alba/Internal/LightweightCache.cs | 19 ++----------------- .../Pages/Diagnostics/ViewModel.cs | 3 +-- 2 files changed, 3 insertions(+), 19 deletions(-) diff --git a/src/Alba/Internal/LightweightCache.cs b/src/Alba/Internal/LightweightCache.cs index f072571a..22ae4a36 100644 --- a/src/Alba/Internal/LightweightCache.cs +++ b/src/Alba/Internal/LightweightCache.cs @@ -85,14 +85,7 @@ public TValue this[TKey key] } set { - if (_values.ContainsKey(key)) - { - _values[key] = value; - } - else - { - _values.Add(key, value); - } + _values[key] = value; } } @@ -128,15 +121,7 @@ public void Fill(TKey key, TValue value) public bool TryRetrieve(TKey key, [MaybeNullWhen(false)] out TValue value) { - value = default; - - if (_values.ContainsKey(key)) - { - value = _values[key]; - return true; - } - - return false; + return _values.TryGetValue(key, out value); } public void Each(Action action) diff --git a/src/IdentityServer.New/Pages/Diagnostics/ViewModel.cs b/src/IdentityServer.New/Pages/Diagnostics/ViewModel.cs index 4be98627..ec29904e 100644 --- a/src/IdentityServer.New/Pages/Diagnostics/ViewModel.cs +++ b/src/IdentityServer.New/Pages/Diagnostics/ViewModel.cs @@ -15,9 +15,8 @@ public ViewModel(AuthenticateResult result) { AuthenticateResult = result; - if (result.Properties.Items.ContainsKey("client_list")) + if (result.Properties.Items.TryGetValue("client_list", out var encoded)) { - var encoded = result.Properties.Items["client_list"]; var bytes = Base64Url.Decode(encoded); var value = Encoding.UTF8.GetString(bytes);