fluent c# quesion

I've got this html helper control which has a fluent api which has a Validate(expression,message,severity) bit to the builder, but it doesn't take a Action<> type param, but you can string multip params together, e.g.:
       editor.NumericBox()
            .Validate("Include = true and Quantity = 0",
                T("Must be geater 0."))
 
            .Validate("Include = true and Quantity > Total",
                T("Too many."),
                ValidationSeverity.Error);

Open in new window

my problem is that I have a Validations collection with a variable number of validators in, what syntax do I need to append an indeterminate number of validators on?
Silas2Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
I am reading this question like you need to add a new method that takes the collection as an argument.  If I am wrong, please explain what you mean in a little more detail.
0
Silas2Author Commented:
This is in razor markup, the fluent api has a procedure Validatate(msg,sev) for this control, so I can do .Validate("onemsg").Validatet("2ndmsg").Validate("etc")

But I wanna do
foreach(var validation in Model.Validations)
{
     control.Validate(validation.msg)
}
which I could if the fluent api took a validationbuilder Action<> method, like:
Columns=>{
    foreach(var col in model.Columns)

}
if you get what I mean.....
0
Bob LearnedCommented:
That could be something like this:

editor.NumericBox()
        .ValidateAll(Model.Validations)

Open in new window

0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

Silas2Author Commented:
so i'll have to modify the api?
I thought there might be a snappy syntax which would allow me to do it as is...
0
Bob LearnedCommented:
I am having a difficult time seeing a way that wouldn't require changing the API.  

Another possibility would be an overloaded method
editor.NumericBox()
        .Validate(Model.Validations)

Open in new window


that might be able to make calls to the Validate method with a foreach for each of the validations.  

Can you show me your Validate method, please?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Silas2Author Commented:
I think you've said enough, i'll go back to the guy how does these api's and see if he'll modify it for me..otherwise i'll have to hard code,
"if one:
if two :
if three:
0
Bob LearnedCommented:
Is the API in the same assembly as your code?
0
Silas2Author Commented:
I've got the source code but its in a different assembly.
0
Bob LearnedCommented:
Sorry, I meant same solution...

If you have the API project in the same solution, you should be able to add a static class for extension methods.

Here is an example, with a wild guess at your code, to show the realm of possibilities:

public static class ExtensionMethods
{

     public static ValidationBuilder ValidateAll(this ValidationBuilder builder, List<Validator> validatorList)
     {
           validatorList.ForEach(x => x.Validate(builder.Control));
           return builder;
     }
}

Open in new window

0
Silas2Author Commented:
Thanks for that, good point.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.