• Stars
    star
    117
  • Rank 301,828 (Top 6 %)
  • Language
    C#
  • License
    MIT License
  • Created over 4 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Code generator to easily create data builder patterns for your model classes

Data Builder Generator

Allows to generate data builder patterns for your model classes.

Reference using Visual Studio 2019 16.6 or .NET CLI 3.1.500 / 5.0.100 or higher and opt into preview language features in your project file:

<PropertyGroup>
  <LangVersion>Preview</LangVersion>
</PropertyGroup>

<ItemGroup>
  <PackageReference Include="DasMulli.DataBuilderGenerator" Version="*" PrivateAssets="All" />
</ItemGroup>

Usage

Use the GenerateDataBuilder attribute to annotate the classes you wish to generate builder patterns for. If your class has constructors, be sure that the parameter names can be resolved to the name of a property:

    using DasMulli.DataBuilderGenerator;

    [GenerateDataBuilder]
    public class Person
    {
        public string FirstName { get; set; }
        public string? MiddleNames { get; set; }
        public string LastName { get; set; }

        public Person(string firstName, string? middleNames, string lastName)
        {
            FirstName = firstName;
            MiddleNames = middleNames;
            LastName = lastName;
        }
    }

Then you can use the generated builder class:

var martinBuilder = new PersonBuilder()
    .WithFirstName("Martin")
    .WithMiddleNames("Andreas")
    .WithLastName("Ullrich");

var martin = martinBuilder.Build();

var otherMartin = martinBuilder.WithoutMiddleNames().WithLastName("Foo").Build();

Notes

Special thanks to Mayr-Melnhof Karton AG for supporting the development of this project.

More Repositories

1

dotnet-win32-service

Helper classes to set up and run as windows services directly on .net core. A ServiceBase alternative.
C#
451
star
2

LocalNupkgExample

Example to demonstrate local nuget packages
C#
21
star
3

SimpleGitVersion

Simple Git prerelease versioning integrated into SDK-based msbuild projects
17
star
4

rider-msbuild-webinar-2020

Sample repository for JetBrains Rider Webinar on MSBuild from December 2020
C#
17
star
5

nuget-include-p2p-example

Example of a NuGet package including its ProjectReference projects
C#
14
star
6

ConfigSampleWebApp

Sample showing how to use appsettings.json for .NET 4.7.1 configuration builders
C#
10
star
7

AdvancedMSBuildDemos

Advanced MSBuild demos
TypeScript
8
star
8

AssemblyInfoGenerationSdk

Extracts .NET SDK AssemblyInfo.cs generation into an SDK for use in legacy project types
C#
8
star
9

hungarian-algorithm

Hungarian method a.k.a. Kuhnโ€“Munkres Algorithm for .NET
C#
7
star
10

hw-intrinsics-samples

Samples for hardware intrinsic comparisons
C#
3
star
11

HelloMSBuildDemos

MSBuild Demos
3
star
12

k8s-demos-2022

TypeScript
3
star
13

k8s-demos-2020

Kubernetes Demos
TypeScript
2
star
14

swetugg-2024-msbuild-demos

Demo code used during the 2024 Swetugg session on MSBuild
C#
2
star
15

CSProjDemos

MSBuild .csproj based demos
C#
2
star
16

dotnext-2020-samples

Samples for DotNext Moscow 2020
C#
2
star
17

exploring-source-generators

C#
2
star
18

so-config-example

Sample for SO question https://stackoverflow.com/questions/45559570/appsettings-json-in-netcore-console-application
C#
2
star
19

alerter-static-app-demo

Azure Static Web App Demo using Blazor WebAssembly and Azure Functions with Microsoft Graph
C#
1
star
20

dasmulli.github.io

http://dasmulli.github.io
HTML
1
star
21

msbuild-metadata-filter-example

Example project that shows how custom metadata and regular expressions can be used in MSBuild to filter items
C#
1
star
22

DevOpsTraining-2019-02

Azure DevOps training material
C#
1
star
23

GlobalCliToolsExample

Example for global CLI tools
C#
1
star
24

net-stammtisch-10

Samples for .NET Stammtisch #10
C#
1
star
25

dotnet-tuning-demos

Demos for .NET optimization and deployment options
C#
1
star