From 481562421f202b90d094ab77df5d84e599e6beb3 Mon Sep 17 00:00:00 2001 From: ewdlop Date: Thu, 28 Mar 2024 22:53:09 -0400 Subject: [PATCH] Add more null checks --- Program.cs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/Program.cs b/Program.cs index 6bd5cf8..c9c3679 100644 --- a/Program.cs +++ b/Program.cs @@ -121,6 +121,7 @@ patchOperationList.AddMove("test", "test2"); patchOperationList.AddRemove("test2"); patchOperationList.AddReplace("age", 55); +//patchOperationList.AddSet((object)null); //throws ArgumentNullException patchOperationList3.Add(PatchOperation.Move("/from", "/to"), PatchOperation.Move("/here", "/there")); IList patchOperations2 = new PatchOperationList(); @@ -303,7 +304,11 @@ public void Add(JsonPatchDocument jsonPatchDocument) public void Add(List operations) => _patchOperations.Add(operations); public void Add(T entity) - where T : class => _patchOperations.Add(entity); + where T : class + { + ArgumentNullException.ThrowIfNull(entity, nameof(entity)); + _patchOperations.Add(entity); + } public void Add(IEnumerable entities) where T : class => _patchOperations.Add(entities); @@ -324,7 +329,11 @@ public void Add(params T[] entities) } } - public void Add(object value, Func? propertyInfoFilter = null) => _patchOperations.Add(value, propertyInfoFilter); + public void Add(object value, Func? propertyInfoFilter = null) + { + ArgumentNullException.ThrowIfNull(value, nameof(value)); + _patchOperations.Add(value, propertyInfoFilter); + } public void AddAppend(string path, object? value) => _patchOperations.AddAppend(path, value); @@ -347,7 +356,11 @@ public void AddSet(JObject value) } public void AddSet(T entity) - where T : class => _patchOperations.AddSet(entity); + where T : class + { + ArgumentNullException.ThrowIfNull(entity, nameof(entity)); + _patchOperations.AddSet(entity); + } public void AddSet(IEnumerable entities) where T : class => _patchOperations.AddSet(entities);