示例#1
0
        public static bool IsDateOnly(QueryToken token)
        {
            if (token is MonthStartToken || token is DateToken)
            {
                return(true);
            }

            PropertyRoute route = token.GetPropertyRoute();

            if (route != null && route.PropertyRouteType == PropertyRouteType.FieldOrProperty)
            {
                var pp = Validator.TryGetPropertyValidator(route);
                if (pp != null)
                {
                    DateTimePrecissionValidatorAttribute datetimePrecission = pp.Validators.OfType <DateTimePrecissionValidatorAttribute>().SingleOrDefaultEx();

                    if (datetimePrecission != null && datetimePrecission.Precision == DateTimePrecision.Days)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
示例#2
0
        public static string FormatString(PropertyRoute route)
        {
            PropertyRoute simpleRoute = route.SimplifyToProperty();

            FormatAttribute format = simpleRoute.PropertyInfo.GetCustomAttribute <FormatAttribute>();

            if (format != null)
            {
                return(format.Format);
            }

            var pp = Validator.TryGetPropertyValidator(simpleRoute);

            if (pp != null)
            {
                DateTimePrecissionValidatorAttribute datetimePrecission = pp.Validators.OfType <DateTimePrecissionValidatorAttribute>().SingleOrDefaultEx();
                if (datetimePrecission != null)
                {
                    return(datetimePrecission.FormatString);
                }

                TimeSpanPrecissionValidatorAttribute timeSpanPrecission = pp.Validators.OfType <TimeSpanPrecissionValidatorAttribute>().SingleOrDefaultEx();
                if (timeSpanPrecission != null)
                {
                    return(timeSpanPrecission.FormatString);
                }

                DecimalsValidatorAttribute decimals = pp.Validators.OfType <DecimalsValidatorAttribute>().SingleOrDefaultEx();
                if (decimals != null)
                {
                    return("N" + decimals.DecimalPlaces);
                }

                StringCaseValidatorAttribute stringCase = pp.Validators.OfType <StringCaseValidatorAttribute>().SingleOrDefaultEx();
                if (stringCase != null)
                {
                    return(stringCase.TextCase == StringCase.Lowercase ? "L" : "U");
                }
            }

            if (route.IsId() && IsNumber(PrimaryKey.Type(route.RootType)))
            {
                return("D");
            }

            return(FormatString(route.Type));
        }