Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/DynamicExpresso.Core/Resolution/MethodResolution.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,12 @@ public static bool CheckIfMethodIsApplicableAndPrepareIt(MethodData method, Expr
if (parameter.HasDefaultValue)
{
var parameterType = TypeUtils.GetConcreteTypeForGenericMethod(parameter.ParameterType, promotedArgs, method);
promotedArgs.Add(Expression.Constant(parameter.DefaultValue, parameterType));

var defaultValue = parameter.DefaultValue;
if (defaultValue is null && parameterType.IsValueType)
defaultValue = Activator.CreateInstance(parameterType);

promotedArgs.Add(Expression.Constant(defaultValue, parameterType));
}
else if (ReflectionExtensions.HasParamsArrayType(parameter))
{
Expand Down
14 changes: 14 additions & 0 deletions test/DynamicExpresso.UnitTest/GithubIssues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,11 @@ public List<int> Add(List<int> list, Func<int, int> transform)
{
return list.Select(i => transform(i)).ToList();
}

public Guid ReturnsGuid(Guid guid = default)
{
return guid;
}
}

[Test]
Expand Down Expand Up @@ -877,6 +882,15 @@ public void GitHub_Issue_341()

Assert.That(interpreter.Eval<bool>("(int)x == 1"), Is.EqualTo((int)x == 1));
}

[Test]
public void GitHub_Issue_354()
{
var interpreter = new Interpreter();
interpreter.SetVariable("b", new Functions());

Assert.That(interpreter.Eval<Guid>("b.ReturnsGuid()"), Is.EqualTo(Guid.Empty));
}
}

internal static class GithubIssuesTestExtensionsMethods
Expand Down
Loading