question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Extension for some rule

See original GitHub issue

PropertyDTO 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:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
JeremySkinnercommented, Aug 6, 2018

It is not possible without a common base class or interface.

1reaction
JeremySkinnercommented, Aug 6, 2018

You’d need to introduce an interface to make the property common for both types.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found