This project is read-only.

Cross-Field Validation using a custom rule question.

Jul 10, 2016 at 10:18 AM
Hi Guys,

I trust that you are all doing well. I was wondering if it is possible to create a custom rule that accepts a different field from the same object?

For example

public class TaxRecord{
    public string RebateForForeignTaxPaid;
    public string TaxWithheld ;

In the code I would like to pass the RebateForForeignTaxPaid into my custom rule
   .Setup(dd => dd.TaxWithheld)
   .MustPassRule(new TaxWithheldRule(dd => dd.RebateForForeignTaxPaid) )

The rule
 class TaxWithheldRule : IRule<string>
    int minimumlength;
    int maximumlength;

    public TaxWithheldRule(string x)
        //some construction


    public ValidationResult Validate(string value)
        //some validation

    public string RuleKind
        get { return this.GetType().Name; }

I keep on getting the following build error

Cannot convert lambda expression to type 'string' because it is not a delegate type

I am unsure what I'm doing wrong?