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

Extend property covariance into the internal model. #1713

Merged
merged 2 commits into from Jun 8, 2021

Conversation

JeremySkinner
Copy link
Member

@JeremySkinner JeremySkinner commented Apr 20, 2021

Makes TProperty covariant within the internal model's IValidationRule<T,TProperty> interface.

This would resolve #1711 and related scenarios where the property type may be an inheritor of the type defined in a rule extension method.

This would introduce several breaking changes. Specifically:

  • IValidationRule.Current would need to be IRuleComponent<T,TProperty> rather than RuleComponent<T,TProperty>
  • IRuleComponent<T,TProperty>.CustomStateProvider would become write-only
  • IRuleComponent<T,TProperty>.SeverityProvider would become write-only
  • GetErrorMessage would not be exposed on IRuleComponent<T,TProperty>

Making various properties write-only is potentially problematic, but in theory users should only ever be setting these, and only the library's internals need to get them. But I expect there will be someone out there who relies on this for something nonstandard.

MessageBuilders still need some work. The quick fix is to not expose TProperty on the MessageBuilderContext and instead go back to exposing this as a non-generic object. This isn't ideal, so see whether there's a better way around this that still allows the MessageBuilder's getter to be exposed.

@JeremySkinner JeremySkinner added this to the 11.0 milestone Apr 20, 2021
@JeremySkinner JeremySkinner changed the title Extend variance into the internal model. Extend property covariance into the internal model. Apr 20, 2021
@JeremySkinner JeremySkinner changed the base branch from main to 11.x June 8, 2021 14:05
@JeremySkinner JeremySkinner merged commit ee05651 into 11.x Jun 8, 2021
@JeremySkinner JeremySkinner deleted the experiment/variance branch June 8, 2021 14:23
JeremySkinner added a commit that referenced this pull request Jun 17, 2021
* Remove IValidationRuleConfigurable and finish implementing variance in the internal api
* Update changelog
JeremySkinner added a commit that referenced this pull request Jul 7, 2021
* Remove IValidationRuleConfigurable and finish implementing variance in the internal api
* Update changelog
JeremySkinner added a commit that referenced this pull request Aug 26, 2021
* Remove IValidationRuleConfigurable and finish implementing variance in the internal api
* Update changelog
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

Successfully merging this pull request may close these issues.

InvalidCastException when using ForEach rule
1 participant