From 19fbf750ae2a80ed106d16bec8347db23a913ce8 Mon Sep 17 00:00:00 2001 From: neuecc Date: Wed, 12 Jun 2024 12:40:23 +0900 Subject: [PATCH] f ReadMe --- ReadMe.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/ReadMe.md b/ReadMe.md index fe010c0..dabba13 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -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 command) + { + // code body + } +} +``` + +
Full generated source code ```csharp namespace ConsoleAppFramework; @@ -111,6 +123,7 @@ Options: } } ``` +
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.