Closed Magnus12 closed 1 year ago
@Magnus12 I can remove the restriction for only using it on classes and structs.
@Magnus12
I've update the attribute and created this this test:
[DynamicLinqType]
public interface ICustomInterfaceWithMethodWithDynamicLinqTypeAttribute
{
int GetAge(int x);
}
public class CustomClassImplementingInterface : ICustomInterfaceWithMethodWithDynamicLinqTypeAttribute
{
public int GetAge(int x) => x;
}
// Arrange
var context = new CustomClassImplementingInterface();
var expression = $"{nameof(ICustomInterfaceWithMethodWithDynamicLinqTypeAttribute.GetAge)}(10)";
// Act
var lambdaExpression = DynamicExpressionParser.ParseLambda(typeof(ICustomInterfaceWithMethodWithDynamicLinqTypeAttribute), null, expression);
var del = lambdaExpression.Compile();
var result = (int?)del.DynamicInvoke(context);
// Assert
result.Should().Be(10);
This is what you need?
(https://github.com/zzzprojects/System.Linq.Dynamic.Core/pull/750)
Great! Thank you!
The
DynamicLinqType
attribute can not be added to interfaces. If I have a field in a class that is of type interface:private readonly IExternalMethod externalMethod;
Interface and implementation:
Trying to run functions on that with dynamic linq does not work even in the implementing class of the interface has the
DynamicLinqType
attribute.