Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@
<Compile Include="..\..\test\System.Linq.Dynamic.Core.Tests\Helpers\TestEnum.cs">
<Link>Helpers\TestEnum.cs</Link>
</Compile>
<Compile Include="..\..\test\System.Linq.Dynamic.Core.Tests\Helpers\Models\UserProfileDetails.cs">
<Link>Helpers\Models\UserProfileDetails.cs</Link>
</Compile>
<Compile Include="..\..\test\System.Linq.Dynamic.Core.Tests\Helpers\Models\UserState.cs">
<Link>Helpers\Models\UserState.cs</Link>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/System.Linq.Dynamic.Core/DynamicExpressionParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public static LambdaExpression ParseLambda([NotNull] Type itType, [CanBeNull] Ty
[PublicAPI]
public static LambdaExpression ParseLambda([CanBeNull] ParsingConfig parsingConfig, [NotNull] Type itType, [CanBeNull] Type resultType, string expression, params object[] values)
{
return ParseLambda(true, itType, resultType, expression, parsingConfig, values);
return ParseLambda(parsingConfig, true, itType, resultType, expression, values);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ public class ComplexParseLambda3Result
public int TotalIncome { get; set; }
}

public class CustomClassWithStaticMethod
{
public static int GetAge(int x) => x;
}

private class TestCustomTypeProvider : AbstractDynamicLinqCustomTypeProvider, IDynamicLinkCustomTypeProvider
{
private HashSet<Type> _customTypes;
Expand All @@ -44,6 +49,7 @@ public virtual HashSet<Type> GetCustomTypes()
}

_customTypes = new HashSet<Type>(FindTypesMarkedWithDynamicLinqTypeAttribute(new[] { GetType().GetTypeInfo().Assembly }));
_customTypes.Add(typeof(CustomClassWithStaticMethod));
return _customTypes;
}
}
Expand Down Expand Up @@ -413,5 +419,27 @@ public void ParseLambda_IllegalMethodCall_ThrowsException()
})
.Throws<ParseException>().WithMessage("Methods on type 'Stream' are not accessible");
}

[Fact]
public void ParseLambda_CustomMethod()
{
var config = new ParsingConfig
{
CustomTypeProvider = new TestCustomTypeProvider()
};

var context = new CustomClassWithStaticMethod();
var original = $"{nameof(CustomClassWithStaticMethod)}.{nameof(CustomClassWithStaticMethod.GetAge)}(10)";
int result = 0;
Check.ThatCode(() =>
{
var expression = System.Linq.Dynamic.Core.DynamicExpressionParser.ParseLambda(config, typeof(CustomClassWithStaticMethod), null, original);
Delegate del = expression.Compile();
result = (int) del.DynamicInvoke(context);
})
.DoesNotThrow();

Check.That(result).IsEqualTo(10);
}
}
}