Extension for some rule
See original GitHub issuePropertyDTO and OtherDTO are from different inheritance hierarchies so, how could i write an extension function for replacing the RuleFor(p => p.Id).IdRule() so i do not have to repeat the p=>p.Id expression each of those DTOs with Id field?
public static class Extensions
{
public static void IdRule<T>(this IRuleBuilder<T, int> @this)
{
@this.Must(id => id >= 1).WithMessage("Id is invalid.");
}
}
public class PropertyDTOValidator : AbstractValidator<PropertyDTO>
{
public PropertyDTOValidator ()
{
RuleFor(p => p.Id).IdRule();
}
}
public class OtherDTOValidator : AbstractValidator<OtherDTO>
{
public OtherDTOValidator ()
{
RuleFor(p => p.Id).IdRule();
}
}
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Extension of Time To File Your Tax Return
You must file your extension request no later than the regular due date of your return. Taxpayers in certain disaster areas do not...
Read more >eslint-plugin-import/docs/rules/extensions.md at main
ESLint plugin with rules that help validate proper imports. ... Some file resolve algorithms allow you to omit the file extension within the...
Read more >USCIS Increases Automatic Extension Period of Work ...
The automatic extension generally will end upon notification of a final decision on the renewal application or the end of the up to...
Read more >Extension rule Definition & Meaning
The meaning of EXTENSION RULE is a sliding attachment to a folding rule for the measuring of inside distances between objects.
Read more >Different eslint rules based on file extension
Is it possible to have different rules applied to files based on their files extension? For example I have [test].spec.js test spec files ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It is not possible without a common base class or interface.
You’d need to introduce an interface to make the property common for both types.