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

How do you handle parentheses when building the expression? #10

Closed
natiki opened this issue Aug 25, 2017 · 2 comments
Closed

How do you handle parentheses when building the expression? #10

natiki opened this issue Aug 25, 2017 · 2 comments
Assignees

Comments

@natiki
Copy link

natiki commented Aug 25, 2017

Hey Dave,

Nice little library. Just wondering how you would approach building in parenthesis?

@dbelmont
Copy link
Owner

dbelmont commented Sep 6, 2017

Hi natiki,

I'm taking a look into it and may have found a way to implement it. But, as I'm still not sure of it, would you mind helping me think of examples where that approach would be useful? I'm struggling a bit to find valid test cases that I could use.

The best that I could come up with so far was this:

var company = new Person.Company { Name = "Back to the future", Industry = "Time Traveling Agency" };

People = new List<Person>
{
        new Person { Name = "John Doe", Gender = PersonGender.Male, Birth = new Person.BirthData { Date = new DateTime(1979, 2, 28), Country = "USA" }, Employer = company },
        new Person { Name = "Jane Doe", Gender = PersonGender.Female, Birth = new Person.BirthData { Date = DateTime.Now.AddYears(-16), Country = " " } },
        new Person { Name = "Wade Wilson", Gender = PersonGender.Male, Birth = new Person.BirthData { Date = new DateTime(1973, 10, 9), Country = "USA" } },
        new Person { Name = "Jessica Jones", Gender = PersonGender.Female, Birth = new Person.BirthData { Date = DateTime.Now.AddYears(-16), Country = "USA" } },
        new Person { Name = "Jane Jones", Gender = PersonGender.Female, Birth = new Person.BirthData { Date = new DateTime(1980, 12, 20), Country = "USA" } },
        new Person { Name = "Fulano Silva", Gender = PersonGender.Male, Birth = new Person.BirthData { Date = new DateTime(1983, 5, 10), Country = "BRA" }, Employer = company },
        new Person { Name = "Fulana da Silva", Gender = PersonGender.Male, Birth = new Person.BirthData { Date = DateTime.Now.AddYears(-16), Country = "BRA" } },
        new Person { Name = "John Hancock", Gender = PersonGender.Male, Employer = company }
};

var eighteenYearsAgo = DateTime.Now.AddYears(-18);
//Selecting people younger than 18 years in USA and older than 18 in BRA at once
People.Where(p => ((p.Birth != null && p.Birth.Date != null && p.Birth.Date > eighteenYearsAgo) && p.Birth.Country == "USA")
                || ((p.Birth != null && p.Birth.Date != null && p.Birth.Date < eighteenYearsAgo) && p.Birth.Country == "BRA"));

What do you reckon? Could you think of something else?

Many thanks,
David

@dbelmont dbelmont self-assigned this Sep 6, 2017
@dbelmont
Copy link
Owner

dbelmont commented Dec 6, 2017

Hi Donovan,

I uploaded a release candidate version to NuGet today that finally has support for "complex expressions" (parentheses handling).

If you add the reference through the "Manage NuGet packages" option in Visual Studio, don't forget to tick the "Include prerelease" option (otherwise, this version won't be listed).

Many thanks,
David

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

No branches or pull requests

2 participants