Code Monkey home page Code Monkey logo

sourcebuilder's Introduction

G4ME SourceBuilder

Overview

G4ME SourceBuilder is a dynamic .NET code generation framework for programmable construction of classes, records, and interfaces, optimised for Visual Studio 2022 and .NET 5+ environments.

Features

  • Builder: Central orchestrator for adding types within a shared namespace.
  • CompilationUnitBuilder: Combine various type builders into a cohesive compilation unit.
  • ClassBuilder: Create and configure classes with inheritance, interfaces, and attributes.
  • RecordBuilder: Construct record types with parameters and attributes.
  • InterfaceBuilder: Build interfaces with methods, properties, and attributes.

Usage

Creating a class with method

new Builder("ExampleNamespace")
                .AddClass("Person", c => c
                    .Properties(p => p
                        .Add<string>("Name").Get().PrivateSet())
                    .Constructor(c => c
                        .Parameter<string>("name")
                        .Body("Name = name;"))
                    .AddMethod("Greet", m => m
                        .Body(@"Console.WriteLine($"Hello, {Name}!");")))
                    .ToString();

Result:

using System;

namespace ExampleNamespace;
public class Person
{
    public string Name { get; private set; }

    public Person(string name)
    {
        Name = name;
    }

    public void Greet()
    {
        Console.WriteLine($"Hello, {Name}!");
    }
}

Creating a record with interface implementation

new Builder("ExampleNamespace")
                .AddRecord("PersonRequest", r => r.Implements<IRequest<PersonResponse>>()
                    .Parameter<string>("Name"))
                    .ToString();

Result:

using System;
using G4ME.SourceBuilder.Tests.Verified;

namespace ExampleNamespace;
public record PersonRequest(string Name) : IRequest<PersonResponse>;

Creating a basic interface with single property

new Builder("Example")
                .AddInterface("IResponse", i => i
                    .Properties(p => p
                        .Add<string>("Name").Get()))
                .ToString();
#### Result:

```csharp
namespace Example;
public interface IResponse
{
    public string Name { get; }
}

sourcebuilder's People

Contributors

arjunsol avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.