views:

36

answers:

1

I've been following this guide and coming up with my own concoction in order to use MonoRail's FormHelper.Select that is generated from an enum. So here's the Brail syntax:

${FormHelper.Select("user.Role", ${LS.EnumToPairs(Roles)}, {"value":"First", "text":"Second"})}

"LS" is just my own helper, which I've defined as follows:

public IEnumerable<Pair<int, string>> EnumToPairs(Type e)
{
    IList<Pair<int, string>> pairs = new List<Pair<int, string>>();

    foreach (int val in Enum.GetValues(e))
        pairs.Add(new Pair<int, string>(val, Enum.GetName(e, val)));

    return pairs;
}

Yet from this, despite being the correct syntax, I get the following error:

Node '$({ return Castle.MonoRail.Views.Brail.ExpandDuckTypedExpressions_WorkaroundForDuplicateVirtualMethods.Invoke(self.GetParameter('LS'), 'EnumToPairs', (self.GetParameter('Roles'),)) })' has not been correctly

The source error doesn't help much unfortunately:

Line 15: output FormHelper.TextField("user.Role", {"class":"text-input full-width"}) Line 16: output """ Line 17: """ Line 18: output FormHelper.Select("user.Role", ${LS.EnumToPairs(Roles)}, {"value":"First", "text":"Second"}) Line 19: output """

Any ideas what I'm doing wrong here?

EDIT

Based on the answer given below, the solution was finally this:

${FormHelper.Select("user.Role", LS.EnumToPairs(Roles), {"value":"First","text":"Second"})}

Where Roles was PropertyBag["Roles"] = typeof(Role);

A: 

Try this:

${FormHelper.Select("user.Role", LS.EnumToPairs(typeof(Roles)), {"value":"First", "text":"Second"})}
Mauricio Scheffer
This was very close, but it wouldn't let me do `typeof(Role)` (that's the actual enum type) or `typeof(Roles)` if `Roles` was in the PropertyBag as I had shown in my code. Instead I did `LS.EnumToPairs(Roles)` where there was `PropertyBag["Roles"] = typeof(Role);` - don't ask me why it wouldn't let me, because Role isn't even in a namespace. Your idea led to the solution though.
Kezzer
@Kezzer: right, you'd have to put the full namespace of `Role` and make sure is has the correct assembly reference.
Mauricio Scheffer
@Mauricio: Indeed, but `Role` was never in a namespace, so I wasn't sure what happens in that circumstance. I did try `Project.Role` on the import without any luck. Not sure what went on there really.
Kezzer