Skip to content

Commit

Permalink
Add more null checks
Browse files Browse the repository at this point in the history
  • Loading branch information
ewdlop committed Mar 29, 2024
1 parent a29a012 commit 4815624
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
patchOperationList.AddMove("test", "test2");
patchOperationList.AddRemove("test2");
patchOperationList.AddReplace("age", 55);
//patchOperationList.AddSet<object>((object)null); //throws ArgumentNullException

patchOperationList3.Add(PatchOperation.Move("/from", "/to"), PatchOperation.Move("/here", "/there"));
IList<PatchOperation> patchOperations2 = new PatchOperationList();
Expand Down Expand Up @@ -303,7 +304,11 @@ public void Add(JsonPatchDocument jsonPatchDocument)
public void Add(List<PatchOperation> operations) => _patchOperations.Add(operations);

public void Add<T>(T entity)
where T : class => _patchOperations.Add(entity);
where T : class
{
ArgumentNullException.ThrowIfNull(entity, nameof(entity));
_patchOperations.Add(entity);
}

public void Add<T>(IEnumerable<T> entities)
where T : class => _patchOperations.Add(entities);
Expand All @@ -324,7 +329,11 @@ public void Add<T>(params T[] entities)
}
}

public void Add(object value, Func<PropertyInfo, bool>? propertyInfoFilter = null) => _patchOperations.Add(value, propertyInfoFilter);
public void Add(object value, Func<PropertyInfo, bool>? propertyInfoFilter = null)
{
ArgumentNullException.ThrowIfNull(value, nameof(value));
_patchOperations.Add(value, propertyInfoFilter);
}

public void AddAppend(string path, object? value) => _patchOperations.AddAppend(path, value);

Expand All @@ -347,7 +356,11 @@ public void AddSet(JObject value)
}

public void AddSet<T>(T entity)
where T : class => _patchOperations.AddSet(entity);
where T : class
{
ArgumentNullException.ThrowIfNull(entity, nameof(entity));
_patchOperations.AddSet(entity);
}

public void AddSet<T>(IEnumerable<T> entities)
where T : class => _patchOperations.AddSet(entities);
Expand Down

0 comments on commit 4815624

Please sign in to comment.