Fengb3.EasyCodeBuilder 0.0.2

dotnet add package Fengb3.EasyCodeBuilder --version 0.0.2
                    
NuGet\Install-Package Fengb3.EasyCodeBuilder -Version 0.0.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Fengb3.EasyCodeBuilder" Version="0.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Fengb3.EasyCodeBuilder" Version="0.0.2" />
                    
Directory.Packages.props
<PackageReference Include="Fengb3.EasyCodeBuilder" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Fengb3.EasyCodeBuilder --version 0.0.2
                    
#r "nuget: Fengb3.EasyCodeBuilder, 0.0.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=Fengb3.EasyCodeBuilder&version=0.0.2
                    
Install as a Cake Addin
#tool nuget:?package=Fengb3.EasyCodeBuilder&version=0.0.2
                    
Install as a Cake Tool

Easy Code Builder

NuGet Version License: MIT

A powerful and flexible library for dynamic code generation, supporting multiple programming languages including C#, Python, and Lisp.

✨ Features

  • 🚀 Fluent API: Easy-to-use method chaining for intuitive code building
  • 🎯 Multi-Language Support: Generate C#, Python, and Lisp code
  • 🔧 Configurable Indentation: Support for spaces, tabs, and custom indentation
  • 📚 Rich Code Constructs: Classes, methods, properties, control structures, and more
  • ⚡ High Performance: Optimized string building with caching mechanisms
  • 🛡️ Type Safety: Generic-based design ensures compile-time safety
  • 📖 XML Documentation: Complete IntelliSense support

🚀 Quick Start

Installation

dotnet add package Fengb3.EasyCodeBuilder

Basic Usage

<div style="display: flex; gap: 20px;"> <div style="flex: 1;">

API Calling:

using Fengb3.EasyCodeBuilder.Csharp;

var builder = new CSharpCodeBuilder();

var code = builder
    .Using("System", "System.Collections.Generic")
    .Namespace("MyProject", ns => ns
        .Class("Person", cls => cls
            .Property("string", "Name", accessors: "{ get; set; }")
            .Property("int", "Age", accessors: "{ get; set; }")
            .Method("GetInfo", method => method
                .AppendLine("return $\"Name: {Name}, Age: {Age}\";")
            , returnType: "string")
        )
    )
    .ToString();

</div> <div style="flex: 1;">

Generated Code:

using System;
using System.Collections.Generic;

namespace MyProject
{
    public class Person
    {
        public string Name { get; set; }
        public int Age { get; set; }
        
        public string GetInfo()
        {
            return $"Name: {Name}, Age: {Age}";
        }
    }
}

</div> </div>

📚 Documentation

For detailed documentation and examples, please refer to:

🏗️ Supported Languages

Language Status Builder Class
C# ✅ Full Support CSharpCodeBuilder
Python ✅ Full Support PythonCodeBuilder
Lisp ✅ Basic Support LispCodeBuilder

🎯 Key Components

Core Classes

  • CodeBuilder<T> - Abstract base class with core functionality
  • CSharpCodeBuilder - C# specific code generation
  • PythonCodeBuilder - Python specific code generation
  • LispCodeBuilder - Lisp specific code generation

Features

  • Fluent API - Method chaining for readable code
  • Indentation Management - Automatic and configurable indentation
  • Code Blocks - Structured code generation with proper nesting
  • Performance Optimized - Efficient string building and caching

📊 Examples

Generate a Complete C# Class

<div style="display: flex; gap: 20px;"> <div style="flex: 1;">

API Calling:

var code = new CSharpCodeBuilder()
    .Using("System")
    .Namespace("MyApp.Models", ns => ns
        .Class("User", cls => cls
            .Field("string", "_name", "private")
            .Property("string", "Name", 
                modifiers: "public",
                accessors: "{ get => _name; set => _name = value ?? throw new ArgumentNullException(); }")
            .Method("ToString", method => method
                .AppendLine("return $\"User: {Name}\";")
            , returnType: "string", modifiers: "public override")
        )
    );

</div> <div style="flex: 1;">

Generated Code:

using System;

namespace MyApp.Models
{
    public class User
    {
        private string _name;
        
        public string Name 
        { 
            get => _name; 
            set => _name = value ?? throw new ArgumentNullException(); 
        }
        
        public override string ToString()
        {
            return $"User: {Name}";
        }
    }
}

</div> </div>

Generate Python Code

<div style="display: flex; gap: 20px;"> <div style="flex: 1;">

API Calling:

var pythonCode = new PythonCodeBuilder()
    .Import("json", "datetime")
    .AppendLine()
    .Class("User", cls => cls
        .Function("__init__", init => init
            .AppendLine("self.name = name")
            .AppendLine("self.created_at = datetime.datetime.now()")
        , "self, name: str")
        .AppendLine()
        .Function("to_dict", func => func
            .AppendLine("return {")
            .AppendLine("    'name': self.name,")
            .AppendLine("    'created_at': self.created_at.isoformat()")
            .AppendLine("}")
        , "self", "dict")
    );

</div> <div style="flex: 1;">

Generated Code:

import json
import datetime

class User:
    def __init__(self, name: str):
        self.name = name
        self.created_at = datetime.datetime.now()
    
    def to_dict(self) -> dict:
        return {
            'name': self.name,
            'created_at': self.created_at.isoformat()
        }

</div> </div>

Control Structures Example

<div style="display: flex; gap: 20px;"> <div style="flex: 1;">

API Calling:

var code = new CSharpCodeBuilder()
    .Namespace("Examples", ns => ns
        .Class("Calculator", cls => cls
            .Method("Divide", method => method
                .If("b == 0", ifBlock => ifBlock
                    .AppendLine("throw new DivideByZeroException(\"Cannot divide by zero\");")
                )
                .AppendLine("return a / b;")
            , returnType: "double", parameters: "double a, double b")
        )
    );

</div> <div style="flex: 1;">

Generated Code:

namespace Examples
{
    public class Calculator
    {
        public double Divide(double a, double b)
        {
            if (b == 0)
            {
                throw new DivideByZeroException("Cannot divide by zero");
            }
            return a / b;
        }
    }
}

</div> </div>

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.


Made with ❤️ by Bohan Feng

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.1

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.0.2 28 6/21/2025
0.0.1 27 6/21/2025

GitHub Actions CI/CD自动化发布测试版本