Domanda RangeAttribute e validator

  • lunedì 6 febbraio 2012 11:49
     
     

    ciao a tutti,

    fino a oggi ho utilizzato il RangeAttribute per tipi base, stringhe, decimal, int, mi chiedevo se è possible utilizzare il range come

     

     [Range(typeof(MyObject), "0", "9999", ErrorMessage = "Valore non concesso")]

     

    dove MyObject è definito come

     

       public partial class MyObject: INotifyPropertyChanged
        {
            private bool isGeneric;

            public bool IsGeneric
            {
                get
                {
                    return isGeneric;
                }
                set
                {
                    isGeneric = value;
                    NotifyPropertyChanged("IsGeneric");
                }
            }

     

    public decimal? Valore

    {

    get {....} set{...}

    }

     

     

           public event PropertyChangedEventHandler PropertyChanged;

            private void NotifyPropertyChanged(String info)
            {
                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs(info));
                }
            }
        }

     

    Che tipo di interfaccia devo implementare affinche possa essere validato in questo modo? non volevo fare 3 oggetti CustomValidator per 3 classi che wrappano oggetti di Entity Framework e che hanno la stessa proprietà Valore sulla quale è necessario effettuale la validazione

    Grazie ciao

Tutte le risposte

  • lunedì 6 febbraio 2012 12:59
    Moderatore
     
     
    Perchè non usi un custom validator?
     

    Corrado Cavalli [Microsoft .NET MVP-MCP]
    UGIdotNET - http://www.ugidotnet.org
    Weblog: http://blogs.ugidotnet.org/corrado/
    Twitter: http://twitter.com/corcav
  • lunedì 6 febbraio 2012 13:30
     
     
    in principio volevo usare 3 custom validator (ho oggetti differenti che mappano oggetti simili), però era per mantenere la logica all'interno della mia classe e non fare 3 custom validator differenti