CSharp.ClassBuilder 1.0.0

Install-Package CSharp.ClassBuilder -Version 1.0.0
dotnet add package CSharp.ClassBuilder --version 1.0.0
<PackageReference Include="CSharp.ClassBuilder" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CSharp.ClassBuilder --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: CSharp.ClassBuilder, 1.0.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install CSharp.ClassBuilder as a Cake Addin
#addin nuget:?package=CSharp.ClassBuilder&version=1.0.0

// Install CSharp.ClassBuilder as a Cake Tool
#tool nuget:?package=CSharp.ClassBuilder&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

csharp-class-builder

Sometime you need fluent api to design the class and output as string for Reflection or anyother purposes and you end up with lot of string lines and messy code. This library will provide you fluent api to design the class and out as string.

Future Changes

  1. Compile Class
  2. Execute Methods
  3. Generate Dll on Runtime.

Usages

        var cb = new ClassBuilder();

        // New class
        var c = cb.CreateClass("Main", Modifier.Public, "My Test Class")
                              .AsSealed()
                              .WithNamespace("Rizvis.Tester.App")
                              .ImportPackage("System")
                              .ImportPackage("System.Threading.Tasks")
                              .Build();

        // New Method
        c.Methods().CreateMethod("HelloWorld", Modifier.Public)
                                       .AsVoid()
                                       .AddCodeBlack("Console.WriteLine(\"Hello World\")")
                                       .AddMethodDescription("My Hello World Method")
                                       .Build();

        // New Property 1
        c.Properties().CreateProperty("myGetProperty", Modifier.Public)
                      .AsReturnWithType(true)
                      .Getter()
                      .Setter()
                      .AddPropertyDescription("This is my test property 1")
                      .Build();

        // New Property 2
        c.Properties().CreateProperty("myGetProperty2", Modifier.Private)
                      .AsReturnWith("dynamic")
                      .Getter()
                      .Setter()
                      .AddPropertyDescription("This is my test property 2")
                      .Build();

        File.WriteAllText(@"test.cs", cb.ToString());

        Console.WriteLine(cb.ToString());
        Console.WriteLine("Done");

Output

using System;
using System.Threading.Tasks;
namespace Rizvis.Tester.App { 

////////////////////////////////////////////////////////////////////////////////////////////////////
/* <summary> My Test Class </summary> */
////////////////////////////////////////////////////////////////////////////////////////////////////
public class Main  {


////////////////////////////////////////////////////////////////////////////////////////////////////
/* <summary> My Hello World Method </summary> */
////////////////////////////////////////////////////////////////////////////////////////////////////

public void HelloWorld () {
 Console.WriteLine("Hello World") 
} 



////////////////////////////////////////////////////////////////////////////////////////////////////
/* <summary> This is my test property 1 </summary> */
////////////////////////////////////////////////////////////////////////////////////////////////////

public Boolean myGetProperty { get; set; }


////////////////////////////////////////////////////////////////////////////////////////////////////
/* <summary> This is my test property 2 </summary> */
////////////////////////////////////////////////////////////////////////////////////////////////////

private dynamic myGetProperty2 { get; set; }
}

}

API

Class API

  1. CreateClass(string name, Modifier modifier, string description = "")
  2. WithNamespace(string nameSpace)
  3. ExtendWith(string extendClassOrInterfaceName)
  4. ImportPackage(string packageName)
  5. AsStatic()
  6. AsSealed()
  7. AsAbstract()
  8. Build()

Method API

  1. CreateMethod(string name, Modifier modifier)
  2. WithArguments(params string[] args)
  3. AsVoid()
  4. WithAsync()
  5. AsReturnWithType<T>(T type)
  6. AsReturnWith(string type)
  7. AddMethodDescription(string description)
  8. AddCodeBlack(string codeBlock)
  9. AsStatic()
  10. AsSealed()
  11. AsAbstract()
  12. Build()

Property API

  1. CreateProperty(string name, Modifier modifier)
  2. AsReturnWithType<T>(T type)
  3. AsReturnWith(string type)
  4. AddPropertyDescription(string description)
  5. AsAbstract()
  6. AsStatic()
  7. ReadOnly()
  8. Getter()
  9. Setter()
  10. Build()
  • .NETStandard 2.0

    • 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
1.0.0 322 9/19/2020