Beispiel #1
0
        public static bool IsDateOnly(QueryToken token)
        {
            if ((token is DatePartStartToken dt && (dt.Name == QueryTokenMessage.MonthStart || dt.Name == QueryTokenMessage.WeekStart)) ||
                token is DateToken)
            {
                return(true);
            }

            PropertyRoute?route = token.GetPropertyRoute();

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

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

            return(false);
        }
Beispiel #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)
            {
                DateTimePrecisionValidatorAttribute datetimePrecision = pp.Validators.OfType <DateTimePrecisionValidatorAttribute>().SingleOrDefaultEx();
                if (datetimePrecision != null)
                {
                    return(datetimePrecision.FormatString);
                }

                TimeSpanPrecisionValidatorAttribute timeSpanPrecision = pp.Validators.OfType <TimeSpanPrecisionValidatorAttribute>().SingleOrDefaultEx();
                if (timeSpanPrecision != null)
                {
                    return(timeSpanPrecision.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() && ReflectionTools.IsNumber(PrimaryKey.Type(route.RootType)))
            {
                return("D");
            }

            return(FormatString(route.Type));
        }