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
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 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
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
- Compile Class
- Execute Methods
- 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
CreateClass(string name, Modifier modifier, string description = "")
WithNamespace(string nameSpace)
ExtendWith(string extendClassOrInterfaceName)
ImportPackage(string packageName)
AsStatic()
AsSealed()
AsAbstract()
Build()
Method API
CreateMethod(string name, Modifier modifier)
WithArguments(params string[] args)
AsVoid()
WithAsync()
AsReturnWithType<T>(T type)
AsReturnWith(string type)
AddMethodDescription(string description)
AddCodeBlack(string codeBlock)
AsStatic()
AsSealed()
AsAbstract()
Build()
Property API
CreateProperty(string name, Modifier modifier)
AsReturnWithType<T>(T type)
AsReturnWith(string type)
AddPropertyDescription(string description)
AsAbstract()
AsStatic()
ReadOnly()
Getter()
Setter()
Build()
Product | Versions 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. |
.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 | 693 | 9/19/2020 |