Esa es la mejor forma!

2011/10/28 Gustavo Souza Gonçalves <[email protected]>

> Hello! Gracias por el consejo. Lo hice de la siguiente manera en el
> BaseEntity.cs clase:
>
>  public class BaseEntity : IEntity, IDataErrorInfo
>        {
>                public virtual long Id { get; private set; }
>
>        private static IEntityValidator entityValidator;
>        private static IEntityValidator EntityValidator
>        {
>            get
>            {
>                if (entityValidator == null)
>                    return entityValidator =
> ServiceLocator.Current.GetInstance<IEntityValidator>();
>                return entityValidator;
>            }
>        }
>
>        string IDataErrorInfo.this[string columnName]
>        {
>            get
>            {
>                var errors = EntityValidator.Validate(this,
> columnName).Select(iv => iv.Message).ToArray();
>                return string.Join(Environment.NewLine, errors);
>            }
>        }
>
>        string IDataErrorInfo.Error
>        {
>            get
>            {
>                var errors = EntityValidator.Validate(this).Select(iv
> => iv.Message).ToArray();
>                return string.Join(Environment.NewLine, errors);
>            }
>        }
>        }
>
> Ahora todo funciona en línea. Muchas gracias!
>
> On 27 out, 12:14, José F. Romaniello <[email protected]> wrote:
> > Deberías hacer algo como esto (pseudo código por que aquí no tengo un
> > ejemplo de esto):
> >
> >        public string Error
> >        {
> >            get {
> >                var messages = ValidatorEngine.GetInvalidValues(this)
> >                     .Select(iv => iv.Message)
> >                     .ToArray();
> >               if(messages.Length > 0) return string.empty();
> >               return string.join(Environment.NewLine, messages);
> >            }
> >        }
> >
> >        public string this[string columnName]
> >        {
> >            get
> >            {
> >                var messages = ValidatorEngine.GetInvalidValues(this,
> > columnName)
> >                     .Select(iv => iv.Message)
> >                     .ToArray();
> >               if(messages.Length > 0) return string.empty();
> >               return string.join(Environment.NewLine, messages);
> >            }
> >        }
> >
> > En la versión actual de uNhAddIns, más proyectos:
> >
> > > uNhAddIns.ComponentBehaviors;
> > > uNhAddIns.ComponentBehaviors.Castle;
> > > Desde DataErrorInfoBehavior se fija en ellos, porque estos proyectos
> > > fueron retirados?
> >
> > Esto fue un intento de hacer IDataErrorInfo con AOP.... pero nos dimos
> > cuenta que era innecesario, se puede poner en una clase base. Y aún si
> > quisiera hacerlo con AOP preferiría escribirlo en mi solución y no tener
> que
> > recompilar unhaddins dependencias a nhibernate etc...
>
> --
> Para escribir al Grupo, hágalo a esta dirección:
> [email protected]
> Para más, visite: http://groups.google.com/group/NHibernate-Hispano
>

-- 
Para escribir al Grupo, hágalo a esta dirección: 
[email protected]
Para más, visite: http://groups.google.com/group/NHibernate-Hispano

Responder a