Skip to content

Commit

Permalink
Use pattern matching to simplify something.
Browse files Browse the repository at this point in the history
  • Loading branch information
catcherwong committed Apr 14, 2018
1 parent 1d664a0 commit 8bb6ac0
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/EasyCaching.ResponseCaching/EasyCachingResponseCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -70,8 +69,7 @@ public async Task<IResponseCacheEntry> GetAsync(string key)

if (entry.HasValue)
{
var val = entry.Value as EasyCachingResponse;
if (val != null)
if (entry.Value is EasyCachingResponse val)
{
return new CachedResponse
{
Expand All @@ -95,8 +93,7 @@ public async Task<IResponseCacheEntry> GetAsync(string key)
/// <param name="validFor">Valid for.</param>
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,
Expand Down Expand Up @@ -127,8 +124,7 @@ public void Set(string key, IResponseCacheEntry entry, TimeSpan validFor)
/// <param name="validFor">Valid for.</param>
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,
Expand Down

0 comments on commit 8bb6ac0

Please sign in to comment.