Skip to content

Commit

Permalink
refactor: Use is (not) null
Browse files Browse the repository at this point in the history
  • Loading branch information
linkdotnet committed Mar 1, 2024
1 parent 81165c0 commit 4107baa
Show file tree
Hide file tree
Showing 14 changed files with 24 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ public ValueTask<IPagedList<TProjection>> GetAllByProjectionAsync<TProjection>(
{
ArgumentNullException.ThrowIfNull(selector);
var result = entities.AsEnumerable();
if (filter != null)
if (filter is not null)
{
result = result.Where(filter.Compile());
}

if (orderBy != null)
if (orderBy is not null)
{
result = descending
? result.OrderByDescending(orderBy.Compile())
Expand All @@ -64,7 +64,7 @@ public ValueTask StoreAsync(TEntity entity)
}

var entry = entities.SingleOrDefault(b => b.Id == entity.Id);
if (entry != null)
if (entry is not null)
{
entities.Remove(entry);
}
Expand All @@ -76,7 +76,7 @@ public ValueTask StoreAsync(TEntity entity)
public ValueTask DeleteAsync(string id)
{
var blogPostToDelete = entities.SingleOrDefault(b => b.Id == id);
if (blogPostToDelete != null)
if (blogPostToDelete is not null)
{
entities.Remove(blogPostToDelete);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ public async ValueTask<IPagedList<TProjection>> GetAllByProjectionAsync<TProject
{
var query = Collection.AsQueryable();

if (filter != null)
if (filter is not null)
{
query = query.Where(filter);
}

if (orderBy != null)
if (orderBy is not null)
{
query = descending ? query.OrderByDescending(orderBy) : query.OrderBy(orderBy);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ public async ValueTask<IPagedList<TProjection>> GetAllByProjectionAsync<TProject
using var session = documentStore.OpenAsyncSession();

var query = session.Query<TEntity>();
if (filter != null)
if (filter is not null)
{
query = query.Where(filter);
}

if (orderBy != null)
if (orderBy is not null)
{
query = descending
? query.OrderByDescending(orderBy)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ public async ValueTask<IPagedList<TProjection>> GetAllByProjectionAsync<TProject
var blogDbContext = await dbContextFactory.CreateDbContextAsync();
var entity = blogDbContext.Set<TEntity>().AsNoTracking().AsQueryable();

if (filter != null)
if (filter is not null)
{
entity = entity.Where(filter);
}

if (orderBy != null)
if (orderBy is not null)
{
entity = descending
? entity.OrderByDescending(orderBy)
Expand Down Expand Up @@ -97,7 +97,7 @@ public async ValueTask StoreAsync(TEntity entity)
public async ValueTask DeleteAsync(string id)
{
var entityToDelete = await GetByIdAsync(id);
if (entityToDelete != null)
if (entityToDelete is not null)
{
var blogDbContext = await dbContextFactory.CreateDbContextAsync();
blogDbContext.Remove(entityToDelete);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ OnYesPressed="DeleteItem"></ConfirmDialog>

private async Task HandleDrop(ProfileInformationEntry dropTarget)
{
if (currentDragItem == null || dropTarget == currentDragItem)
if (currentDragItem is null || dropTarget == currentDragItem)
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@

private async Task HandleDrop(ProficiencyLevel proficiencyLevel)
{
if (currentDragItem == null || currentDragItem.ProficiencyLevel == proficiencyLevel)
if (currentDragItem is null || currentDragItem.ProficiencyLevel == proficiencyLevel)
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
<label for="tags">Tags</label>
<InputText class="form-control" id="tags" @bind-Value="model.Tags"/>
</div>
@if (BlogPost != null && !IsScheduled)
@if (BlogPost is not null && !IsScheduled)
{
<div class="form-check">
<InputCheckbox class="form-check-input" id="updatedate" @bind-Value="model.ShouldUpdateDate" />
Expand Down Expand Up @@ -117,7 +117,7 @@

protected override void OnParametersSet()
{
if (BlogPost == null)
if (BlogPost is null)
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@inject IRepository<BlogPost> BlogPostRepository
@inject IToastService ToastService

@if (blogPostFromDb != null)
@if (blogPostFromDb is not null)
{
<CreateNewBlogPost
Title="Update BlogPost"
Expand Down Expand Up @@ -38,4 +38,4 @@ else
await BlogPostRepository.StoreAsync(blogPostFromDb);
ToastService.ShowInfo($"Updated BlogPost {blogPost.Title}");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<div class="card-body">
<div class="row">
<DateRangeSelector FilterChanged="RefreshVisitCount"></DateRangeSelector>
@if (visitData != null)
@if (visitData is not null)
{
<p id="total-clicks">@visitData.Sum(c => c.ClickCount) clicks in total</p>
}
Expand All @@ -31,7 +31,7 @@
<th>Clicks</th>
<th>Likes</th>
</tr>
@if (visitData != null)
@if (visitData is not null)
{
@foreach (var date in visitData)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
{
<Loading></Loading>
}
@if (sitemapUrlSet != null)
@if (sitemapUrlSet is not null)
{
<table class="table table-striped table-hover h-50">
<thead>
Expand Down
2 changes: 1 addition & 1 deletion src/LinkDotNet.Blog.Web/Features/Archive/ArchivePage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<div class="ps-2">
<h3 class="pb-3">Archive (@blogPostCount posts)</h3>

@if (blogPostsPerYear == null)
@if (blogPostsPerYear is null)
{
<Loading></Loading>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ else
<h1>@BlogPost.Title</h1></header>
<div class="blogpost-metainformation d-flex flex-row flex-wrap gap-2">
<div><span class="date"></span><span class="ms-1">@BlogPost.UpdatedDate.ToString("dd/MM/yyyy")</span></div>
@if (BlogPost.Tags != null && BlogPost.Tags.Any())
@if (BlogPost.Tags is not null && BlogPost.Tags.Any())
{
<span class="blogpost-tag d-inline-block">
@foreach (var tag in BlogPost.Tags)
Expand Down
2 changes: 1 addition & 1 deletion tests/LinkDotNet.Blog.IntegrationTests/SmokeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public async Task ShouldAllowDotsForFreeTextSearch()

public async ValueTask DisposeAsync()
{
if (factory != null)
if (factory is not null)
{
await factory.DisposeAsync();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private static void AssertMetaTagExistsWithValue(
titleMeta.Should().NotBeNull();
var titleMetaTag = (IHtmlMetaElement)titleMeta;
titleMetaTag.Content.Should().Be(metaTagValue);
if (ogPropertyName != null)
if (ogPropertyName is not null)
{
titleMetaTag.Attributes.Any(a => a.Value == ogPropertyName).Should().BeTrue();
}
Expand Down

0 comments on commit 4107baa

Please sign in to comment.