//ValidarPatente recibirá un string, y validará que coincida con los formatos de patente_mercosur o patente_vieja.
        public static Patente ValidarPatente(this string str)
        {
            Regex   rgx_v = new Regex(PatenteStringExtension.patente_vieja);
            Regex   rgx_n = new Regex(PatenteStringExtension.patente_mercosur);
            Patente p;

            //Verifica patente vieja
            if (rgx_v.IsMatch(str))
            {
                p = new Patente(str, Patente.Tipo.Vieja);
            }

            //verifica patente Mercosur
            else if (rgx_n.IsMatch(str))
            {
                p = new Patente(str, Patente.Tipo.Mercosur);
            }
            else
            {
                //Caso contrario se lanzará una excepción del tipo PatenteInvalidaException con el mensaje "{0} no cumple el formato."
                string s = string.Format("{0} no cumple el formato.", str);

                throw new PatenteInvalidaException(s);
            }

            return(p);
        }
Exemplo n.º 2
0
        public static Patente ValidarPatentr(this String str)
        {
            Patente p = null;

            try
            {
                Regex rgx_v = new Regex(PatenteStringExtension.patente_vieja);
                Regex rgx_n = new Regex(PatenteStringExtension.patente_mercosur);

                if (rgx_v.IsMatch(str))
                {
                    p = new Patente(str, Patente.Tipo.Vieja);
                }
                else if (rgx_n.IsMatch(str))
                {
                    p = new Patente(str, Patente.Tipo.Mercosur);
                }
                else
                {
                    //string s = string.Format("{0} no cumple el formato.", str);
                    //throw new PatenteInvalidaException(s);
                    throw null;
                }
            }
            catch (Exception e)
            {
                string s = string.Format("{0} no cumple el formato.", str);
                throw new PatenteInvalidaException(s, e);
            }

            return(p);
        }
        /// <summary>
        /// Validates if the entity is type old or new, then returns a valid entity regarding
        /// the type of the entity.
        /// </summary>
        /// <param name="patente">String of the entity to validate.</param>
        /// <returns>Returns an object of the entity.</returns>
        public static Patente ValidarPatente(this string patente)
        {
            Patente pat = null;

            try {
                if (rgx_v.IsMatch(patente))
                {
                    pat = new Patente(patente, Patente.Tipo.Vieja);
                }
                else if (rgx_n.IsMatch(patente))
                {
                    pat = new Patente(patente, Patente.Tipo.Mercosur);
                }
                else
                {
                    string s = string.Format("{0} no cumple el formato.", patente);
                    throw new PatenteInvalidaException(s);
                }
            } catch (Exception exe) {
                string s = string.Format("{0} no cumple el formato.", patente);
                throw new PatenteInvalidaException(s, exe);
            }

            return(pat);
        }
 static Patente ValidarPatente(this string str)
 {
     try
     {
         Regex   rgx_v = new Regex(PatenteStringExtension.patente_vieja);
         Regex   rgx_n = new Regex(PatenteStringExtension.patente_mercosur);
         Patente p;
         if (rgx_v.IsMatch(str))
         {
             p = new Patente(str, Patente.Tipo.Vieja);
         }
         else if (rgx_n.IsMatch(str))
         {
             p = new Patente(str, Patente.Tipo.Mercosur);
         }
         else
         {
             string s = string.Format("{0} no cumple el formato.", str);
             throw new PatenteInvalidaException(s);
             //throw null;
         }
         return(p);
     }
     catch (PatenteInvalidaException pEx)
     {
         throw pEx;
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 5
0
        public static Patente ValidarPatente(this string str)
        {
            Regex   rgx_v = new Regex(PatenteStringExtension.patente_vieja);
            Regex   rgx_n = new Regex(PatenteStringExtension.patente_mercosur);
            Patente p;

            if (rgx_v.IsMatch(str))
            {
                p = new Patente(str, Patente.Tipo.Vieja);
            }
            else if (rgx_n.IsMatch(str))
            {
                p = new Patente(str, Patente.Tipo.Mercosur);
            }
            else
            {
                throw new PatenteInvalidaException(string.Format("{0} no cumple el formato.", str));
            }
            return(p);
        }
        public static Patente ValidarPatente(this string str)
        {
            Patente p;

            if (rgx_v.IsMatch(str))
            {
                p = new Patente(str, Patente.Tipo.Vieja);
            }
            else if (rgx_n.IsMatch(str))
            {
                p = new Patente(str, Patente.Tipo.Mercosur);
            }
            else
            {
                string s = string.Format("{0} no cumple el formato.", str);
                throw new PatenteInvalidaException(s);
            }

            return(p);
        }
        public static Patente ValidarPatente(this string codigo)
        {
            Patente patente;
            Regex   rgx_v = new Regex(PatenteStringExtension.patente_vieja);
            Regex   rgx_n = new Regex(PatenteStringExtension.patente_mercosur);

            if (rgx_v.IsMatch(codigo))
            {
                patente = new Patente(codigo, Patente.Tipo.Vieja);
            }
            else if (rgx_n.IsMatch(codigo))
            {
                patente = new Patente(codigo, Patente.Tipo.Mercosur);
            }
            else
            {
                string error = string.Format("{0} no cumple el formato.", codigo);
                throw new PatenteInvalidException(error);
            }
            return(patente);
        }
        public static Patente MetodoExtendido(this String str)
        {
            Patente p;
            Regex   rgx_v = new Regex(PatenteStringExtension.patente_vieja);
            Regex   rgx_n = new Regex(PatenteStringExtension.patente_mercosur);

            if (rgx_v.IsMatch(str))
            {
                p = new Patente(str, Patente.Tipo.Vieja);
            }
            else if (rgx_n.IsMatch(str))
            {
                p = new Patente(str, Patente.Tipo.Mercosur);
            }
            else
            {
                string s = string.Format("{0} no cumple el formato.", str);
                throw new PatenteInvalidaException(s);
                throw null;
            }

            return(p);
        }