Input type automatically changes inside lambda expression

I noticed a very strange problem when using the Fluent Validation proposal Must.

Say I have a model like this:

public class PhoneDetail
{
    public int PrefixId { get; set; }
    public string Digits { get; set; }
}

And here is the validator:

public PhoneDetailValidator()
{
    this.RuleFor(phone => phone.Digits)
        .Must(x => x == null);
}

What type do x you think ? String? Yes you are right.

enter image description here

But what is it?

enter image description here

He changed his type from Stringto PhoneDetail. I am using Visual Studio 2012 .

Is this a mistake or something else?

Update:

In addition, it is worth saying that in the first case it compiles just fine. But in the second case, a compiler error occurs:

> Delegate 'System.Func<SportsStore.WebUI.Models.PhoneDetail,string,bool>'
> does not take 1 arguments
+4
source share
1 answer

IDE, , IntelliSense Must. Func, , :

this.RuleFor(phone => phone.Digits)
            .Must((phone, x) => phone.Digits == null);
+4

Source: https://habr.com/ru/post/1585112/


All Articles