V.QueryParser 1.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package V.QueryParser --version 1.1.0                
NuGet\Install-Package V.QueryParser -Version 1.1.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="V.QueryParser" Version="1.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add V.QueryParser --version 1.1.0                
#r "nuget: V.QueryParser, 1.1.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install V.QueryParser as a Cake Addin
#addin nuget:?package=V.QueryParser&version=1.1.0

// Install V.QueryParser as a Cake Tool
#tool nuget:?package=V.QueryParser&version=1.1.0                

V.QueryParser

木叉一人工作室封装的表达式字符串解析类库,该类库只需要遍历一次字符串即可解析出对应的表达式结构,但是目前对于表达式的格式要求比较严格,在两个关键词之间必须加上空格,否则会解析失败。

/// <summary>
/// 查询表达式解析器
/// <para>key1 > value1 && key2 == value2 || key3 like value3</para>
/// <para>关键词与符号之间的空格是严格要求的</para>
/// </summary>
public class QueryExpression
{
    /// <summary>
    /// 当 Type 为 Compound 时,有值
    /// </summary>
    public List<QueryExpression> Queries { get; private set; } = new List<QueryExpression>();

    /// <summary>
    /// 当 Type 为 Compound 时,有值
    /// <para>长度比 Queries 少 1,Symbols[i] 左边表达式为 Queries[i] 右边为 Queries[i+1]</para>
    /// </summary>
    public List<Symbol> Symbols { get; private set; } = new List<Symbol>();

    /// <summary>
    /// 当前表达式的查询类型
    /// </summary>
    public QueryType Type { get; private set; } = QueryType.All;

    public string Key { get; private set; }

    public Symbol Ope { get; private set; }

    public string Value { get; private set; }

    public QueryExpression(string condition){}
}

当初始化表达式为空时,Type 为 QueryType.All,表示查询全部;当 Type 为 QueryType.Base 时,表示表达式为基础查询,直接看 Key、Ope、Value 三个字段,Ope 支持 Gt、Gte、Lt、Lte、Eq、Neq、Like,当 value 部分为字符串时,可以用英文单引号或双引号包围起来,使表达式更加清晰可读,当然也可以不使用,但是这种情况下,value 不可以包含空格。

当 Type 为 QueryType.Compound 时,表示表达式为组合查询,需要使用到 Queries、Symbols 两个字段,Queries 依次存储从左到右的表达式,Symbols 依次存储从左到右的逻辑运算符,Queries 的长度等于 Symbols 长度 + 1,在解析组合查询时,应该遍历 Symbols,先把 Ope.And 左右两边的表达式先进行运算(即,若 Symbols[i] == Ope.And,则先运算 Queries[i] and Queries[i + 1]),最后再运算 Ope.Or。若表达式不存在括号,则 Queries 中全部都是基础查询,若存在括号,则 Queries 可能包含组合查询。

// 使用以下代码测试表达式,并查看解析后的表达式数据格式
var query = new QueryExpression("key1 > value1 && key2 == value2 || key3 like value3");

若出现表达式解析异常,或需要支持的特性,欢迎提交 issue 以及 PR

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

NuGet packages (1)

Showing the top 1 NuGet packages that depend on V.QueryParser:

Package Downloads
V.Talog.Extension

木叉一人工作室开发的单机日志解决方案-扩展包

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.1 449 5/30/2023
1.1.0 126 5/30/2023
1.0.4 199 5/29/2023
1.0.3 490 11/18/2022
1.0.2 352 11/2/2022
1.0.1 360 11/1/2022
1.0.0 346 11/1/2022