This project has moved. For the latest updates, please go here.
1
Vote

RuleFor/SetCollectionValidator doesn't show up in IntelliSense for IList<T> properties

description

Given types:
    class User
    {
        public int Id { get; set; }
        public string Name { get; set; }
    }

    class Role
    {
        public string Name { get; set; }
        public IList<string> AllowedOperations { get; set; }

        public IList<User> Users { get; set; }
    }
and validators:
    class UserValidator : AbstractValidator<User>
    {
        public UserValidator()
        {
            RuleFor(x => x.Id)
                .NotEmpty();
        }
    }

    class RoleValidator : AbstractValidator<Role>
    {
        public RoleValidator()
        {
            // SetCollectionValidator compiles but doesn't show up in IntelliSense
            RuleFor(x => x.Users)
                .SetCollectionValidator(new UserValidator());
        }
    }
Addition of following extension method to base AbstractValidator would solve this problem:
protected IRuleBuilderInitial<Role, IEnumerable<TProperty>> RuleFor<TProperty>(Expression<Func<Role, IEnumerable<TProperty>>> expression)
        {
            return base.RuleFor<IEnumerable<TProperty>>(expression);
        }
This behavior can be confusing for inexperienced programmers, on my team I had problem with younger programmer who tried to use RuleForEach instead of RuleFor+SetCollectionValidator because 'it didn't show up in IntelliSense'. Please consider also improving documentation on RuleForEach method.

file attachments

comments

JeremyS wrote Jan 27, 2015 at 8:23 AM

Hi

I can't reproduce this. It shows up just fine in intellisense provided you have the "using FluentValidation" namespace import.

Jeremy

miyako wrote Feb 4, 2015 at 7:34 PM

Sorry for late answer.

I checked this on VS Community Update 4 without any plugins (fresh install), and on VS 2014 Pro and it didn't show up, maybe you have ReSharper installed and it adds some "better IntelliSense".

I tested this with FluentValidation version 5.5.0.0 nuget package from official repo (nuget.org).

In attachment you may find entire solution that I use for testing, maybe this will help you spot this issue.

JeremyS wrote Feb 5, 2015 at 1:41 PM

Hi

I'm afraid I still can't reproduce the problem. I tried opening your solution in a clean install of visual studio (no resharper) and the SetCollectionValidator method appears in intellisense correctly. (Screenshot attached)

I'm not quite sure what else to suggest...are you sure that you don't have any plug-ins installed that might be interfering with VS intellisense? Have you tried resetting your VS settings to the factory default?

Jeremy