Skip to content

Commit

Permalink
chore: change all occurence of == null to is null
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Pluskal committed Feb 7, 2024
1 parent 10ed8c5 commit 1d127bd
Show file tree
Hide file tree
Showing 27 changed files with 30 additions and 30 deletions.
2 changes: 1 addition & 1 deletion Lectures/Lecture_02/Lecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -1153,7 +1153,7 @@ class Test
{
static void Display(string name)
{
if(name == null)
if(name is null)
throw new ArgumentNullException(nameof(name));
Console.WriteLine(name);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ public void DefaultIfEmptyTest()
int[] emptyInt = { };
string[] words = { "one", "two", "three" };

Assert.True(emptyStr.DefaultIfEmpty().First() == null);
Assert.True(emptyStr.DefaultIfEmpty().First() is null);
Assert.True(emptyInt.DefaultIfEmpty().First() == 0);
Assert.False(words.DefaultIfEmpty() == null);
Assert.False(words.DefaultIfEmpty() is null);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ public void DefaultIfEmptyTest()
int[] emptyInt = { };
string[] words = { "one", "two", "three" };

Assert.True(emptyStr.DefaultIfEmpty().First() == null);
Assert.True(emptyStr.DefaultIfEmpty().First() is null);
Assert.True(emptyInt.DefaultIfEmpty().First() == 0);
Assert.False(words.DefaultIfEmpty() == null);
Assert.False(words.DefaultIfEmpty() is null);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public IEnumerable<AddressDetailModel> Map(IQueryable<AddressEntity> entities)
=> entities?.Select(entity => Map(entity)).ToValueCollection();

public AddressDetailModel Map(AddressEntity entity)
=> entity == null? null : new AddressDetailModel
=> entity is null? null : new AddressDetailModel
{
Id = entity.Id,
City = entity.City,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public IEnumerable<CourseListModel> Map(IQueryable<CourseEntity> entities)
}).ToValueCollection();

public CourseDetailModel Map(CourseEntity entity)
=> entity == null
=> entity is null
? null
: new CourseDetailModel
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public GradeListModel MapListModel(GradeEntity entity) =>
};

public GradeDetailModel Map(GradeEntity entity)
=> entity == null
=> entity is null
? null
: new GradeDetailModel
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public IEnumerable<StudentListModel> Map(IQueryable<StudentEntity> entities)
}).ToValueCollection();
}

public StudentDetailModel Map(StudentEntity entity) => entity == null
public StudentDetailModel Map(StudentEntity entity) => entity is null
? null
: new StudentDetailModel
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class EntityFactory : IEntityFactory
.Entries<TEntity>()
.SingleOrDefault(i => i.Entity.Id == id)
?.Entity;
if (entity == null)
if (entity is null)
{
entity = new TEntity { Id = id };
_changeTracker?.Context.Attach(entity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private void SynchronizeCollections(TEntity entity)
}

var entityInDb = GetById(entity.Id);
if (entityInDb == null) return;
if (entityInDb is null) return;

foreach (var collectionSelector in toBeSynchronized)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public IEnumerable<AddressDetailModel> Map(IQueryable<AddressEntity> entities)
=> entities?.Select(entity => Map(entity)).ToValueCollection();

public AddressDetailModel Map(AddressEntity entity)
=> entity == null? null : new AddressDetailModel
=> entity is null? null : new AddressDetailModel
{
Id = entity.Id,
City = entity.City,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public IEnumerable<CourseListModel> Map(IQueryable<CourseEntity> entities)
}).ToValueCollection();

public CourseDetailModel Map(CourseEntity entity)
=> entity == null
=> entity is null
? null
: new CourseDetailModel
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public GradeListModel MapListModel(GradeEntity entity) =>
};

public GradeDetailModel Map(GradeEntity entity)
=> entity == null
=> entity is null
? null
: new GradeDetailModel
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public IEnumerable<StudentListModel> Map(IQueryable<StudentEntity> entities)
}).ToValueCollection();
}

