Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/roeibajayo/SourceGeneratorQuery
C# SourceGenerator helper which helps you query your files, and adds LINQ support
https://github.com/roeibajayo/SourceGeneratorQuery
csharp-sourcegenerator linq query query-builder source-generator
Last synced: 3 months ago
JSON representation
C# SourceGenerator helper which helps you query your files, and adds LINQ support
- Host: GitHub
- URL: https://github.com/roeibajayo/SourceGeneratorQuery
- Owner: roeibajayo
- Created: 2023-01-15T02:18:15.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-01-16T22:17:54.000Z (almost 2 years ago)
- Last Synced: 2024-07-30T17:09:01.667Z (3 months ago)
- Topics: csharp-sourcegenerator, linq, query, query-builder, source-generator
- Language: C#
- Homepage:
- Size: 23.4 KB
- Stars: 17
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- RSCG_Examples - SourceGeneratorQuery
- csharp-source-generators - SourceGeneratorQuery - ![stars](https://img.shields.io/github/stars/roeibajayo/SourceGeneratorQuery?style=flat-square&cacheSeconds=604800) ![last commit](https://img.shields.io/github/last-commit/roeibajayo/SourceGeneratorQuery?style=flat-square&cacheSeconds=86400) - C# SourceGenerator helper which helps you query your files, and adds LINQ support. (Source Generators / Metaprogramming)
README
# SourceGeneratorQuery
C# class library that helps you query the GeneratorExecutionContext, and also adds LINQ support.You can read about Source Generators on [Microsoft's site](https://learn.microsoft.com/en-us/dotnet/csharp/roslyn-sdk/source-generators-overview).
Installation
---
This library is distributed via NuGet.> PM> Install-Package [SourceGeneratorQuery](https://www.nuget.org/packages/SourceGeneratorQuery)
Quick Start
---
```csharp
//..
public void Execute(GeneratorExecutionContext context)
{
var classes = context
.NewQuery() // start new query
.WithPath("./Social") // filter search on specific path
.GetClasses()
.WithName(x => x.EndsWith("Client")); // classes ends with 'Client'var syntaxNodes = classes.Select(x => x.SyntaxNode); // get the syntax nodes if you want
// example of iteration
foreach (var c in classes)
{
var publicMethodsWithMyAttributeAndStartsWithGet = c.GetMethods()
.WithAttribute("MyAttribute")
.WithPublic()
.WithName(name => name.StartsWith("Get"));var methodsSyntaxNodes = publicMethodsWithMyAttributeAndStartsWithGet.Select(x => x.SyntaxNode);
var stringifyMethods = publicMethodsWithMyAttributeAndStartsWithGet
.Select(x => $"{string.Join(" ", x.Modifiers)} {x.Name}({string.Join(", ", x.Parameters.Select(p => $"{p.Type} {p.Name}"))})")
.ToArray();
}
}
//..
```Examples
---
See/src/examples
folder for more examples.