示例#1
0
    public static bool IsValid <T>(this IGridifyFiltering filtering, IGridifyMapper <T>?mapper = null)
    {
        if (string.IsNullOrWhiteSpace(filtering.Filter))
        {
            return(true);
        }
        try
        {
            var parser     = new Parser(filtering.Filter !, GridifyGlobalConfiguration.CustomOperators.Operators);
            var syntaxTree = parser.Parse();
            if (syntaxTree.Diagnostics.Any())
            {
                return(false);
            }

            var fieldExpressions = syntaxTree.Root.Descendants()
                                   .Where(q => q.Kind is SyntaxKind.FieldExpression)
                                   .Cast <FieldExpressionSyntax>().ToList();

            mapper ??= new GridifyMapper <T>(true);

            if (fieldExpressions.Any(field => !mapper.HasMap(field.FieldToken.Text)))
            {
                return(false);
            }
        }
        catch (Exception)
        {
            return(false);
        }

        return(true);
    }
示例#2
0
    public static bool IsValid <T>(this IGridifyOrdering ordering, IGridifyMapper <T>?mapper = null)
    {
        if (string.IsNullOrWhiteSpace(ordering.OrderBy))
        {
            return(true);
        }
        try
        {
            var orders = ParseOrderings(ordering.OrderBy !).ToList();
            mapper ??= new GridifyMapper <T>(true);
            if (orders.Any(order => !mapper.HasMap(order.MemberName)))
            {
                return(false);
            }
        }
        catch (Exception)
        {
            return(false);
        }

        return(true);
    }