Hi!

I'm using DynamicProxy 2.2 for Silverlight 3.0 to generate validation
based on DataAnnotations.

I've defined a class like this:

    public class AutenticacaoViewModel
    {
        [Required(ErrorMessage = "O usuário é obrigatório.")]
        [Display(Name = "", Description = "Informe o usuário.")]
        public virtual string Usuario { get; set; }

        [Required(ErrorMessage = "A senha é obrigatória.")]
        [Display(Name = "", Description = "Informe a senha.")]
        public virtual string Senha { get; set; }

        [Required(ErrorMessage = "A unidade é obrigatória.")]
        [Display(Name = "", Description = "Informe a unidade.")]
        public virtual Contratos.EmpresaUnidade EmpresaUnidade { get;
set; }
    }

The interceptor for this class uses some code to validate a property
given its attributes:

    var property = invocation.Method.Name.Substring(4);
    var @this = invocation.InvocationTarget;
    Validator.ValidateProperty(invocation.Arguments[0], new
ValidationContext(@this, null, null) { MemberName = property });

The problem is, framework code can't retrieve validation attributes.
With some code I can see DP does copy target attributes to proxy:

    autenticacao =
ValidationInterceptor.MakeNotifier<AutenticacaoViewModel>();
    var x1 =
Attribute.GetCustomAttributes(autenticacao.GetType().GetProperty("Usuario"));
    var y1 =
Attribute.GetCustomAttributes(autenticacao.GetType().GetProperty("Senha"));

    var x2 =
autenticacao.GetType().GetProperty("Usuario").GetCustomAttributes(true);
    var y2 =
autenticacao.GetType().GetProperty("Senha").GetCustomAttributes(true);

x1 and y1 holds a list of attributes, but x2 and y2 are empty.
Unfortunately, Validator.ValidateProperty() uses the second approach
(confirmed by Reflector).

Does anyone here knows how to solve this problem?

TIA

-- 
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" 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-users?hl=en.

Reply via email to