Skip to content

Commit

Permalink
f ReadMe
Browse files Browse the repository at this point in the history
  • Loading branch information
neuecc committed Jun 12, 2024
1 parent 1e1229a commit 19fbf75
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ ConsoleApp.Run(args, (int foo, int bar) => Console.WriteLine($"Sum: {foo + bar}"

Unlike typical Source Generators that use attributes as keys for generation, ConsoleAppFramework analyzes the provided lambda expressions or method references and generates the actual code body of the Run method.

```csharp
internal static partial class ConsoleApp
{
// Generate the Run method itself with arguments and body to match the lambda expression
public static void Run(string[] args, Action<int, int> command)
{
// code body
}
}
```

<details><summary>Full generated source code</summary>
```csharp
namespace ConsoleAppFramework;

Expand Down Expand Up @@ -111,6 +123,7 @@ Options:
}
}
```
</details>

As you can see, the code is straightforward and simple, making it easy to imagine the execution cost of the framework portion. That's right, it's zero. This technique was influenced by Rust's macros. Rust has [Attribute-like macros and Function-like macros](https://doc.rust-lang.org/book/ch19-06-macros.html), and ConsoleAppFramework's generation can be considered as Function-like macros.

Expand Down

0 comments on commit 19fbf75

Please sign in to comment.