CSharp.ClassBuilder 1.0.0

dotnet add package CSharp.ClassBuilder --version 1.0.0
NuGet\Install-Package CSharp.ClassBuilder -Version 1.0.0
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="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
#r "nuget: CSharp.ClassBuilder, 1.0.0"
#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.
// 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

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()
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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  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.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 610 9/19/2020