Home

Awesome

Qulaly

Query language for Roslyn. Qulaly is a library that queries Roslyn's C# syntax tree with CSS selector-like syntax. Inspired by esquery in ECMAScript ecosystem.

NuGet version Build-Development

⚡Live Demo: https://mayuki.github.io/Qulaly/

Example

The following code shows how to query the async method.

using Qulaly;

var syntaxTree = CSharpSyntaxTree.ParseText(@"
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

public class Class1
{
    public static async ValueTask<T> FooAsync<T>(int a, string b, T c) => throw new NotImplementedException();
    public async Task BarAsync<T>() => throw new NotImplementedException();
    public object MethodA(int arg1) => throw new NotImplementedException();
    public object MethodB(int arg1, string arg2) => throw new NotImplementedException();
}
");

// Enumerate SyntaxNodes by calling `QuerySelectorAll` extension method for SyntaxNode/SyntaxTree.
foreach (var methodNode in syntaxTree.QuerySelectorAll(":method[Modifiers ~= 'async']"))
{
    Console.WriteLine(((MethodDeclarationSyntax)methodNode).Identifier.ToFullString());
}

Output

FooAsync
BarAsync

Methods

Install

Install NuGet package from NuGet.org

$ dotnet add package Qulaly
PS> Install-Package Qulaly

Supported Selectors

Qulaly supports a subset of CSS selector level 4. The selector engine also supports Qulaly-specific extensions to the selector.

License

MIT License

Copyright © 2020-present Mayuki Sawatari <mayuki@misuzilla.org>