Skip to content

Commit

Permalink
Custom method can now have nullable parameters and nullable arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
bjelbo committed Dec 16, 2024
1 parent d0b2f76 commit 8106120
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ private Expression BindCustomMethodExpressionOrNull(SingleValueFunctionCallNode
MethodInfo methodInfo;
if (UriFunctionsBinder.TryGetMethodInfo(node.Name, methodArgumentsType, out methodInfo))
{
return ExpressionBinderHelper.MakeFunctionCall(methodInfo, QuerySettings, arguments);
return ExpressionBinderHelper.MakeCustomFunctionCall(methodInfo, arguments);
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,27 @@ public static Expression MakeFunctionCall(MemberInfo member, ODataQuerySettings
return CreateFunctionCallWithNullPropagation(functionCall, arguments, querySettings);
}

public static Expression CreateFunctionCallWithNullPropagation(Expression functionCall, Expression[] arguments, ODataQuerySettings querySettings)
{
if (querySettings.HandleNullPropagation == HandleNullPropagationOption.True)
//Custom methods might contain nullable parameters and, therefore, also should be able to take arguments of type Nullable<T>
public static Expression MakeCustomFunctionCall(MethodInfo method, params Expression[] arguments)
{
Expression functionCall;
if (method.IsStatic)
{
functionCall = Expression.Call(null, method, arguments);
}
else
{
functionCall = Expression.Call(arguments.First(), method, arguments.Skip(1));
}

return functionCall;
}

public static Expression CreateFunctionCallWithNullPropagation(Expression functionCall, Expression[] arguments, ODataQuerySettings querySettings)
{
Expression test = CheckIfArgumentsAreNull(arguments);
if (querySettings.HandleNullPropagation == HandleNullPropagationOption.True)
{
Expression test = CheckIfArgumentsAreNull(arguments);

if (test == FalseConstant)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -754,12 +754,12 @@ protected virtual Expression BindCustomMethodExpressionOrNull(SingleValueFunctio
Expression[] arguments = BindArguments(node.Parameters, context);
IEnumerable<Type> methodArgumentsType = arguments.Select(argument => argument.Type);

// Search for custom method info that are binded to the node name
MethodInfo methodInfo;
if (UriFunctionsBinder.TryGetMethodInfo(node.Name, methodArgumentsType, out methodInfo))
{
return ExpressionBinderHelper.MakeFunctionCall(methodInfo, context.QuerySettings, arguments);
}
// Search for custom method info that are binded to the node name
MethodInfo methodInfo;
if (UriFunctionsBinder.TryGetMethodInfo(node.Name, methodArgumentsType, out methodInfo))
{
return ExpressionBinderHelper.MakeCustomFunctionCall(methodInfo, arguments);
}

return null;
}
Expand Down

0 comments on commit 8106120

Please sign in to comment.