Skip to content

Commit 19fbf75

Browse files
committed
f ReadMe
1 parent 1e1229a commit 19fbf75

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

ReadMe.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@ ConsoleApp.Run(args, (int foo, int bar) => Console.WriteLine($"Sum: {foo + bar}"
1818

1919
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.
2020

21+
```csharp
22+
internal static partial class ConsoleApp
23+
{
24+
// Generate the Run method itself with arguments and body to match the lambda expression
25+
public static void Run(string[] args, Action<int, int> command)
26+
{
27+
// code body
28+
}
29+
}
30+
```
31+
32+
<details><summary>Full generated source code</summary>
2133
```csharp
2234
namespace ConsoleAppFramework;
2335

@@ -111,6 +123,7 @@ Options:
111123
}
112124
}
113125
```
126+
</details>
114127

115128
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.
116129

0 commit comments

Comments
 (0)