public StudentDetailModel Map(StudentEntity entity) => entity == null
public StudentDetailModel Map(StudentEntity entity) => entity is null
? null
: new StudentDetailModel
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class EntityFactory : IEntityFactory
.Entries<TEntity>()
.SingleOrDefault(i => i.Entity.Id == id)
?.Entity;
if (entity == null)
if (entity is null)
{
entity = new TEntity { Id = id };
_changeTracker?.Context.Attach(entity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private void SynchronizeCollections(TEntity entity)
}

var entityInDb = GetById(entity.Id);
if (entityInDb == null) return;
if (entityInDb is null) return;

foreach (var collectionSelector in toBeSynchronized)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class NullToVisibilityConverter : IValueConverter
{
public object Convert(object? value, Type targetType, object parameter, CultureInfo culture)
{
return value == null ? Visibility.Collapsed : Visibility.Visible;
return value is null ? Visibility.Collapsed : Visibility.Visible;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private void Delete()

private void Save()
{
if (Model == null)
if (Model is null)
{
throw new InvalidOperationException("Null model cannot be saved");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public async Task LoadAsync(Guid id)

public async Task SaveAsync()
{
if (Model == null)
if (Model is null)
{
throw new InvalidOperationException("Null model cannot be saved");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private void SelectRecipe(Guid? id)
else
{
var recipeDetailViewModel = RecipeDetailViewModels.SingleOrDefault(vm => vm.Model?.Id == id);
if (recipeDetailViewModel == null)
if (recipeDetailViewModel is null)
{
recipeDetailViewModel = _recipeDetailViewModelFactory.Create();
RecipeDetailViewModels.Add(recipeDetailViewModel);
Expand All @@ -135,7 +135,7 @@ private void SelectIngredient(Guid? id)
{
var ingredientDetailViewModel =
IngredientDetailViewModels.SingleOrDefault(vm => vm.Model?.Id == id);
if (ingredientDetailViewModel == null)
if (ingredientDetailViewModel is null)
{
ingredientDetailViewModel = _ingredientDetailViewModelFactory.Create();
IngredientDetailViewModels.Add(ingredientDetailViewModel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public async Task DeleteAsync()

public async Task SaveAsync()
{
if (Model == null)
if (Model is null)
{
throw new InvalidOperationException("Null model cannot be saved");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public abstract class ModelWrapper<T> : ViewModelBase, IModel, IValidatableObjec
{
protected ModelWrapper(T? model)
{
if (model == null)
if (model is null)
{
throw new ArgumentNullException(nameof(model));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public string? ImageUrl

private void InitializeCollectionProperties(RecipeDetailModel model)
{
if (model.Ingredients == null)
if (model.Ingredients is null)
{
throw new ArgumentException("Ingredients cannot be null");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static async Task PreLoadChangeTracker<TEntity>(this IQueryable<TEntity>
public static IQueryable<TEntity> IncludeFirstLevelNavigationProperties<TEntity>(this IQueryable<TEntity> query, Microsoft.EntityFrameworkCore.Metadata.IModel model) where TEntity : class
{
var navigationProperties = model.FindEntityType(typeof(TEntity))?.GetNavigations();
if (navigationProperties == null)
if (navigationProperties is null)
return query;

foreach (var navigationProperty in navigationProperties)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public ValueProviderAttribute([NotNull] string name)
/// </summary>
/// <example><code>
/// void Foo(string param) {
/// if (param == null)
/// if (param is null)
/// throw new ArgumentNullException("par"); // Warning: Cannot resolve symbol
/// }
/// </code></example>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public ValueProviderAttribute([NotNull] string name)
/// </summary>
/// <example><code>
/// void Foo(string param) {
/// if (param == null)
/// if (param is null)
/// throw new ArgumentNullException("par"); // Warning: Cannot resolve symbol
/// }
/// </code></example>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1d127bd

Please sign in to comment.