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

Fluent interface #22

Open
jamescurran opened this issue Apr 3, 2020 · 3 comments
Open

Fluent interface #22

jamescurran opened this issue Apr 3, 2020 · 3 comments

Comments

@jamescurran
Copy link
Contributor

I've been working on a alternate fluent/expression interface for creating rules. Basically, what you'd now write as

Rule rule = Rule.Create("Status", mreOperator.Equal, Status.Open);

you could now write as

Rule rule = Rule<Order>.Create(x=>x.Status).Equals(Status.Open);

By specifying the member as a lambda function, it verifies at coding time that the property exists on the source object, and even gives you Intellisense so you can't misspell it. It also verifies that the target value is the right type. (And it produces standard Rule objects, so you can mix & match the different syntaxes)

So, syntax question: Which do you prefer??

A) Rule rule = Rule<Order>.Create(x=>x.Status).Equals(Status.Open);

B) Rule rule = Rule<Order>.Equals(x=>x.Status, Status.Open);

One part of me prefers the shorter syntax of B), but another part prefers the way A have the operation between the member and the target.

@runxc1
Copy link
Owner

runxc1 commented Apr 3, 2020

So I don't ever write the rules in code but instead have more of a query builder web UI that I use to build them but as far as syntax goes I'd vote foe B as it seems similar to they syntax in other libraries I've used such as that of the MongoDB QueryBuilder.

@jamescurran
Copy link
Contributor Author

jamescurran commented Apr 3, 2020

Funny, my other project was to create a desktop app to create Rules.

Do you have a Rules Collection class?
I was thinking about something like this:

class RuleTypeCollection
       Type    Type
       Rule[]  Rules;

class RuleAssemblyCollection
         Assembly   Assembly;
         RuleTypeCollection[]   RulesForType;

class RuleCatalog
        RuleAssemblyCollection[]  RulesForAssembly;

@RubberChickenParadise
Copy link

I would also go for B or change Create to Target Rule rule = Rule<Order>.Target(x=>x.Status).Equals(Status.Open);

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

No branches or pull requests

3 participants