The C# AST library is used by Blueprint and .NET engine plugins. Node.js plugins use different methods for code generation as detailed in the Node.js Plugin Events documentation.
The C# AST library provides functionality for generating C# code through an abstract syntax tree in the Amplication platform. It enables the creation of type-safe, well-structured C# code for .NET applications.
The C# AST library is not intended to cover all C# language functionality. Instead, it focuses on the elements needed to create foundation and boilerplate code with Amplication plugins. The library provides building blocks for generating well-structured C# code for common patterns and use cases.When more specialized or custom code is needed, the CodeBlock class can be used as a generic node that can include any code as a string:
Copy
import { CodeBlock } from '@amplication/csharp-ast';// Create a custom code block for specialized logicconst customLogic = new CodeBlock(` // Custom C# implementation using (var client = new HttpClient()) { var response = await client.GetAsync(endpoint); return await response.Content.ReadAsStringAsync(); }`);// Add to your class or method
This flexibility allows you to generate both structured AST-based code and custom code blocks when necessary.