Hi group,

I could not find a way to bind a parameter to an incoming value with a 
different name. Let's say I have a form which contains an email address 
text field with the name "Profile.Email". AFAIK I can't bind it to a 
method parameter because of the . in the name. What I'd like to do is 
something like this:

public void MyAction([BindTo("Profile.Email")] string email){
  // ..
}

Here I define the key of the form value I want SmartDispatcherController 
to use when binding the email parameter.

Is this functionality available in monorail yet? I know DataBind of 
course, but it binds whole objects, not primitives.

I'm posting this to the dev group because I created a simple solution 
for this issue:

[AttributeUsage(AttributeTargets.Parameter, AllowMultiple=false, 
Inherited=false)]
public class BindToAttribute : Attribute {
  private readonly string parameterName;

  public BindToAttribute(string parameterName) {
    if(string.IsNullOrEmpty(parameterName)) {
      throw new ArgumentException("parameterName must not be null or 
empty", "parameterName");
    }
    this.parameterName = parameterName;
  }

  public string ParameterName {
    get { return parameterName; }
  }
}

// overriding SmartDispatcherController.GetRequestParameterName:
// ...
protected override string GetRequestParameterName(ParameterInfo param) {
  var args = param.GetCustomAttributes(typeof (BindToAttribute), false);
  if (args != null && args.Length > 0) {
    var attrib = (BindToAttribute) args[0];
    return attrib.ParameterName;
  }
  return base.GetRequestParameterName(param);
}

It's rather simple but it works for me.

So, my question is: is there already this kind of functionality in 
monorail? If so, I'd drop my implementation, otherwise I could polish 
the whole thing and provide a patch.

Regards,
Andre


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Castle Project Development List" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/castle-project-devel?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to