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

Accessing static property or field in normal class does not work #873

Closed
StefH opened this issue Jan 23, 2025 · 1 comment · Fixed by #874
Closed

Accessing static property or field in normal class does not work #873

StefH opened this issue Jan 23, 2025 · 1 comment · Fixed by #874
Assignees
Labels

Comments

@StefH
Copy link
Collaborator

StefH commented Jan 23, 2025

    [Theory]
    [InlineData("Prop", "TestProp")]
    [InlineData("Field", "TestField")]
    public void Parse_StaticPropertyOrField_In_NonStaticClass1(string name, string value)
    {
        // Arrange
        var ints = new int[1].AsQueryable();

        // Act
        var result = ints.Select<string>($"new {typeof(NonStaticClassExample)}().{name}").First();

        // Assert
        Assert.Equal(value, result);
    }

    [Theory]
    [InlineData("Prop", "TestProp")]
    [InlineData("Field", "TestField")]
    public void Parse_StaticPropertyOrField_In_NonStaticClass2(string name, string value)
    {
        // Arrange
        var ints = new NonStaticClassExample[] { new NonStaticClassExample() }.AsQueryable();

        // Act
        var result = ints.Select<string>(name).First();

        // Assert
        Assert.Equal(value, result);
    }
}

[DynamicLinqType]
public class NonStaticClassExample
{
    public static string Prop { get; set; } = "TestProp";

    public static string Field = "TestField";
}

Both tests throw:

System.Linq.Dynamic.Core.Exceptions.ParseException : No property or field 'Field' exists in type 'NonStaticClassExample'
System.Linq.Dynamic.Core.Exceptions.ParseException : No property or field 'Prop' exists in type 'NonStaticClassExample'
@StefH StefH self-assigned this Jan 23, 2025
@StefH StefH added the bug label Jan 23, 2025
@StefH
Copy link
Collaborator Author

StefH commented Jan 23, 2025

#874

@StefH StefH closed this as completed Jan 23, 2025
@StefH StefH linked a pull request Jan 23, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

1 participant