Skip to content

Commit 7f6431f

Browse files
author
Chris Santero
committed
add null checks in ResourceTypeRegistration
1 parent c96ec02 commit 7f6431f

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

JSONAPI/Core/ResourceTypeRegistration.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.Linq;
55
using System.Linq.Expressions;
66
using System.Reflection;
7-
using JSONAPI.Http;
87

98
namespace JSONAPI.Core
109
{
@@ -22,6 +21,9 @@ internal ResourceTypeRegistration(Type type, PropertyInfo idProperty, string res
2221
Func<ParameterExpression, string, BinaryExpression> filterByIdExpressionFactory,
2322
Func<ParameterExpression, Expression> sortByIdExpressionFactory)
2423
{
24+
if (type == null) throw new ArgumentNullException(nameof(type));
25+
if (idProperty == null) throw new ArgumentNullException(nameof(idProperty));
26+
if (resourceTypeName == null) throw new ArgumentNullException(nameof(resourceTypeName));
2527
IdProperty = idProperty;
2628
Type = type;
2729
ResourceTypeName = resourceTypeName;
@@ -44,11 +46,13 @@ internal ResourceTypeRegistration(Type type, PropertyInfo idProperty, string res
4446

4547
public string GetIdForResource(object resource)
4648
{
49+
if (resource == null) throw new ArgumentNullException(nameof(resource));
4750
return IdProperty.GetValue(resource).ToString();
4851
}
4952

5053
public void SetIdForResource(object resource, string id)
5154
{
55+
if (resource == null) throw new ArgumentNullException(nameof(resource));
5256
IdProperty.SetValue(resource, id); // TODO: handle classes with non-string ID types
5357
}
5458

0 commit comments

Comments
 (0)