SharpBuilder 4.0.0

dotnet add package SharpBuilder --version 4.0.0
                    
NuGet\Install-Package SharpBuilder -Version 4.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="SharpBuilder" Version="4.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SharpBuilder" Version="4.0.0" />
                    
Directory.Packages.props
<PackageReference Include="SharpBuilder" />
                    
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 SharpBuilder --version 4.0.0
                    
#r "nuget: SharpBuilder, 4.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.
#addin nuget:?package=SharpBuilder&version=4.0.0
                    
Install SharpBuilder as a Cake Addin
#tool nuget:?package=SharpBuilder&version=4.0.0
                    
Install SharpBuilder as a Cake Tool

SharpBuilder

SharpBuilder is a library for building valid C# code. It is useful for generating working code.

SharpBuilder main purpose is to create C# models from various sources. For example, you can create a model from a Database Table or a JSON schema. However, the read and export must be done manually.

SharpBuilder is not a code generator. It does not generate code for you. It only helps you to build valid C# code.

Installation

SharpBuilder is available on NuGet.

Use cases

  • Creating models from Excel files.
  • Creating models from Database tables.
  • Creating models from JSON schemas.
  • Creating models from XML schemas.
  • Creating models from CSV files.

Be aware that SharpBuilder does not read files. You must read the files yourself and then use SharpBuilder to create the models.

Builders

SharpAttributeBuilder
  • SharpAttribute can be added to almost everything except SharpFile and itself
var attribute = new SharpAttributeBuilder("Obsolete")
    .AddParameter("This is obsolete")
    .Build();
SharpClassBuilder
  • SharpClassBuilder can be added to SharpFile
var @class = new SharpClassBuilder("Person")
    .AddAttribute(new SharpAttributeBuilder("Obsolete")
        .AddParameter("This is obsolete")
        .Build())
    .AddProperty(new SharpPropertyBuilder("Name", typeof(string))
        .AddAttribute(new SharpAttributeBuilder("Required")
            .Build())
        .Build())
    .AddProperty(new SharpPropertyBuilder("Age", typeof(int))
        .AddAttribute(new SharpAttributeBuilder("Required")
            .Build())
        .Build())
    .Build();
SharpConstantBuilder
  • SharpConstant can be added to SharpClass
var constant = new SharpConstantBuilder("Name", typeof(string), "John Doe")
    .Build();
SharpFieldBuilder
  • SharpField can be added to SharpClass
var field = new SharpFieldBuilder("Name", typeof(string))
    .Build();
SharpPropertyBuilder
  • SharpProperty can be added to SharpClass
var property = new SharpPropertyBuilder("Name", typeof(string))
    .Static()
    .Build();
SharpEnumKeyBuilder
  • SharpEnumKey can be added to SharpEnum
var exampleEnumKey = new SharpEnumKeyBuilder("Name")
    .WithValue(23) //Sets an integer value
    .ClearValue() //Clears set value, does nothing if value is not set before
    .Build();
SharpEnumBuilder
  • Ability to change Enum value type to any other value other than is not recommended by Microsoft. Thats why that option is not provided by the library. If you exceed integer value limit, you may need to rethink what you are doing.
  • SharpEnum can be added to SharpFile or SharpClass
var exampleEnum = new SharpEnumBuilder("Name")
    .AddKey(exampleEnumKey) //Single key 
    .RemoveKey(exampleKey) //Remove a key instance
    .AddKeys([exampleEnumKey]) //Add list of keys
    .ClearKeys() //Clears list of keys
    .SetKeys([exampleEnumKey]) //Completely overrides existing keys
    .Build();

Todo

  • Add support for SharpStruct and more
  • More Validation before compiling class to text
  • Tests

Changelog

v4.0

  • !Breaking: All library classes is changed to sealed.
  • !Breaking: Fixed a bug where AddAttributes method was actually setting the whole list instead of calling AddRange
  • Added support for multiple .NET versions.
  • Added null value checks in constructors will only be triggered when *Builder.Build() is called.
  • SharpClass now has Classes property which can be used to create inner classes.
  • Added SharpEnum which can be added to SharFile or SharpClass.
  • Added SharpEnumKey which can be added inside SharpEnum.
  • Added internal abstract class and interface to reduce copy paste code.
  • After build is called, no other builder methods can be called
  • Added option to add attributes to some other builders
  • Simple tests project has been removed, in future might add unit tests

v3.0 and before

  • Implemented SharpClassBuilder
  • Implemented SharpAttributeBuilder
  • Implemented SharpConstantBuilder
  • Implemented SharpFieldBuilder
  • Implemented SharpFileBuilder
  • Implemented SharpPropertyBuilder
  • Implemented SharpSummaryBuilder
Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net5.0-windows7.0 is compatible.  net6.0 is compatible.  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.  net6.0-windows7.0 is compatible.  net7.0 is compatible.  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.  net7.0-windows7.0 is compatible.  net8.0 is compatible.  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.  net8.0-windows7.0 is compatible.  net9.0 is compatible.  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 netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
.NET Framework net481 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.
  • .NETFramework 4.8.1

    • No dependencies.
  • .NETStandard 2.1

    • No dependencies.
  • net5.0

    • No dependencies.
  • net5.0-windows7.0

    • No dependencies.
  • net6.0

    • No dependencies.
  • net6.0-windows7.0

    • No dependencies.
  • net7.0

    • No dependencies.
  • net7.0-windows7.0

    • No dependencies.
  • net8.0

    • No dependencies.
  • net8.0-windows7.0

    • No dependencies.
  • net9.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
4.0.0 162 a month ago
3.0.0 143 1/22/2024
2.0.4 111 1/21/2024
2.0.3 114 1/21/2024
2.0.2 114 1/21/2024
2.0.1 107 1/21/2024
2.0.0 140 1/12/2024
1.2.0 108 1/12/2024
1.1.0 115 1/12/2024
1.0.0 195 7/12/2023