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

Expressions of Interest - MustConformToOneOf for conventions #71

Open
andrewabest opened this issue Jan 30, 2020 · 0 comments
Open

Expressions of Interest - MustConformToOneOf for conventions #71

andrewabest opened this issue Jan 30, 2020 · 0 comments

Comments

@andrewabest
Copy link
Owner

A recent update to Conventional made property-based conventions more explicit - in particular it ensured that PropertiesMustHavePrivateSettersConventionSpecification didn't allow properties with no setters pass.

Whilst I'm all for conventions being more explicit and there for easier to reason about / apply / rely on, the previous behaviour was also useful in some circumstances - for example you could apply it to Entity Framework models and it will allow navigation properties etc implemented as get-only properties to exist alongside other properties with private setters, giving you stronger guarantees on encapsulation across your models.

If you wanted to achieve the same behaviour now there is no out of the box convention to do so - you're left to write your own convention. This is simple enough to do, the framework is built to encourage you rolling your own to suit your specific needs.

However another option would be to implement a MustConformToOneOf extension that allowed you to group sets of conventions, and ensure that a given type's contents conform to at least one of the conventions specified.

To do this we would need to strongly type ConventionResult so that we could reliably inspect and compare the results emitted by various conventions, and then make decisions on whether a given Type indeed passed at least one of the supplied tests.

The implementation would look something like this:

https://gist.github.com/andrewabest/1df91aef9116488480ad8df4d90e8fa0

I'll leave this issue up for a while - if you're interested in Conventional having this type of functionality, sing out!

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

1 participant