Skip to content

Commit 4ccfccc

Browse files
Copilotalirezanet
andcommitted
fix: add null check for GetMethod reflection call
Co-authored-by: alirezanet <7004080+alirezanet@users.noreply.github.com>
1 parent 95b35e2 commit 4ccfccc

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/Gridify/GridifyMapper.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,12 @@ private IGridifyMapper<T> AddNestedMapperWithMapperType<TMapper>(
276276

277277
// Call the internal method using reflection
278278
var method = typeof(GridifyMapper<T>)
279-
.GetMethod(nameof(AddNestedMapperInternal), BindingFlags.NonPublic | BindingFlags.Instance)!
280-
.MakeGenericMethod(propertyType);
279+
.GetMethod(nameof(AddNestedMapperInternal), BindingFlags.NonPublic | BindingFlags.Instance);
280+
281+
if (method == null)
282+
throw new InvalidOperationException($"Internal method {nameof(AddNestedMapperInternal)} not found");
283+
284+
method = method.MakeGenericMethod(propertyType);
281285

282286
return (IGridifyMapper<T>)method.Invoke(this, new object?[] { typedLambda, nestedMapper, prefix, overrideIfExists })!;
283287
}

0 commit comments

Comments
 (0)