Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The DynamicLinqType attribute can not be added to interfaces. #745

Closed
Magnus12 opened this issue Sep 12, 2023 · 3 comments
Closed

The DynamicLinqType attribute can not be added to interfaces. #745

Magnus12 opened this issue Sep 12, 2023 · 3 comments
Assignees
Labels

Comments

@Magnus12
Copy link

Magnus12 commented Sep 12, 2023

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:

    public interface IExternalMethod 
    {
        int Run();
    }
    
    [DynamicLinqType]
    public class ExternalMethod : IExternalMethod
    {
        public int Run() => 1;
    }

Trying to run functions on that with dynamic linq does not work even in the implementing class of the interface has the DynamicLinqType attribute.

@StefH StefH self-assigned this Sep 19, 2023
@StefH
Copy link
Collaborator

StefH commented Sep 19, 2023

@Magnus12
I can remove the restriction for only using it on classes and structs.

@StefH StefH added the refactor label Sep 19, 2023
@StefH
Copy link
Collaborator

StefH commented Oct 14, 2023

@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?

(#750)

@Magnus12
Copy link
Author

Great! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants