Silas2
asked on
fluent c# quesion
I've got this html helper control which has a fluent api which has a Validate(expression,messag e,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);
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?
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.
ASKER
This is in razor markup, the fluent api has a procedure Validatate(msg,sev) for this control, so I can do .Validate("onemsg").Valida tet("2ndms g").Valida te("etc")
But I wanna do
foreach(var validation in Model.Validations)
{
control.Validate(validatio n.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.....
But I wanna do
foreach(var validation in Model.Validations)
{
control.Validate(validatio
}
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.....
That could be something like this:
editor.NumericBox()
.ValidateAll(Model.Validations)
ASKER
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...
I thought there might be a snappy syntax which would allow me to do it as is...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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:
"if one:
if two :
if three:
Is the API in the same assembly as your code?
ASKER
I've got the source code but its in a different assembly.
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:
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;
}
}
ASKER
Thanks for that, good point.