andrewabest/Conventional

Expressions of Interest - MustConformToOneOf for conventions

Opened this issue · 0 comments

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!