Example #1
0
        public FormatterResult <int> GetInt(string input)
        {
            FormatterResult <int> res            = new FormatterResult <int>();
            FormatterError        formatterError = new FormatterError();

            if (input == null)
            {
                res.Errors.Add(formatterError.Create("String is null"));
                return(res);
            }

            if (input.Length == 0)
            {
                res.Errors.Add(formatterError.Create("String is empty"));
                return(res);
            }

            int val = 0;

            if (!int.TryParse(input, out val))
            {
                res.Errors.Add(formatterError.Create("Cant transform the string to int number"));
                return(res);
            }
            if (val <= 0)
            {
                res.Errors.Add(formatterError.Create("Can be only positive number"));
                return(res);
            }
            res.Value = val;

            return(res);
        }
Example #2
0
        public FormatterResult <string> GetString(string input)
        {
            FormatterResult <string> res            = new FormatterResult <string>();
            FormatterError           formatterError = new FormatterError();

            if (input == null)
            {
                res.Errors.Add(formatterError.Create("String is null"));
                return(res);
            }

            if (input.Length == 0)
            {
                res.Errors.Add(formatterError.Create("String is empty"));
                return(res);
            }

            Regex regex = new Regex("[a-zA-Z]");

            if (!regex.IsMatch(input))
            {
                res.Errors.Add(formatterError.Create("String hasn't any word"));
                return(res);
            }

            res.Value = input;

            return(res);
        }
Example #3
0
        public FormatterResult <DateTime> GetDateTime(string input)
        {
            FormatterResult <DateTime> res            = new FormatterResult <DateTime>();
            FormatterError             formatterError = new FormatterError();

            if (input == null)
            {
                res.Errors.Add(formatterError.Create("String is null"));
                return(res);
            }

            if (input.Length == 0)
            {
                res.Errors.Add(formatterError.Create("String is empty"));
                return(res);
            }

            DateTime val;

            if (!DateTime.TryParse(input, out val))
            {
                res.Errors.Add(formatterError.Create("Cant transform the string to datetime format"));
                return(res);
            }

            res.Value = val;

            return(res);
        }