From 8bb6ac0cb016de0006a4602e5e895c4fb9987ef1 Mon Sep 17 00:00:00 2001 From: catcherwong Date: Sat, 14 Apr 2018 18:43:20 +0800 Subject: [PATCH] Use pattern matching to simplify something. --- .../EasyCachingResponseCache.cs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/EasyCaching.ResponseCaching/EasyCachingResponseCache.cs b/src/EasyCaching.ResponseCaching/EasyCachingResponseCache.cs index 52935184..9b7cafd3 100644 --- a/src/EasyCaching.ResponseCaching/EasyCachingResponseCache.cs +++ b/src/EasyCaching.ResponseCaching/EasyCachingResponseCache.cs @@ -43,8 +43,7 @@ public IResponseCacheEntry Get(string key) if (entry.HasValue) { - var val = entry.Value as EasyCachingResponse; - if (val != null) + if (entry.Value is EasyCachingResponse val) { return new CachedResponse { @@ -70,8 +69,7 @@ public async Task GetAsync(string key) if (entry.HasValue) { - var val = entry.Value as EasyCachingResponse; - if (val != null) + if (entry.Value is EasyCachingResponse val) { return new CachedResponse { @@ -95,8 +93,7 @@ public async Task GetAsync(string key) /// Valid for. public void Set(string key, IResponseCacheEntry entry, TimeSpan validFor) { - var cachedResponse = entry as CachedResponse; - if (cachedResponse != null) + if (entry is CachedResponse cachedResponse) { _provider.Set( key, @@ -127,8 +124,7 @@ public void Set(string key, IResponseCacheEntry entry, TimeSpan validFor) /// Valid for. public async Task SetAsync(string key, IResponseCacheEntry entry, TimeSpan validFor) { - var cachedResponse = entry as CachedResponse; - if (cachedResponse != null) + if (entry is CachedResponse cachedResponse) { await _provider.SetAsync( key,