Skip to content

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

@StefH

Description

@StefH
    [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'

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions