Esempio n. 1
0
        private DateTime?ResolveToDate(string propertyName, string pattern, TagModel model)
        {
            object result = GetAutoValue(propertyName, model);

            if (result == null)
            {
                return(default(DateTime?));
            }
            if ((result as DateTime?) != null)
            {
                return((DateTime?)result);
            }
            var dateStr = result.ToString();

            if (string.IsNullOrEmpty(dateStr))
            {
                return(default(DateTime?));
            }
            try
            {
                return(DateTime.ParseExact(dateStr, pattern, model.GetApplicableCulture()));
            }
            catch (FormatException Fe)
            {
                throw new FormatException($"Can't parse '{dateStr}' to date using pattern {pattern}.", Fe);
            }
        }
Esempio n. 2
0
        public decimal?GetAutoValueAsDecimal(string propertyName, TagModel model)
        {
            object result = GetAutoValue(propertyName, model);

            return((decimal?)TypeConverter.To(result, typeof(decimal?), model.GetApplicableCulture()));
        }